当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionProperty::getDeclaringClass方法代码示例

本文整理汇总了PHP中ReflectionProperty::getDeclaringClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty::getDeclaringClass方法的具体用法?PHP ReflectionProperty::getDeclaringClass怎么用?PHP ReflectionProperty::getDeclaringClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionProperty的用法示例。


在下文中一共展示了ReflectionProperty::getDeclaringClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: defaultValue

 public function defaultValue()
 {
     if ($this->property->isDefault()) {
         $defaultProperties = $this->property->getDeclaringClass()->getDefaultProperties();
         return $defaultProperties[$this->property->getName()];
     }
     return null;
 }
开发者ID:watoki,项目名称:reflect,代码行数:8,代码来源:InstanceVariableProperty.php

示例2: getDeclaringClass

 /**
  * Returns declaring class or trait.
  * @return \ReflectionClass
  */
 public static function getDeclaringClass(\ReflectionProperty $prop)
 {
     foreach ($prop->getDeclaringClass()->getTraits() as $trait) {
         if ($trait->hasProperty($prop->getName())) {
             return self::getDeclaringClass($trait->getProperty($prop->getName()));
         }
     }
     return $prop->getDeclaringClass();
 }
开发者ID:Northys,项目名称:di,代码行数:13,代码来源:PhpReflection.php

示例3: exportCode

 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $default_properties = $this->_property->getDeclaringClass()->getDefaultProperties();
     $modifiers = \Reflection::getModifierNames($this->_property->getModifiers());
     $default_value = null;
     if (array_key_exists($this->_property->getName(), $default_properties)) {
         $default_value = $default_properties[$this->_property->getName()];
         if (!is_numeric($default_value)) {
             $default_value = "'{$default_value}'";
         }
     }
     return sprintf('%s $%s%s;', join(' ', $modifiers), $this->_property->getName(), !is_null($default_value) ? " = {$default_value}" : '');
 }
开发者ID:michalkoslab,项目名称:Helpers,代码行数:18,代码来源:ReflectionProperty.php

示例4: getPropertyClass

 /**
  * Parse the docblock of the property to get the class of the var annotation.
  *
  * @param \ReflectionProperty $property
  *
  * @throws AnnotationException Non exists class.
  *
  * @return null|ObjectDefinition
  */
 public function getPropertyClass(\ReflectionProperty $property)
 {
     $propertyComment = $property->getDocComment();
     if (!preg_match('/@var\\s+([^\\s\\(\\*\\/]+)/', $propertyComment, $matches)) {
         return;
     }
     $className = end($matches);
     if (!is_string($className) || in_array($className, static::$ignoredTypes)) {
         return;
     }
     $classWithNamespace = $className;
     if ($this->namespaceExists($classWithNamespace) === false) {
         $classWithNamespace = $this->namespace . '\\' . $className;
     }
     if (!$this->classExists($classWithNamespace)) {
         $declaringClass = $property->getDeclaringClass();
         throw new AnnotationException(sprintf('The @var annotation on %s::%s contains a non existent class "%s"', $declaringClass->name, $property->getName(), $className));
     }
     $createNewObject = function ($propertyComment, $className, $classWithNamespace) {
         $classParameters = $this->propertyClassParameters($propertyComment, $className);
         if (is_array($classParameters)) {
             $values = [];
             foreach ($classParameters as $value) {
                 $values[] = static::parseValue($value);
             }
             $object = new ObjectDefinition($classWithNamespace, $className);
             $object->setConstructorInjection($values);
             return $object;
         }
         return new $classWithNamespace();
     };
     return $createNewObject($propertyComment, $className, $classWithNamespace);
 }
开发者ID:devstackphp,项目名称:di,代码行数:42,代码来源:PhpDocReader.php

示例5: getDeclaringClassName

 private function getDeclaringClassName($propertyName)
 {
     $reflection = new ReflectionProperty(get_class($this), $propertyName);
     $declaringClass = $reflection->getDeclaringClass();
     $className = $declaringClass->getName();
     return $className;
 }
开发者ID:panigh,项目名称:server,代码行数:7,代码来源:KalturaObject.php

示例6: getTypeOfProperty

 private function getTypeOfProperty(\ReflectionProperty $prop)
 {
     if (preg_match('/^[\\s\\/*]*@var\\s+(\\S+)/m', $prop->getDocComment(), $matches)) {
         return $this->getFullNameOfType($matches[1], $prop->getDeclaringClass());
     }
     return;
 }
开发者ID:ranyuen,项目名称:di,代码行数:7,代码来源:Type.php

示例7: getPropertyLine

 /**
  * @param \ReflectionProperty $property
  * @return int
  */
 public static function getPropertyLine(\ReflectionProperty $property)
 {
     $class = $property->getDeclaringClass();
     $context = 'file';
     $contextBrackets = 0;
     foreach (token_get_all(file_get_contents($class->getFileName())) as $token) {
         if ($token === '{') {
             $contextBrackets += 1;
         } elseif ($token === '}') {
             $contextBrackets -= 1;
         }
         if (!is_array($token)) {
             continue;
         }
         if ($token[0] === T_CLASS) {
             $context = 'class';
             $contextBrackets = 0;
         } elseif ($context === 'class' && $contextBrackets === 1 && $token[0] === T_VARIABLE) {
             if ($token[1] === '$' . $property->getName()) {
                 return $token[2];
             }
         }
     }
     return NULL;
 }
开发者ID:kdyby,项目名称:doctrine,代码行数:29,代码来源:Helpers.php

示例8: getDeclaringClass

 /**
  * Get declaring class reflection object
  *
  * @return ClassReflection
  */
 public function getDeclaringClass()
 {
     $phpReflection = parent::getDeclaringClass();
     $zendReflection = new ClassReflection($phpReflection->getName());
     unset($phpReflection);
     return $zendReflection;
 }
开发者ID:tillk,项目名称:vufind,代码行数:12,代码来源:PropertyReflection.php

示例9: getSetter

 /**
  * @param \ReflectionProperty $property
  *
  * @return \ReflectionMethod|null
  */
 public function getSetter(\ReflectionProperty $property)
 {
     $setter = sprintf(static::SETTER_FORMAT, ucfirst($property->getName()));
     $class = $property->getDeclaringClass();
     if ($class->hasMethod($setter)) {
         return $class->getMethod($setter);
     }
 }
开发者ID:mihai-stancu,项目名称:php-property-info,代码行数:13,代码来源:NativeTypeInfoParser.php

示例10: getXmlNamespace

 public function getXmlNamespace()
 {
     $namespace = $this->_parseAnnotation($this->property->getDocComment(), 'xmlNamespace');
     if (!$namespace && $this->configuration) {
         $value = $this->getValue();
         if (is_object($this->getValue())) {
             $classMeta = new ClassMetadata($this->getValue(), $this->configuration);
             $namespace = $classMeta->getXmlNamespace();
         } elseif (is_array($value) && count($value) > 0) {
             $classMeta = new ClassMetadata($this->getValue()[0], $this->configuration);
             $namespace = $classMeta->getXmlNamespace();
         } else {
             $classNamespace = $this->property->getDeclaringClass()->getNamespaceName();
             $namespace = $this->configuration->getXmlNamespace($classNamespace);
         }
     }
     return $namespace;
 }
开发者ID:ddvzwzjm,项目名称:xml-serializer,代码行数:18,代码来源:PropertyMetadata.php

示例11: getDeclaringClass

 /**
  * Returns the declaring class.
  *
  * @return ezcReflectionClass
  */
 public function getDeclaringClass()
 {
     if ($this->reflectionSource instanceof ReflectionProperty) {
         return new ezcReflectionClass($this->reflectionSource->getDeclaringClass());
     } else {
         $class = parent::getDeclaringClass();
         return new ezcReflectionClass($class->getName());
     }
 }
开发者ID:naderman,项目名称:ezc-reflection,代码行数:14,代码来源:property.php

示例12: setValue

 /**
  * {@inheritDoc}
  */
 public function setValue(\ReflectionProperty $property, $object, $value)
 {
     $propertyName = $property->getName();
     $declaringClass = $property->getDeclaringClass();
     $setterName = sprintf('set%s', ucfirst($propertyName));
     if (!$declaringClass->hasMethod($setterName)) {
         throw new \RuntimeException('No setter found for "' . $propertyName . '"');
     }
     $declaringClass->getMethod($setterName)->invoke($object, $value);
 }
开发者ID:exeu,项目名称:objectmerger,代码行数:13,代码来源:PublicMethodAccessor.php

示例13: asInstance

 /**
  * @param object|NULL
  * @return AccessBase $this
  */
 public function asInstance($object)
 {
     if (is_object($object)) {
         if ($this->reflection instanceof ReflectionClass) {
             $class = $this->reflection->getName();
         } else {
             $class = $this->reflection->getDeclaringClass()->getName();
         }
         if (!$object instanceof $class) {
             throw new Exception('Must be instance of accessible class.');
         }
     } else {
         if ($object !== NULL) {
             throw new Exception('Instance must be object or NULL.');
         }
     }
     $this->instance = $object;
     return $this;
 }
开发者ID:petrp,项目名称:access,代码行数:23,代码来源:Base.php

示例14: match

 public static function match(\ReflectionProperty $property, $matches = array())
 {
     $comment = static::get($property->getDeclaringClass()->getName(), $property->getName());
     foreach ($matches as $match) {
         if (preg_match("|{$match}|", $comment)) {
             return true;
         }
     }
     return false;
 }
开发者ID:ncud,项目名称:sagalaya,代码行数:10,代码来源:ModelAnnotation.php

示例15: from

 /**
  * @return self
  */
 public static function from(\ReflectionProperty $from)
 {
     $prop = new static($from->getName());
     $defaults = $from->getDeclaringClass()->getDefaultProperties();
     $prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
     $prop->static = $from->isStatic();
     $prop->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public');
     $prop->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
     return $prop;
 }
开发者ID:pavel81,项目名称:php-generator,代码行数:13,代码来源:Property.php


注:本文中的ReflectionProperty::getDeclaringClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。