public static function fromReflection(ZendL_Reflection_Class $reflectionClass) { $class = new self(); $class->setSourceContent($class->getSourceContent()); $class->setSourceDirty(false); if ($reflectionClass->getDocComment() != '') { $class->setDocblock(ZendL_Tool_CodeGenerator_Php_Docblock::fromReflection($reflectionClass->getDocblock())); } $class->setAbstract($reflectionClass->isAbstract()); $class->setName($reflectionClass->getName()); if ($parentClass = $reflectionClass->getParentClass()) { $class->setExtendedClass($parentClass->getName()); } $class->setImplementedInterfaces($reflectionClass->getInterfaceNames()); $properties = array(); foreach ($reflectionClass->getProperties() as $reflectionProperty) { if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) { $properties[] = ZendL_Tool_CodeGenerator_Php_Property::fromReflection($reflectionProperty); } } $class->setProperties($properties); $methods = array(); foreach ($reflectionClass->getMethods() as $reflectionMethod) { if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) { $methods[] = ZendL_Tool_CodeGenerator_Php_Method::fromReflection($reflectionMethod); } } $class->setMethods($methods); return $class; }
public static final function exec($data) { $process = new self(); $process->run($data); Log::info(' === ' . $process->getName() . ' ==== started === '); return $process; }
/** * @param string|int|self $role */ public function addChild($role) { if (!$role instanceof self) { $role = new self($role); } $this->children[$role->getName()] = $role; }
public function getParentClass() { $parent = parent::getParentClass(); if ($parent) { $parent = new self($parent->getName()); } return $parent; }
/** * @param Privilege|string $privilege * * @throws \InvalidArgumentException * * @return bool */ public function equals($privilege) { if (is_scalar($privilege)) { $privilege = new self($privilege); } elseif (!$privilege instanceof self) { throw new \InvalidArgumentException('$privilege is expected to be of type string or Gobline\\Acl\\Privilege'); } return $privilege->getName() === $this->name; }
/** * {@inheritdoc} */ public function equals($role) { if (is_scalar($role)) { $role = new self($role); } elseif (!$role instanceof self) { throw new \InvalidArgumentException('$role is expected to be of type string or Gobline\\Acl\\Role'); } $roleName = $role->getName(); return $roleName === $this->name; }
public static function getFromRegularDonation(Donator_Model_RegularDonation $regDon) { $obj = new self($regDon->__get('bank_account_nr'), $regDon->__get('account_name'), $regDon->__get('bank_name'), $regDon->__get('bank_code'), $regDon->getForeignId('donation_payment_method')); $fundMaster = $regDon->getForeignRecord('fundmaster_id', Donator_Controller_FundMaster::getInstance()); $obj->setContactId($fundMaster->getForeignId('contact_id')); $contact = $fundMaster->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance()); $countryCode = $contact->getLetterDrawee()->getPostalAddress()->getCountryCode('DE'); $obj->setCountryCode($countryCode); if (trim($obj->getName()) == '') { $obj->setName($contact->__get('n_fileas')); } return $obj; }
/** * {@inheritdoc} */ public function matches($resource) { if (!$resource instanceof self) { if (is_scalar($resource)) { $resource = new self($resource); } elseif ($resource instanceof ResourceInterface) { return false; } else { throw new \InvalidArgumentException('$resource is expected to be of type string or Gobline\\Acl\\ResourceInterface'); } } $resourceName = $resource->getName(); return $this->matcher->matches($resourceName, $this->name); }
/** * Function to get instance by using XML node * @param <XML DOM> $extensionXMLNode * @return <Settings_ModuleManager_Extension_Model> $extensionModel */ public static function getInstanceFromXMLNodeObject($extensionXMLNode) { $extensionModel = new self(); $objectProperties = get_object_vars($extensionXMLNode); foreach ($objectProperties as $propertyName => $propertyValue) { $propertyValue = (string) $propertyValue; if ($propertyName === 'description') { $propertyValue = nl2br(str_replace(array('<', '>'), array('<', '>'), br2nl(trim($propertyValue)))); } $extensionModel->set($propertyName, $propertyValue); } $label = $extensionModel->get('label'); if (!$label) { $extensionModel->set('label', $extensionModel->getName()); } return $extensionModel; }
/** * @param \RokCommon_XMLElement $xml_node * * @throws \RokCommon_Config_Exception */ protected function initialize(RokCommon_XMLElement $xml_node) { $this->xml_node = $xml_node; // get the name of the entry if (!isset($this->xml_node['name'])) { throw new RokCommon_Config_Exception(rc__('Meta Config entry in %s does not have a name', $this->parent_identifier)); } $this->name = (string) $this->xml_node['name']; // set the identifier name $id_parts = explode(self::ENTRY_SEPERATOR, $this->parent_identifier); $id_parts[] = $this->name; $this->identifier = implode(self::ENTRY_SEPERATOR, $id_parts); // get the filename of the entry if (!isset($this->xml_node['filename'])) { throw new RokCommon_Config_Exception(rc__('Meta Config entry %s does not have a filename', $this->identifier)); } $this->filename = (string) $this->xml_node['filename']; // get the mode if (isset($this->xml_node['mode'])) { $this->mode = (string) $this->xml_node['mode']; } // get the jointype if (isset($this->xml_node['jointype'])) { $this->jointype = (string) $this->xml_node['jointype']; } // see if there is a library and add it to the lib path $library_paths = $xml_node->xpath('libraries/library'); if ($library_paths) { foreach ($library_paths as $library_path) { $resolved_lib_path = RokCommon_Config::replaceTokens((string) $library_path, dirname($this->root_file)); if (is_dir($resolved_lib_path)) { RokCommon_ClassLoader::addPath($resolved_lib_path); } } } // get the paths for the config $paths = $xml_node->xpath('paths/path'); if (!$paths) { throw new RokCommon_Config_Exception(rc__('Meta Config entry %s must have at least one path.', $this->identifier)); } foreach ($paths as $path_entry) { $priority = RokCommon_Composite::DEFAULT_PRIORITY; if (isset($path_entry['priority'])) { $priority = (string) $path_entry['priority']; } $path = RokCommon_Config::replaceTokens((string) $path_entry, dirname($this->root_file)); if (is_dir($path)) { // see if there is a testservice entry if (isset($path_entry['testservice'])) { // see if the testservice extists $testservice_name = (string) $path_entry['testservice']; $container = RokCommon_Service::getContainer(); /** @var $testservice RokCommon_Config_PathTest */ $testservice = $container->{$testservice_name}; if (!$container->hasService($testservice_name)) { throw new RokCommon_Config_Exception(rc__('Path test service %s does not exist', $testservice_name)); } // see if we can add the if ($testservice->isPathAvailable()) { $this->addPath($path, $priority); } } else { // add the path if there is no testclass $this->addPath($path, $priority); } } else { // TODO log unable to find path } } // add any subconfigs $subconfigs = $xml_node->xpath('subconfigs/subconfig'); if ($subconfigs) { foreach ($subconfigs as $subconfig_entry) { $subconfig = new self($this->identifier, $this->root_file, $subconfig_entry); $this->subentries[$subconfig->getName()] = $subconfig; } } $this->context = RokCommon_Composite::get($this->identifier); }
/** * Generate a new Cookie object from a cookie string * (for example the value of the Set-Cookie HTTP header) * * @static * @throws Zend_Http_Header_Exception_InvalidArgumentException * @param $headerLine * @param bool $bypassHeaderFieldName * @return array|SetCookie */ public static function fromString($headerLine, $bypassHeaderFieldName = false) { list($name, $value) = explode(': ', $headerLine, 2); // check to ensure proper header type for this factory if (strtolower($name) !== 'set-cookie') { throw new Zend_Http_Header_Exception_InvalidArgumentException('Invalid header line for Set-Cookie string: "' . $name . '"'); } $multipleHeaders = preg_split('#(?<!Sun|Mon|Tue|Wed|Thu|Fri|Sat),\\s*#', $value); $headers = array(); foreach ($multipleHeaders as $headerLine) { $header = new self(); $keyValuePairs = preg_split('#;\\s*#', $headerLine); foreach ($keyValuePairs as $keyValue) { if (strpos($keyValue, '=')) { list($headerKey, $headerValue) = preg_split('#=\\s*#', $keyValue, 2); } else { $headerKey = $keyValue; $headerValue = null; } // First K=V pair is always the cookie name and value if ($header->getName() === NULL) { $header->setName($headerKey); $header->setValue($headerValue); continue; } // Process the remanining elements switch (str_replace(array('-', '_'), '', strtolower($headerKey))) { case 'expires': $header->setExpires($headerValue); break; case 'domain': $header->setDomain($headerValue); break; case 'path': $header->setPath($headerValue); break; case 'secure': $header->setSecure(true); break; case 'httponly': $header->setHttponly(true); break; case 'version': $header->setVersion((int) $headerValue); break; case 'maxage': $header->setMaxAge((int) $headerValue); break; default: // Intentionally omitted } } $headers[] = $header; } return count($headers) == 1 ? array_pop($headers) : $headers; }
/** * fromReflection() - build a Code Generation Php Object from a Class Reflection * * @param \Zend\Reflection\ReflectionClass $reflectionClass * @return \Zend\CodeGenerator\Php\PhpClass */ public static function fromReflection(\Zend\Reflection\ReflectionClass $reflectionClass) { $class = new self(); $class->setSourceContent($class->getSourceContent()); $class->setSourceDirty(false); if ($reflectionClass->getDocComment() != '') { $class->setDocblock(PhpDocblock::fromReflection($reflectionClass->getDocblock())); } $class->setAbstract($reflectionClass->isAbstract()); // set the namespace if ($reflectionClass->inNamespace()) { $class->setNamespaceName($reflectionClass->getNamespaceName()); } $class->setName($reflectionClass->getName()); if ($parentClass = $reflectionClass->getParentClass()) { $class->setExtendedClass($parentClass->getName()); $interfaces = array_diff($reflectionClass->getInterfaces(), $parentClass->getInterfaces()); } else { $interfaces = $reflectionClass->getInterfaces(); } $interfaceNames = array(); foreach($interfaces AS $interface) { $interfaceNames[] = $interface->getName(); } $class->setImplementedInterfaces($interfaceNames); $properties = array(); foreach ($reflectionClass->getProperties() as $reflectionProperty) { if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) { $properties[] = PhpProperty::fromReflection($reflectionProperty); } } $class->setProperties($properties); $methods = array(); foreach ($reflectionClass->getMethods() as $reflectionMethod) { if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) { $methods[] = PhpMethod::fromReflection($reflectionMethod); } } $class->setMethods($methods); return $class; }
/** * @param array $option * @param integer $currentXml * @return array */ private function internalParse(array &$option, $currentXml = 0) { if ($currentXml == 0) { if (!isset($option[0])) { return array(); } $currentXmlArray = $option[0]; $this->setName(isset($currentXmlArray['tag']) ? $currentXmlArray['tag'] : 'noname'); $this->setValue(isset($currentXmlArray['value']) ? $currentXmlArray['value'] : ''); $this->setAttributes(isset($currentXmlArray['attributes']) ? $currentXmlArray['attributes'] : array()); $this->setRoot(true); } $xmlArray = array(); $currentXml++; $deep = $currentXml; while ($deep < count($option)) { $currentXmlArray = $option[$deep]; if ($currentXmlArray['type'] == 'close') { return array($xmlArray, $deep); } $xmlObject = new self(''); $xmlObject->setName(isset($currentXmlArray['tag']) ? $currentXmlArray['tag'] : 'noname'); $xmlObject->setValue(isset($currentXmlArray['value']) ? $currentXmlArray['value'] : ''); $xmlObject->setAttributes(isset($currentXmlArray['attributes']) ? $currentXmlArray['attributes'] : array()); if ($currentXmlArray['type'] == 'open') { $result = $this->internalParse($option, $deep++); if (!empty($result)) { list($children, $deep) = $result; $xmlObject->appendChild($children); } } $xmlArray[$xmlObject->getName()][] = $xmlObject; $deep++; } return array($xmlArray, $deep); }
public static function &getInstance($name = NULL) { static $instance = array(); if ($name === NULL) { $keys = array_keys($instance); $name = array_shift($keys); } if (!strlen($name)) { $name = self::getDefaultLogger(); } if (!isset($instance[$name])) { $object = new self($name); $name = $object->getName(); // If the instance already exists, we throw away the newly created one // we can't safely do this before we create the object because it might be invalid and the // test code for this is inside the class, so in this scenario, we just take a small hit if (!isset($instance[$name])) { $instance[$name] = $object; } if (!self::getDefaultLogger()) { self::setDefaultLogger($name); } } return $instance[$name]; }
/** * @since version 0.84 * * @param $row HTMLTableRow object (default NULL) * @param $item CommonDBTM object (default NULL) * @param $father HTMLTableCell object (default NULL) * @param $options array **/ static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array()) { global $DB, $CFG_GLPI; $column_name = __CLASS__; if (isset($options['dont_display'][$column_name])) { return; } if (empty($item)) { if (empty($father)) { return; } $item = $father->getItem(); } $canedit = isset($options['canedit']) && $options['canedit']; if ($item->getType() == 'NetworkPort_Vlan') { if (isset($item->fields["tagged"]) && $item->fields["tagged"] == 1) { $tagged_msg = __('Tagged'); } else { $tagged_msg = __('Untagged'); } $vlan = new self(); if ($vlan->getFromDB($options['items_id'])) { $content = sprintf(__('%1$s - %2$s'), $vlan->getName(), $tagged_msg); $content .= Html::showToolTip(sprintf(__('%1$s: %2$s'), __('ID TAG'), $vlan->fields['tag']) . "<br>" . sprintf(__('%1$s: %2$s'), __('Comments'), $vlan->fields['comment']), array('display' => false)); $this_cell = $row->addCell($row->getHeaderByName($column_name), $content, $father); } } }
/** * Function to get instance by using XML node * @param <XML DOM> $extensionXMLNode * @return <Settings_ExtensionStore_Extension_Model> $extensionModel */ public function getInstanceFromArray($listing) { $extensionModel = new self(); foreach ($listing as $key => $value) { switch ($key) { case 'name' : $key = 'label'; break; case 'identifier': $key = 'name'; break; case 'version' : $key = 'pkgVersion'; break; case 'minrange': $key = 'vtigerVersion'; break; case 'maxrange': $key = 'vtigerMaxVersion'; break; case 'CustomerId': $key = 'publisher'; break; case 'price': $value = $value ? $value : 'Free'; break; case 'approvedon': $key = 'pubDate'; break; case 'ListingFileId': if ($value) { $key = 'downloadURL'; $value = $this->getExtensionsLookUpUrl() . '/customer/listingfiles?id='.$value; } break; case 'thumbnail': if ($value) { $key = 'thumbnailURL'; $value = str_replace('api', "_listingimages/$value", $this->getExtensionsLookUpUrl()); } break; case 'banner' : if ($value) { $key = 'bannerURL'; $value = str_replace('api', "_listingimages/$value", $this->getExtensionsLookUpUrl()); } break; case 'description': if($value){ $markDownInstance = new Michelf\Markdown(); $value = $markDownInstance->transform($value); } } $extensionModel->set($key, $value); } $label = $extensionModel->get('label'); if (!$label) { $extensionModel->set('label', $extensionModel->getName()); } $moduleModel = self::getModuleFromExtnName($extensionModel->getName()); if($moduleModel && $moduleModel->get('extnType') == 'language') { $trial = $extensionModel->get('trial'); $moduleModel->set('trial',$trial); } $extensionModel->set('moduleModel', $moduleModel); return $extensionModel; }
/** * Create a symlink pointing to this directory * * @param Dir|string $dir Dir object or path * @param boolean $createPaths Create paths (if does not exist) * * @return $this * @throws \InvalidArgumentException */ public function symlink($dir, $createPaths = true) { if (!$this->exists()) { throw new \InvalidArgumentException(sprintf("Cannot create a link. Directory must exist: '%s'", $this->path)); } if (!$dir instanceof self) { $dir = new self($dir); } if ($dir->isLink()) { unlink($dir->getPath()); } $parent = $dir->getParent(); if ($createPaths) { if (!$this->exists()) { $this->create(); } if (!$parent->exists()) { $parent->create(); } } symlink($this->getAbsolutePath(), $parent->getAbsolutePath() . '/' . $dir->getName()); return $this; }
/** * Возвращает всех детей выше * Возвращает родословную от человека указанного в модели до Я (чей род) * * @param int $id * * @return array * [ * [ * 'name' => string, (если имя не указано или не заполнены данные о человеке, то здесь = null) * 'id' => int, идентификатор рода * ], ... * ] */ private function getRodPathCircle($id) { $ret = []; $childId = self::calcChild($id); if ($childId == 0) { return $ret; } else { $class = self::find(['user_id' => $this->getField('user_id'), 'rod_id' => $childId]); if (is_null($class)) { $ret[] = ['id' => $childId, 'name' => null]; $class = new self(['user_id' => $this->getField('user_id'), 'rod_id' => $childId]); } else { $ret[] = ['id' => $childId, 'name' => $class->getName()]; } $path = $class->getRodPathCircle($childId); return ArrayHelper::merge($path, $ret); } }
public static function selectbox($fieldName, $dataOptions, $args = '') { if (empty($dataOptions) || !is_array($dataOptions)) { return false; } $Field = new self($fieldName, $args); $value = $Field->getValue(); $name = $Field->getName(); $html_options = $Field->getHtmlOptions(); if (!empty($html_options['multiple'])) { $name .= '[]'; } $options[] = '<select name="' . $name . '" ' . $html_options . '>'; foreach ($dataOptions as $optionKey => $optionValue) { if ($value == $optionKey) { $selected = 'selected="selected"'; } elseif (is_array($value) and in_array($optionKey, $value)) { $selected = 'selected="selected"'; } else { $selected = ''; } $options[] = '<option value="' . $optionKey . '" ' . $selected . '>' . $optionValue . '</option>'; } $options[] = '</select>'; $separator = empty($args['separator']) ? '' : $args['separator']; return implode($separator, $options); }
static function exportAsPDF($models_id) { $logresults = self::prepareLogResults($models_id); $model = new self(); $model->getFromDB($models_id); if (!empty($logresults)) { $pdf = new PluginPdfSimplePDF('a4', 'landscape'); $pdf->setHeader(sprintf(__('%1$s (%2$s)'), __('File injection report', 'datainjection') . ' - <b>' . PluginDatainjectionSession::getParam('file_name') . '</b>', $model->getName())); $pdf->newPage(); if (isset($logresults[PluginDatainjectionCommonInjectionLib::SUCCESS])) { $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . __('Array of successful injections', 'datainjection') . '</b>'); $pdf->setColumnsSize(6, 54, 20, 20); $pdf->setColumnsAlign('center', 'center', 'center', 'center'); $col0 = '<b>' . __('Line', 'datainjection') . '</b>'; $col1 = '<b>' . __('Data Import', 'datainjection') . '</b>'; $col2 = '<b>' . __('Injection type', 'datainjection') . '</b>'; $col3 = '<b>' . __('Object Identifier', 'datainjection') . '</b>'; $pdf->displayTitle($col0, $col1, $col2, $col3); $index = 0; foreach ($logresults[PluginDatainjectionCommonInjectionLib::SUCCESS] as $result) { $pdf->displayLine($result['line'], $result['status_message'], $result['type'], $result['item']); } } if (isset($logresults[PluginDatainjectionCommonInjectionLib::FAILED])) { $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . __('Array of unsuccessful injections', 'datainjection') . '</b>'); $pdf->setColumnsSize(6, 16, 38, 20, 20); $pdf->setColumnsAlign('center', 'center', 'center', 'center', 'center'); $col0 = '<b>' . __('Line', 'datainjection') . '</b>'; $col1 = '<b>' . __('Data check', 'datainjection') . '</b>'; $col2 = '<b>' . __('Data Import', 'datainjection') . '</b>'; $col3 = '<b>' . __('Injection type', 'datainjection') . '</b>'; $col4 = '<b>' . __('Object Identifier', 'datainjection') . '</b>'; $pdf->displayTitle($col0, $col1, $col2, $col3, $col4); $index = 0; foreach ($logresults[PluginDatainjectionCommonInjectionLib::FAILED] as $result) { $pdf->setColumnsSize(6, 16, 38, 20, 20); $pdf->setColumnsAlign('center', 'center', 'center', 'center', 'center'); $pdf->displayLine($result['line'], $result['check_sumnary'], $result['status_message'], $result['type'], $result['item']); if ($result['check_message']) { $pdf->displayText('<b>' . __('Data check', 'datainjection') . '</b> :', $result['check_message'], 1); } } } $pdf->render(); } }
public function startEdit() { if ($this->getRole() != "view") { throw new Exception("only worksheets with role 'view' can be edited!"); } $currentUser = $GLOBALS["STEAM"]->get_current_steam_user(); $userWorkroom = $currentUser->get_workroom(); $newObj = \steam_factory::create_copy($GLOBALS["STEAM"]->get_id(), $this->steamObj); $newObj->move($userWorkroom); $newWorksheet = new self($newObj->get_id()); $newWorksheet->setRole("edit"); $name = $newWorksheet->getName(); $name = preg_replace('!(\\ )*\\(Vorlage\\)!isU', '', $name); $name = preg_replace('!(\\ )*\\(Verteilkopie\\)!isU', '', $name); $name = $name . " (Arbeitskopie)"; $newWorksheet->setName($name); $this->addEditCopy($currentUser->get_id(), $newWorksheet->getId()); return $newWorksheet; }
public static function fromSlack(SlackUser $user) { $user = new self($user->getId(), $user->getName()); return $user; }