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


PHP Reflector::getDeclaringClass方法代码示例

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


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

示例1: getAll

	/**
	 * Returns annotations.
	 * @param  \ReflectionClass|\ReflectionMethod|\ReflectionProperty
	 * @return array
	 */
	public static function getAll(\Reflector $r)
	{
		if ($r instanceof \ReflectionClass) {
			$type = $r->getName();
			$member = '';

		} elseif ($r instanceof \ReflectionMethod) {
			$type = $r->getDeclaringClass()->getName();
			$member = $r->getName();

		} else {
			$type = $r->getDeclaringClass()->getName();
			$member = '$' . $r->getName();
		}

		if (!self::$useReflection) { // auto-expire cache
			$file = $r instanceof \ReflectionClass ? $r->getFileName() : $r->getDeclaringClass()->getFileName(); // will be used later
			if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) {
				unset(self::$cache[$type]);
			}
			unset(self::$timestamps[$file]);
		}

		if (isset(self::$cache[$type][$member])) { // is value cached?
			return self::$cache[$type][$member];
		}

		if (self::$useReflection === NULL) { // detects whether is reflection available
			self::$useReflection = (bool) Nette\Reflection\ClassReflection::from(__CLASS__)->getDocComment();
		}

		if (self::$useReflection) {
			return self::$cache[$type][$member] = self::parseComment($r->getDocComment());

		} else {
			if (self::$cache === NULL) {
				self::$cache = (array) self::getCache()->offsetGet('list');
				self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : array();
			}

			if (!isset(self::$cache[$type]) && $file) {
				self::$cache['*'][$file] = filemtime($file);
				self::parseScript($file);
				self::getCache()->save('list', self::$cache);
			}

			if (isset(self::$cache[$type][$member])) {
				return self::$cache[$type][$member];
			} else {
				return self::$cache[$type][$member] = array();
			}
		}
	}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:58,代码来源:AnnotationsParser.php

示例2: getAnnotationsFor

 /**
  * Get annotations for reflector
  *
  * @param \Reflector $reflector
  *
  * @return array
  */
 public function getAnnotationsFor(\Reflector $reflector)
 {
     if ($reflector instanceof \ReflectionClass) {
         return $this->getClassAnnotations($reflector->getName());
     } elseif ($reflector instanceof \ReflectionMethod) {
         return $this->getMethodAnnotations($reflector->getDeclaringClass()->getName(), $reflector->getName());
     } elseif ($reflector instanceof \ReflectionProperty) {
         return $this->getPropertyAnnotations($reflector->getDeclaringClass()->getName(), $reflector->getName());
     } else {
         return [];
     }
 }
开发者ID:thinframe,项目名称:annotations,代码行数:19,代码来源:Collector.php

示例3: getDeclaringClass

 /**
  * Returns the ReflectionClass of the given Reflector.
  *
  * @param \Reflector $reflector
  *
  * @return \ReflectionClass|null
  */
 private function getDeclaringClass(\Reflector $reflector)
 {
     if ($reflector instanceof \ReflectionClass) {
         return $reflector;
     }
     if ($reflector instanceof \ReflectionProperty) {
         return $reflector->getDeclaringClass();
     }
     if ($reflector instanceof \ReflectionMethod) {
         return $reflector->getDeclaringClass();
     }
     if ($reflector instanceof \ReflectionParameter) {
         return $reflector->getDeclaringClass();
     }
     return null;
 }
开发者ID:brick,项目名称:reflection,代码行数:23,代码来源:ImportResolver.php

示例4: getCodeDocs

 /**
  * @param \Reflector $reflection
  * @param string $type
  *   If we are not reflecting the class itself, specify "Method", "Property", etc.
  *
  * @return array
  */
 public static function getCodeDocs($reflection, $type = NULL)
 {
     $docs = self::parseDocBlock($reflection->getDocComment());
     // Recurse into parent functions
     if (isset($docs['inheritDoc'])) {
         unset($docs['inheritDoc']);
         $newReflection = NULL;
         try {
             if ($type) {
                 $name = $reflection->getName();
                 $reflectionClass = $reflection->getDeclaringClass()->getParentClass();
                 if ($reflectionClass) {
                     $getItem = "get{$type}";
                     $newReflection = $reflectionClass->{$getItem}($name);
                 }
             } else {
                 $newReflection = $reflection->getParentClass();
             }
         } catch (\ReflectionException $e) {
         }
         if ($newReflection) {
             // Mix in
             $additionalDocs = self::getCodeDocs($newReflection, $type);
             if (!empty($docs['comment']) && !empty($additionalDocs['comment'])) {
                 $docs['comment'] .= "\n\n" . $additionalDocs['comment'];
             }
             $docs += $additionalDocs;
         }
     }
     return $docs;
 }
开发者ID:civicrm,项目名称:api4,代码行数:38,代码来源:ReflectionUtils.php

示例5: _make_internal_message

	protected function _make_internal_message(\Reflector $reflection) {
		$type = false;
		$name = false;
		$location = false;
		
		if($reflection instanceof \ReflectionFunction) {
			$type = 'function';
			$name = $reflection->name;
		}
		elseif($reflection instanceof \ReflectionClass) {
			$type = 'class';
			$name = $reflection->name;
		}
		elseif($reflection instanceof \ReflectionMethod) {
			$type = 'method';
			$name = $reflection->getDeclaringClass()->name . '::' . $reflection->name;
		}
		
		$location = $reflection->getFileName() . ':' . $reflection->getStartLine();
		
		Ev\Evaluer::make_internal_from(
			Ev\Evaluer::SOURCE_OUTPUT,
			sprintf("Source Code for %s '%s' (%s)", $type, $name, $location)
		);
	}
开发者ID:rATRIJS,项目名称:AIP,代码行数:25,代码来源:AIPLang_Function_SHOW_SOURCE.php

示例6: getType

 public function getType(\Reflector $reflector)
 {
     if (!$reflector instanceof \ReflectionProperty && !$reflector instanceof \ReflectionMethod) {
         throw new \InvalidArgumentException('Argument "reflector" should be instance of \\ReflectionProperty or \\ReflectionMethod');
     }
     if (null === ($tokenizedClass = $this->getTokenizedReflectionClass($reflector->getDeclaringClass()))) {
         return null;
     }
     if ($reflector instanceof \ReflectionProperty) {
         $name = self::PROPERTY_ANNOTATION_NAME;
         $annotations = $tokenizedClass->getProperty($reflector->name)->getAnnotations();
     } else {
         $name = self::METHOD_ANNOTATION_NAME;
         $annotations = $tokenizedClass->getMethod($reflector->name)->getAnnotations();
     }
     return isset($annotations[$name]) ? $this->parseType($annotations[$name], $tokenizedClass) : null;
 }
开发者ID:idr0id,项目名称:papper,代码行数:17,代码来源:AnnotationTypeReader.php

示例7: resolveElementType

 /**
  * @param \Reflector $reflector
  * @param string $tagName
  *
  * @return string|null
  */
 public function resolveElementType(\Reflector $reflector, $tagName)
 {
     $docBlock = new DocBlock($reflector);
     $returnTags = $docBlock->getTagsByName($tagName);
     /** @var ReturnTag $returnTag */
     $returnTag = reset($returnTags);
     $type = $returnTag->getType();
     $isCollection = false;
     if ($extractedType = $this->extractTypeFromCollectionType($type)) {
         $isCollection = true;
         $type = $extractedType;
     }
     if (static::isTypeObject($type) && ($reflector instanceof \ReflectionMethod || $reflector instanceof \ReflectionProperty)) {
         $type = $this->resolveClassName($type, $reflector->getDeclaringClass());
     }
     return $type . ($isCollection ? '[]' : '');
 }
开发者ID:tonicforhealth,项目名称:json-rpc,代码行数:23,代码来源:TypeResolver.php

示例8: array

 /**
  * Parses and caches annotations.
  * @param  ReflectionClass|\ReflectionMethod|\ReflectionProperty
  * @return array
  */
 public static function &init(Reflector $r)
 {
     $cache =& self::$cache[$r->getName()][$r instanceof ReflectionClass ? '' : $r->getDeclaringClass()->getName()];
     if ($cache !== NULL) {
         return $cache;
     }
     preg_match_all('#@([a-zA-Z0-9_]+)(?:\\(((?>[^\'")]+|\'[^\']*\'|"[^"]*")*)\\))?#', $r->getDocComment(), $matches, PREG_SET_ORDER);
     $cache = array();
     foreach ($matches as $match) {
         if (isset($match[2])) {
             preg_match_all('#[,\\s](?>([a-zA-Z0-9_]+)\\s*=\\s*)?([^\'",\\s][^,]*|\'[^\']*\'|"[^"]*")#', ',' . $match[2], $matches, PREG_SET_ORDER);
             $items = array();
             $key = '';
             $val = TRUE;
             foreach ($matches as $m) {
                 list(, $key, $val) = $m;
                 if ($val[0] === "'" || $val[0] === '"') {
                     $val = substr($val, 1, -1);
                 } elseif (strcasecmp($val, 'true') === 0) {
                     $val = TRUE;
                 } elseif (strcasecmp($val, 'false') === 0) {
                     $val = FALSE;
                 } elseif (is_numeric($val)) {
                     $val = 1 * $val;
                 }
                 if ($key === '') {
                     $items[] = $val;
                 } else {
                     $items[$key] = $val;
                 }
             }
             $items = count($items) < 2 && $key === '' ? $val : new ArrayObject($items, ArrayObject::ARRAY_AS_PROPS);
         } else {
             $items = TRUE;
         }
         $cache[$match[1]][] = $items;
     }
     return $cache;
 }
开发者ID:jakubkulhan,项目名称:shopaholic,代码行数:44,代码来源:Annotations.php

示例9: __construct

 /**
  * Constructor
  *
  * @param ReflectionFunction $r
  */
 public function __construct(Reflector $r, $namespace = null, $argv = array())
 {
     // In PHP 5.1.x, ReflectionMethod extends ReflectionFunction. In 5.2.x,
     // both extend ReflectionFunctionAbstract. So, we can't do normal type
     // hinting in the prototype, but instead need to do some explicit
     // testing here.
     if (!$r instanceof ReflectionFunction && !$r instanceof ReflectionMethod) {
         require_once 'Zend/Server/Reflection/Exception.php';
         throw new Zend_Server_Reflection_Exception('Invalid reflection class');
     }
     $this->_reflection = $r;
     // Determine namespace
     if (null !== $namespace) {
         $this->setNamespace($namespace);
     }
     // Determine arguments
     if (is_array($argv)) {
         $this->_argv = $argv;
     }
     // If method call, need to store some info on the class
     if ($r instanceof ReflectionMethod) {
         $this->_class = $r->getDeclaringClass()->getName();
     }
     // Perform some introspection
     $this->_reflect();
 }
开发者ID:georgepaul,项目名称:socialstrap,代码行数:31,代码来源:Abstract.php

示例10: getAll

 /**
  * Returns annotations.
  * @param  \ReflectionClass|\ReflectionMethod|\ReflectionProperty
  * @return array
  */
 public static function getAll(\Reflector $r)
 {
     if ($r instanceof \ReflectionClass) {
         $type = $r->getName();
         $member = 'class';
     } elseif ($r instanceof \ReflectionMethod) {
         $type = $r->getDeclaringClass()->getName();
         $member = $r->getName();
     } else {
         $type = $r->getDeclaringClass()->getName();
         $member = '$' . $r->getName();
     }
     if (!self::$useReflection) {
         // auto-expire cache
         $file = $r instanceof \ReflectionClass ? $r->getFileName() : $r->getDeclaringClass()->getFileName();
         // will be used later
         if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) {
             unset(self::$cache[$type]);
         }
         unset(self::$timestamps[$file]);
     }
     if (isset(self::$cache[$type][$member])) {
         // is value cached?
         return self::$cache[$type][$member];
     }
     if (self::$useReflection === NULL) {
         // detects whether is reflection available
         self::$useReflection = (bool) ClassType::from(__CLASS__)->getDocComment();
     }
     if (self::$useReflection) {
         $annotations = self::parseComment($r->getDocComment());
     } else {
         if (!self::$cacheStorage) {
             // trigger_error('Set a cache storage for annotations parser via Nette\Reflection\AnnotationParser::setCacheStorage().', E_USER_WARNING);
             self::$cacheStorage = new Nette\Caching\Storages\DevNullStorage();
         }
         $outerCache = new Nette\Caching\Cache(self::$cacheStorage, 'Nette.Reflection.Annotations');
         if (self::$cache === NULL) {
             self::$cache = (array) $outerCache->load('list');
             self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : array();
         }
         if (!isset(self::$cache[$type]) && $file) {
             self::$cache['*'][$file] = filemtime($file);
             foreach (self::parsePhp(file_get_contents($file)) as $class => $info) {
                 foreach ($info as $prop => $comment) {
                     if ($prop !== 'use') {
                         self::$cache[$class][$prop] = self::parseComment($comment);
                     }
                 }
             }
             $outerCache->save('list', self::$cache);
         }
         if (isset(self::$cache[$type][$member])) {
             $annotations = self::$cache[$type][$member];
         } else {
             $annotations = array();
         }
     }
     if ($r instanceof \ReflectionMethod && !$r->isPrivate() && (!$r->isConstructor() || !empty($annotations['inheritdoc'][0]))) {
         try {
             $inherited = self::getAll(new \ReflectionMethod(get_parent_class($type), $member));
         } catch (\ReflectionException $e) {
             try {
                 $inherited = self::getAll($r->getPrototype());
             } catch (\ReflectionException $e) {
                 $inherited = array();
             }
         }
         $annotations += array_intersect_key($inherited, array_flip(self::$inherited));
     }
     return self::$cache[$type][$member] = $annotations;
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:77,代码来源:AnnotationsParser.php

示例11: findRenamed

 /**
  * @param \Reflector|Nette\Reflection\ClassType|Nette\Reflection\Method $refl
  * @param $annotation
  */
 private static function findRenamed(\Reflector $refl, $annotation)
 {
     $parser = new Doctrine\Common\Annotations\PhpParser();
     $imports = $parser->parseClass($refl instanceof \ReflectionClass ? $refl : $refl->getDeclaringClass());
     $annotationClass = ltrim($annotation, '@');
     foreach ($imports as $alias => $import) {
         if (!Strings::startsWith($annotationClass, $import)) {
             continue;
         }
         $aliased = str_replace(Strings::lower($import), $alias, Strings::lower($annotationClass));
         $searchFor = preg_quote(Strings::lower($aliased));
         if (!($m = Strings::match($refl->getDocComment(), "~(?P<usage>@?{$searchFor})~i"))) {
             continue;
         }
         return $m['usage'];
     }
     return $annotation;
 }
开发者ID:LidskaSila,项目名称:Doctrine,代码行数:22,代码来源:Panel.php

示例12: getAll

 static function getAll(\Reflector $r)
 {
     if ($r instanceof \ReflectionClass) {
         $type = $r->getName();
         $member = '';
     } elseif ($r instanceof \ReflectionMethod) {
         $type = $r->getDeclaringClass()->getName();
         $member = $r->getName();
     } else {
         $type = $r->getDeclaringClass()->getName();
         $member = '$' . $r->getName();
     }
     if (!self::$useReflection) {
         $file = $r instanceof \ReflectionClass ? $r->getFileName() : $r->getDeclaringClass()->getFileName();
         if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) {
             unset(self::$cache[$type]);
         }
         unset(self::$timestamps[$file]);
     }
     if (isset(self::$cache[$type][$member])) {
         return self::$cache[$type][$member];
     }
     if (self::$useReflection === NULL) {
         self::$useReflection = (bool) ClassType::from(__CLASS__)->getDocComment();
     }
     if (self::$useReflection) {
         $annotations = self::parseComment($r->getDocComment());
     } else {
         if (!self::$cacheStorage) {
             self::$cacheStorage = new Nette\Caching\Storages\DevNullStorage();
         }
         $outerCache = new Nette\Caching\Cache(self::$cacheStorage, 'Nette.Reflection.Annotations');
         if (self::$cache === NULL) {
             self::$cache = (array) $outerCache->offsetGet('list');
             self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : array();
         }
         if (!isset(self::$cache[$type]) && $file) {
             self::$cache['*'][$file] = filemtime($file);
             self::parseScript($file);
             $outerCache->save('list', self::$cache);
         }
         if (isset(self::$cache[$type][$member])) {
             $annotations = self::$cache[$type][$member];
         } else {
             $annotations = array();
         }
     }
     if ($r instanceof \ReflectionMethod && !$r->isPrivate() && (!$r->isConstructor() || !empty($annotations['inheritdoc'][0]))) {
         try {
             $inherited = self::getAll(new \ReflectionMethod(get_parent_class($type), $member));
         } catch (\ReflectionException $e) {
             try {
                 $inherited = self::getAll($r->getPrototype());
             } catch (\ReflectionException $e) {
                 $inherited = array();
             }
         }
         $annotations += array_intersect_key($inherited, array_flip(self::$inherited));
     }
     return self::$cache[$type][$member] = $annotations;
 }
开发者ID:rotten77,项目名称:xcv,代码行数:61,代码来源:nette.min.php

示例13: getAll

 static function getAll(Reflector $r)
 {
     if ($r instanceof ReflectionClass) {
         $type = $r->getName();
         $member = '';
     } elseif ($r instanceof ReflectionMethod) {
         $type = $r->getDeclaringClass()->getName();
         $member = $r->getName();
     } else {
         $type = $r->getDeclaringClass()->getName();
         $member = '$' . $r->getName();
     }
     if (!self::$useReflection) {
         $file = $r instanceof ReflectionClass ? $r->getFileName() : $r->getDeclaringClass()->getFileName();
         if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) {
             unset(self::$cache[$type]);
         }
         unset(self::$timestamps[$file]);
     }
     if (isset(self::$cache[$type][$member])) {
         return self::$cache[$type][$member];
     }
     if (self::$useReflection === NULL) {
         self::$useReflection = (bool) NClassReflection::from(__CLASS__)->getDocComment();
     }
     if (self::$useReflection) {
         return self::$cache[$type][$member] = self::parseComment($r->getDocComment());
     } else {
         if (self::$cache === NULL) {
             self::$cache = (array) self::getCache()->offsetGet('list');
             self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : array();
         }
         if (!isset(self::$cache[$type]) && $file) {
             self::$cache['*'][$file] = filemtime($file);
             self::parseScript($file);
             self::getCache()->save('list', self::$cache);
         }
         if (isset(self::$cache[$type][$member])) {
             return self::$cache[$type][$member];
         } else {
             return self::$cache[$type][$member] = array();
         }
     }
 }
开发者ID:kacer,项目名称:FakturoidPairing,代码行数:44,代码来源:nette.php

示例14: resolveAnnotationClass

 private function resolveAnnotationClass(\Reflector $prop, $annotationValue, $annotationName)
 {
     /** @var Property|Method $prop */
     if (!($type = ltrim($annotationValue, '\\'))) {
         throw new \Kdyby\Autowired\InvalidStateException("Missing annotation @{$annotationName} with typehint on {$prop}.", $prop);
     }
     if (!class_exists($type) && !interface_exists($type)) {
         if (substr(func_get_arg(1), 0, 1) === '\\') {
             throw new \Kdyby\Autowired\MissingClassException("Class \"{$type}\" was not found, please check the typehint on {$prop} in annotation @{$annotationName}.", $prop);
         }
         if (!class_exists($type = $prop->getDeclaringClass()->getNamespaceName() . '\\' . $type) && !interface_exists($type)) {
             throw new \Kdyby\Autowired\MissingClassException("Neither class \"" . func_get_arg(1) . "\" or \"{$type}\" was found, please check the typehint on {$prop} in annotation @{$annotationName}.", $prop);
         }
     }
     return \Nette\Reflection\ClassType::from($type)->getName();
 }
开发者ID:frosty22,项目名称:ale,代码行数:16,代码来源:Presenter.php

示例15: getAll

 /**
  * Returns annotations.
  * @param  \ReflectionClass|\ReflectionMethod|\ReflectionProperty
  * @return array
  */
 public static function getAll(\Reflector $r)
 {
     if ($r instanceof \ReflectionClass) {
         $type = $r->getName();
         $member = 'class';
         $file = $r->getFileName();
     } elseif ($r instanceof \ReflectionMethod) {
         $type = $r->getDeclaringClass()->getName();
         $member = $r->getName();
         $file = $r->getFileName();
     } elseif ($r instanceof \ReflectionFunction) {
         $type = NULL;
         $member = $r->getName();
         $file = $r->getFileName();
     } else {
         $type = $r->getDeclaringClass()->getName();
         $member = '$' . $r->getName();
         $file = $r->getDeclaringClass()->getFileName();
     }
     if (!self::$useReflection) {
         // auto-expire cache
         if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) {
             unset(self::$cache[$type]);
         }
         unset(self::$timestamps[$file]);
     }
     if (isset(self::$cache[$type][$member])) {
         // is value cached?
         return self::$cache[$type][$member];
     }
     if (self::$useReflection === NULL) {
         // detects whether is reflection available
         self::$useReflection = (bool) ClassType::from(__CLASS__)->getDocComment();
     }
     if (self::$useReflection) {
         $annotations = self::parseComment($r->getDocComment());
     } else {
         $outerCache = self::getCache();
         if (self::$cache === NULL) {
             self::$cache = (array) $outerCache->load('list');
             self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : [];
         }
         if (!isset(self::$cache[$type]) && $file) {
             self::$cache['*'][$file] = filemtime($file);
             foreach (static::parsePhp(file_get_contents($file)) as $class => $info) {
                 foreach ($info as $prop => $comment) {
                     if ($prop !== 'use') {
                         self::$cache[$class][$prop] = self::parseComment($comment);
                     }
                 }
             }
             $outerCache->save('list', self::$cache);
         }
         if (isset(self::$cache[$type][$member])) {
             $annotations = self::$cache[$type][$member];
         } else {
             $annotations = [];
         }
     }
     if ($r instanceof \ReflectionMethod && !$r->isPrivate() && (!$r->isConstructor() || !empty($annotations['inheritdoc'][0]))) {
         try {
             $inherited = self::getAll(new \ReflectionMethod(get_parent_class($type), $member));
         } catch (\ReflectionException $e) {
             try {
                 $inherited = self::getAll($r->getPrototype());
             } catch (\ReflectionException $e) {
                 $inherited = [];
             }
         }
         $annotations += array_intersect_key($inherited, array_flip(self::$inherited));
     }
     return self::$cache[$type][$member] = $annotations;
 }
开发者ID:nette,项目名称:reflection,代码行数:78,代码来源:AnnotationsParser.php


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