/** * Add a complex type by recursivly using all the class properties fetched via Reflection. * * @param string $type Name of the class to be specified * @return string XSD Type for the given PHP type */ public function addComplexType($type) { if (!class_exists($type)) { throw new \Zend\Soap\WSDL\Exception(sprintf('Cannot add a complex type %s that is not an object or where ' . 'class could not be found in \'DefaultComplexType\' strategy.', $type)); } $dom = $this->getContext()->toDomDocument(); $class = new \ReflectionClass($type); $complexType = $dom->createElement('xsd:complexType'); $complexType->setAttribute('name', $type); $all = $dom->createElement('xsd:all'); foreach ($class->getProperties() as $property) { if ($property->isPublic() && preg_match_all('/@var\\s+([^\\s]+)/m', $property->getDocComment(), $matches)) { /** * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType' * node for describing other classes used as attribute types for current class */ $element = $dom->createElement('xsd:element'); $element->setAttribute('name', $property->getName()); $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0]))); $all->appendChild($element); } } $complexType->appendChild($all); $this->getContext()->getSchema()->appendChild($complexType); $this->getContext()->addType($type); return "tns:{$type}"; }
/** * Derives properties from constructor, public instance variables, getters and setters. * * @param object|null $object If provided, dynamic (run-time) variables are read as well * @return \watoki\collections\Map|Property[] indexed by property name */ public function readInterface($object = null) { $properties = new Map(); if ($this->class->getConstructor()) { foreach ($this->class->getConstructor()->getParameters() as $parameter) { $this->accumulate($properties, new property\ConstructorProperty($this->factory, $this->class->getConstructor(), $parameter)); } } $declaredProperties = array(); foreach ($this->class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { if (!$property->isStatic()) { $declaredProperties[] = $property->name; $this->accumulate($properties, new property\InstanceVariableProperty($this->factory, $property)); } } if (is_object($object)) { foreach ($object as $name => $value) { if (!in_array($name, $declaredProperties)) { $this->accumulate($properties, new property\DynamicProperty($this->factory, new \ReflectionClass($object), $name)); } } } foreach ($this->class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { if (property\AccessorProperty::isAccessor($method) && !$method->isStatic()) { $this->accumulate($properties, new property\AccessorProperty($this->factory, $method)); } } return $properties; }
private function obj2Array($obj) { $toRtn = array(); $reflect = new \ReflectionClass(get_class($obj)); $reflect->getProperties(); foreach ($reflect->getProperties() as $property) { $result = null; if ($property->isPrivate() || $property->isProtected()) { $getter = 'get' . ucfirst($property->getName()); if ($reflect->hasMethod($getter)) { $result = $obj->{$getter}(); } } else { $result = $property->getValue($obj); } if (is_object($result)) { $toRtn[$property->getName()] = $this->obj2Array($result); } elseif (is_array($result)) { $toRtn[$property->getName()] = $this->prepare($result); } else { $toRtn[$property->getName()] = $result; } } return $toRtn; }
/** * @param string $columnName * * @return array */ public function getAsArray($columnName = null) { if ($columnName) { $this->rewind(); $obj = $this->current(); if ($obj) { if (!$this->reflection) { $this->reflection = new \ReflectionClass($this->current()); } if ($this->columnMap === null) { $this->columnMap = []; foreach ($this->reflection->getProperties() as $property) { $this->columnMap[$property->getName()] = $property; } } } } $this->rewind(); $arr = []; while ($this->valid()) { if ($columnName && !empty($this->columnMap[$columnName])) { $obj = $this->current(); /** * @var \ReflectionProperty $test */ $this->columnMap[$columnName]->setAccessible(true); $arr[] = $this->columnMap[$columnName]->getValue($obj); } else { $arr[] = $this->current(); } $this->next(); } return $arr; }
/** * Exports the PHP code * * @return string */ public function exportCode() { $code_lines = array(); $code_lines[] = '<?php'; // Export the namespace if ($this->_reflection_class->getNamespaceName()) { $code_lines[] = ''; $code_lines[] = 'namespace ' . $this->_reflection_class->getNamespaceName() . ';'; $code_lines[] = ''; } // Export the class' signature $code_lines[] = sprintf('%s%s%s %s%s%s', $this->_reflection_class->isAbstract() ? 'abstract ' : '', $this->_reflection_class->isFinal() ? 'final ' : '', $this->_reflection_class->isInterface() ? 'interface' : ($this->_reflection_class->isTrait() ? 'trait' : 'class'), $this->getClassName(), $this->_getParentClassName() ? " extends {$this->_getParentClassName()}" : '', $this->_getInterfaceNames() ? " implements " . join(', ', $this->_getInterfaceNames()) : ''); $code_lines[] = '{'; $code_lines[] = ''; // Export constants foreach ($this->_reflection_class->getConstants() as $name => $value) { $reflection_constant = new ReflectionConstant($name, $value); $code_lines[] = "\t" . $reflection_constant->exportCode(); $code_lines[] = ''; } // Export properties foreach ($this->_reflection_class->getProperties() as $property) { $reflection_property = new ReflectionProperty($property); $code_lines[] = "\t" . $reflection_property->exportCode(); $code_lines[] = ''; } // Export methods foreach ($this->_reflection_class->getMethods() as $method) { $reflection_method = new ReflectionMethod($method); $code_lines[] = "\t" . $reflection_method->exportCode(); $code_lines[] = ''; } $code_lines[] = '}'; return join("\n", $code_lines); }
protected function _parseProperties() { $props = $this->_class->getProperties(); foreach ($props as $prop) { $this->_properties[] = new AnnotatedProperty($prop); } }
/** * Construct and return Array-Object * @param String $class * @return Array */ public static function construct($class) { // If is already an object return the object // If not create an instance of the object bypassing a possible // class constructor if (is_object($class)) { $instantiatedClass = $class; $class = get_class($class); } else { $instantiatedClass = self::instantiate($class); } // Clean arrays $properties = array('protected' => array(), 'public' => array()); $methods = array('protected' => array(), 'public' => array()); // Reflection get properties and methods names (public and protected) $reflect = new \ReflectionClass($instantiatedClass); $reflectedClass = array('properties' => array('protected' => $reflect->getProperties(\ReflectionProperty::IS_PROTECTED), 'public' => $reflect->getProperties(\ReflectionProperty::IS_PUBLIC)), 'methods' => array('protected' => $reflect->getMethods(\ReflectionProperty::IS_PROTECTED), 'public' => $reflect->getMethods(\ReflectionProperty::IS_PUBLIC))); // Properties foreach's foreach ($reflectedClass['properties']['protected'] as $prop) { $properties['protected'][] = $prop->name; } foreach ($reflectedClass['properties']['public'] as $prop) { $properties['public'][] = $prop->name; } // Methods foreach's foreach ($reflectedClass['methods']['protected'] as $method) { $methods['protected'][] = $method->name; } foreach ($reflectedClass['methods']['public'] as $method) { $methods['public'][] = $method->name; } // Return Array-Object return array('name' => $class, 'object' => $instantiatedClass, 'methods' => $methods, 'properties' => $properties); }
/** * Access to undeclared property. * @throws LogicException */ public function __set($name, $value) { $rc = new \ReflectionClass($this); $items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC)); $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean \${$t}?" : '.'; throw new LogicException("Attempt to write to undeclared property {$rc->getName()}::\${$name}{$hint}"); }
/** * @param \ReflectionClass $reflectionClass * * @return \ReflectionProperty[] */ private function getParentProperties(\ReflectionClass $reflectionClass) { $parent = $reflectionClass->getParentClass(); if ($parent != null) { return array_merge($reflectionClass->getProperties(), $this->getParentProperties($parent)); } return $reflectionClass->getProperties(); }
/** * Gets the properties of the object provided. * * @param int $filter * * @return array */ public function getProperties($filter = \ReflectionProperty::IS_PUBLIC) { $properties = array(); $reflectionProperties = $this->reflectionEntity->getProperties($filter); foreach ($reflectionProperties as $property) { $properties[] = new Property($property->name, $property->isStatic()); } return $properties; }
/** * Gets an array of class properties through a reflection class instance * * @param \ReflectionClass $class * @return array */ public function getClassProperties(\ReflectionClass $class) { $classProperties = []; $classProperties['constant'] = $class->getConstants(); $classProperties['private'] = $class->getProperties(\ReflectionProperty::IS_PRIVATE); $classProperties['protected'] = $class->getProperties(\ReflectionProperty::IS_PROTECTED); $classProperties['public'] = $class->getProperties(\ReflectionProperty::IS_PUBLIC); $classProperties['static'] = $class->getProperties(\ReflectionProperty::IS_STATIC); return $classProperties; }
public function entityProperties() { $fields = array(); $reflection = new \ReflectionClass($this->entityClass); $reflection->getProperties(); foreach ($reflection->getProperties() as $key => $property) { $fields[$key] = $property->getName(); } return $fields; }
/** * Returns an array containing the names of all properties containing a particular annotation. * * @param string $annotation * * @return array */ public function getPropertiesWithAnnotation($annotation) { $properties = array(); foreach ($this->clazz->getProperties() as $property) { $annotations = $this->getPropertyAnnotations($property->getName()); if (array_key_exists($annotation, $annotations)) { $properties[] = $property->getName(); } } return $properties; }
/** * @param string $classname The class to inspect * @param Reader $reader The annotation reader * @throws ClassNotFoundException */ public function __construct($classname, Reader $reader) { try { $this->className = $classname; $this->reader = $reader; $this->reflectionClass = new \ReflectionClass($classname); $this->reflectionMethods = $this->reflectionClass->getMethods(); $this->reflectionProperties = $this->reflectionClass->getProperties(); } catch (\Exception $ex) { throw new ClassNotFoundException(sprintf("cannot find class %s", $classname), $ex->getCode(), $ex); } }
private static function mockInjectedProperties() { /** @var \ReflectionProperty $property */ foreach (self::$reflectedClass->getProperties() as $property) { if (Nette\DI\PhpReflection::parseAnnotation($property, 'inject') !== NULL || Nette\DI\PhpReflection::parseAnnotation($property, 'autowire') !== NULL) { if ($mockedParameterClass = Nette\DI\PhpReflection::parseAnnotation($property, 'var')) { $mockedParameterClass = Nette\DI\PhpReflection::expandClassName($mockedParameterClass, Nette\DI\PhpReflection::getDeclaringClass($property)); } self::setProperty($mockedParameterClass, $property); } } }
public function __construct($model) { $reader = self::getAnnotationReader(); $this->_reflectionClass = new \ReflectionClass($model); /* @var $formAnnotation \SlimForm\Annotation\Form */ $this->_classAnnotation = $reader->getClassAnnotation($this->_reflectionClass, 'SlimForm\\Annotation\\Form'); foreach ($this->_reflectionClass->getProperties() as $property) { $propertyAnnotation = $reader->getPropertyAnnotation($property, 'SlimForm\\Annotation\\RowElement'); if (empty($propertyAnnotation)) { continue; } $this->_propertyAnnotations[] = array('property' => $property, 'annotation' => $propertyAnnotation); } }
public function testGeneralInfoGetters() { $allNameGetters = ['isDefault', 'getName', 'getModifiers', 'getDocComment', 'isPrivate', 'isProtected', 'isPublic', 'isStatic', '__toString']; $allProperties = $this->originalRefClass->getProperties(); foreach ($allProperties as $refProperty) { $propertyName = $refProperty->getName(); $parsedProperty = $this->parsedRefClass->getProperty($propertyName); foreach ($allNameGetters as $getterName) { $expectedValue = $refProperty->{$getterName}(); $actualValue = $parsedProperty->{$getterName}(); $this->assertSame($expectedValue, $actualValue, "{$getterName}() for property {$propertyName} should be equal"); } } }
/** * @covers \vsc\domain\models\ModelA::getProperties */ public function testGetPropertiesWithNonPublic() { $o = new ModelA_underTest_getProperties(); $ToArray = $o->getProperties(true); $oMirror = new \ReflectionClass($o); $aPublicProperties = $oMirror->getProperties(\ReflectionProperty::IS_PUBLIC); $this->assertEquals(3, count($aPublicProperties)); $aProtectedProperties = $oMirror->getProperties(\ReflectionProperty::IS_PROTECTED); $this->assertEquals(3, count($aProtectedProperties)); // this includes IteratorT::$_current $aPrivateProperties = $oMirror->getProperties(\ReflectionProperty::IS_PRIVATE); $this->assertEquals(1, count($aPrivateProperties)); $aProperties = array_merge($aPrivateProperties, $aProtectedProperties, $aPublicProperties); $this->assertEquals(count($ToArray), count($aProperties)); }
private static function compile($exception_type, $object, $message, $parameters = array(), $prefix = null) { if (!is_object($object) && strpos($object, '\\') === false) { return new self(sprintf('Object supplied to %s is not a valid object or namespace.', __CLASS__)); } $rc = new \ReflectionClass($object); $props = array(); switch ($exception_type) { case self::E_CONSTANT: $props = $rc->getConstants(); $props = array_keys($props); break; case self::E_PRIVATE: $props = $rc->getProperties(\ReflectionProperty::IS_PRIVATE); break; case self::E_PUBLIC: $props = $rc->getProperties(\ReflectionProperty::IS_PUBLIC); break; case self::E_PROTECTED: $props = $rc->getProperties(\ReflectionProperty::IS_PROTECTED); break; case self::E_STATIC: $props = $rc->getStaticProperties(); break; } unset($rc); foreach ($props as &$prop) { // match by prefix if (!empty($prefix) && stripos($prop, $prefix) !== 0) { $prop = null; continue; } switch ($exception_type) { case self::E_CONSTANT: $prop = get_class($object) . '::' . $prop; break; case self::E_STATIC: $prop = $prop->class . '::' . $prop->name; break; default: $prop = $prop->class . '->$' . $prop->name; } } $props = array_filter($props); $parameters[] = implode(', ', $props); $message = vsprintf($message, $parameters); return new self($message); }
/** * {@inheritdoc} */ public function getProperties($class, array $context = array()) { try { $reflectionClass = new \ReflectionClass($class); } catch (\ReflectionException $reflectionException) { return; } $reflectionProperties = $reflectionClass->getProperties(); $properties = array(); foreach ($reflectionProperties as $reflectionProperty) { if ($reflectionProperty->isPublic()) { $properties[$reflectionProperty->name] = true; } } foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { $propertyName = $this->getPropertyName($reflectionMethod->name, $reflectionProperties); if (!$propertyName || isset($properties[$propertyName])) { continue; } if (!preg_match('/^[A-Z]{2,}/', $propertyName)) { $propertyName = lcfirst($propertyName); } $properties[$propertyName] = true; } return array_keys($properties); }
/** * */ public function run() { $annotations = []; foreach ($this->reflection->getProperties() as $property) { $docBlock = $property->getDocComment(); if (!$docBlock) { continue; } try { $annotations[$property->getName()] = $this->extractMapperAnnotation($property->getDocComment()); } catch (AnnotationNotFoundException $e) { continue; } } $this->annotations = $annotations; }
public function store($object) { if (!is_object($object)) { throw new Exception('Invalid Entity. Should be object'); } $table = $this->getTableName($object); $values = array(); $reflector = new ReflectionClass($object); foreach ($reflector->getProperties() as $prop) { $comment = $prop->getDocComment(); if (strpos($comment, '@primary') || strpos($comment, '@field')) { $values[$prop->getName()] = $prop->getValue($object); } } $keys = array_keys($values); if (is_null($object->id)) { $str = '`' . implode('`, `', $keys) . '`'; $str2 = ':' . implode(', :', $keys); $sql = "INSERT INTO {$table} ({$str}) VALUES ({$str2})"; $this->execute($sql, $values); $object->id = $this->lastInsertId(); } else { $str = ''; foreach ($keys as $k) { if ($k == 'id') { continue; } $str .= " {$k}=:{$k},"; } $str = rtrim($str, ','); $sql = "UPDATE {$table} SET {$str} WHERE id = :id"; $this->execute($sql, $values); } return $object; }
/** * Restores all static attributes in user-defined classes from this snapshot. * * @param Snapshot $snapshot */ public function restoreStaticAttributes(Snapshot $snapshot) { $current = new Snapshot($snapshot->blacklist(), false, false, false, false, true, false, false, false, false); $newClasses = array_diff($current->classes(), $snapshot->classes()); unset($current); foreach ($snapshot->staticAttributes() as $className => $staticAttributes) { foreach ($staticAttributes as $name => $value) { $reflector = new ReflectionProperty($className, $name); $reflector->setAccessible(true); $reflector->setValue($value); } } foreach ($newClasses as $className) { $class = new \ReflectionClass($className); $defaults = $class->getDefaultProperties(); foreach ($class->getProperties() as $attribute) { if (!$attribute->isStatic()) { continue; } $name = $attribute->getName(); if ($snapshot->blacklist()->isStaticAttributeBlacklisted($className, $name)) { continue; } if (!isset($defaults[$name])) { continue; } $attribute->setAccessible(true); $attribute->setValue($defaults[$name]); } } }
/** * @param \ReflectionClass|string * @return self */ public static function from($from) { $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from); if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) { $class = new static('anonymous'); } else { $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName())); } $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class'); $class->final = $from->isFinal() && $class->type === 'class'; $class->abstract = $from->isAbstract() && $class->type === 'class'; $class->implements = $from->getInterfaceNames(); $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array(); if ($from->getParentClass()) { $class->extends = $from->getParentClass()->getName(); $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames()); } foreach ($from->getProperties() as $prop) { if ($prop->getDeclaringClass()->getName() === $from->getName()) { $class->properties[$prop->getName()] = Property::from($prop); } } foreach ($from->getMethods() as $method) { if ($method->getDeclaringClass()->getName() === $from->getName()) { $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace); } } return $class; }
public static function fromEvent(DomainEvent $event) { $refEvent = new \ReflectionClass($event); $refEventProperties = $refEvent->getProperties(); $properties = []; $convertPropertyValueAsString = function ($propertyValue) { if (true === is_array($propertyValue)) { return implode(', ', $propertyValue); } if ($propertyValue instanceof \DateTimeInterface) { return $propertyValue->format('Y-m-d H:i:s'); } return (string) $propertyValue; }; foreach ($refEventProperties as $property) { $propertyName = $property->getName(); $getter = 'get' . ucfirst($propertyName); if (false === method_exists($event, $getter)) { throw new \LogicException(sprintf('Each event property should have a getter. Missing %s::%s', get_class($event), $getter)); } $propertyValue = $event->{$getter}(); $properties[$propertyName] = $convertPropertyValueAsString($propertyValue); } return new EventProperties($properties); }
/** * Add a complex type by recursivly using all the class properties fetched via Reflection. * * @param string $type Name of the class to be specified * @return string XSD Type for the given PHP type */ public function addComplexType($type) { if (!class_exists($type)) { #require_once "Zend/Soap/Wsdl/Exception.php"; throw new Zend_Soap_Wsdl_Exception(sprintf("Cannot add a complex type %s that is not an object or where " . "class could not be found in 'DefaultComplexType' strategy.", $type)); } $dom = $this->getContext()->toDomDocument(); $class = new ReflectionClass($type); $defaultProperties = $class->getDefaultProperties(); $complexType = $dom->createElement('xsd:complexType'); $complexType->setAttribute('name', $type); $all = $dom->createElement('xsd:all'); foreach ($class->getProperties() as $property) { if ($property->isPublic() && preg_match_all('/@var\\s+([^\\s]+)/m', $property->getDocComment(), $matches)) { /** * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType' * node for describing other classes used as attribute types for current class */ $element = $dom->createElement('xsd:element'); $element->setAttribute('name', $propertyName = $property->getName()); $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0]))); // If the default value is null, then this property is nillable. if ($defaultProperties[$propertyName] === null) { $element->setAttribute('nillable', 'true'); } $all->appendChild($element); } } $complexType->appendChild($all); $this->getContext()->getSchema()->appendChild($complexType); $this->getContext()->addType($type); return "tns:{$type}"; }
/** * put your comment there... * * @param mixed $class * @param mixed $options */ public function define($className, $options = array()) { $definition = array(); $definition['options'] = $options; // Get class properties to find out the events! $class = new ReflectionClass($className); $properties = $class->getProperties(ReflectionProperty::IS_PROTECTED); $values = $class->getDefaultProperties(); // protected (static + non-static) represent an event! foreach ($properties as $property) { $propertyName = $property->getName(); $propertyClass = $property->getDeclaringClass()->getName(); if (strpos($propertyName, $options['prefix']) === 0) { // Get event properties! $eventName = substr($propertyName, strlen($options['prefix'])); // If the event is already defined inherits the options! $inheritedOptions = array(); if (isset($this->definitions[$propertyClass]['events'][$propertyName])) { $inheritedOptions = $this->definitions[$propertyClass]['events'][$propertyName]['type']; } $definition['events'][$propertyName] = array('fullName' => $propertyName, 'name' => $eventName, 'class' => $propertyClass, 'id' => $eventName, 'type' => array_merge($options, $inheritedOptions, (array) $values[$propertyName])); } } $this->definitions[$className] = $this->extend($definition); return $this; }
/** * {@inheritdoc} */ protected function extractAttributes($object, $format = null, array $context = array()) { // If not using groups, detect manually $attributes = array(); // methods $reflClass = new \ReflectionClass($object); foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) { if ($reflMethod->getNumberOfRequiredParameters() !== 0 || $reflMethod->isStatic() || $reflMethod->isConstructor() || $reflMethod->isDestructor()) { continue; } $name = $reflMethod->name; if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) { // getters and hassers $attributeName = lcfirst(substr($name, 3)); } elseif (strpos($name, 'is') === 0) { // issers $attributeName = lcfirst(substr($name, 2)); } if ($this->isAllowedAttribute($object, $attributeName)) { $attributes[$attributeName] = true; } } // properties foreach ($reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflProperty) { if ($reflProperty->isStatic() || !$this->isAllowedAttribute($object, $reflProperty->name)) { continue; } $attributes[$reflProperty->name] = true; } return array_keys($attributes); }
/** * Searches a given annotation for a specified property. If given, the value is returned, otherwise (when not found) null is returned. * * @param string $strProperty * @param string $strAnnotation * @param class_reflection_enum $objEnum - whether to return annotation values or parameters, default is values * * @return null|string */ public function getAnnotationValueForProperty($strProperty, $strAnnotation, class_reflection_enum $objEnum = null) { if ($objEnum == null) { $objEnum = class_reflection_enum::VALUES(); } $arrProperties = $this->objReflectionClass->getProperties(); foreach ($arrProperties as $objOneProperty) { if ($objOneProperty->getName() == $strProperty) { $strFirstAnnotation = $this->searchFirstAnnotationInDoc($objOneProperty->getDocComment(), $strAnnotation); if ($objEnum->equals(class_reflection_enum::VALUES())) { $strFirstAnnotation = $strFirstAnnotation["values"][0]; } else { if ($objEnum->equals(class_reflection_enum::PARAMS())) { $strFirstAnnotation = $strFirstAnnotation["params"][0]; } } if ($strFirstAnnotation !== false) { return $strFirstAnnotation; } } } //check if there's a base-class -> inheritance $objBaseClass = $this->objReflectionClass->getParentClass(); if ($objBaseClass !== false) { $objBaseAnnotations = new class_reflection($objBaseClass->getName()); return $objBaseAnnotations->getAnnotationValueForProperty($strProperty, $strAnnotation, $objEnum); } return null; }
public function getProperties($className) { $properties = []; if (!class_exists($className)) { throw new ReaderException(sprintf('The class "%s" is not on the PHP include path', $className)); } $class = new \ReflectionClass($className); foreach ($class->getProperties() as $property) { $m = preg_match('/ @Drift\\\\ (?P<type>[A-Z][a-zA-Z]+) \\( (?P<spec>.+?)? \\) /xms', $property->getDocComment(), $matches); if (!$m) { continue; } $config = ['type' => strtolower($matches['type']), 'field' => null, 'options' => []]; if (isset($matches['spec'])) { $spec = $this->parseSpec($matches['spec']); if (isset($spec['field'])) { $config['field'] = $spec['field']; unset($spec['field']); } $config['options'] = $spec; } if (!$config['field']) { $config['field'] = $property->getName(); } $properties[$property->getName()] = $config; } return $properties; }