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


PHP Reflector类代码示例

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


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

示例1: parse

 /**
  * Parse the annotations for a given Reflector.
  * Annotations are derived from doc comments, and are similar to Java's.
  *
  * Annotation syntax is simple:
  *
  * :foo = expr
  *
  * Where 'expr' is a valid JSON expression containing no new lines.
  * We also support single values, not nested in arrays/objects.
  * You can't use any null expressions - this would be seen as a syntax
  * error. You can, of course, create arrays/objects containing nulls.
  *
  * It's also valid to do:
  *
  * :foo
  *
  * Which is simply a shortcut for
  *
  * :foo = true
  *
  * The JSON is subject to whatever nuances affect PHP's json_decode().
  * Particularly, string keys must always be enclosed in quotes, and
  * all string quoting must be done with double quotes.
  *
  * Example usage:
  *
  * :requires_super_user = true
  * :requires_privileges = { "foo": "crude" }
  *
  * You can build up arrays on separate lines for clarity:
  *
  * :extensions[]        = { "name": "Extension1", "param": "foo" }
  * :extensions[]        = { "name": "Extension2", "param": "bar" }
  *
  * @todo this method should cache its results as the builder hammers it pretty hard
  *
  * @param $r <tt>Reflector</tt> for which to parse annotations
  * @return associative array of annotations for <tt>$r</tt>
  */
 public static function parse(\Reflector $r)
 {
     $comment = $r->getDocComment();
     if (strlen($comment) == 0 || strpos($comment, ':') === false) {
         return array();
     }
     $annotations = array();
     preg_match_all('/\\*\\s+:(\\w+)(\\[\\])?\\s*(=\\s*(.*))?$/m', $comment, $matches, PREG_SET_ORDER);
     foreach ($matches as $m) {
         if (!isset($m[4])) {
             $decode = true;
         } else {
             $json = trim($m[4]);
             if ($json[0] == '[' || $json[0] == '{') {
                 $decode = json_decode($json, true);
             } else {
                 $decode = json_decode('[' . $json . ']', true);
                 if (is_array($decode)) {
                     $decode = $decode[0];
                 }
             }
         }
         if ($decode === null) {
             throw new Error_Syntax("Invalid JSON fragment: {$json}");
         }
         if ($m[2] == '[]') {
             $annotations[$m[1]][] = $decode;
         } else {
             $annotations[$m[1]] = $decode;
         }
     }
     return $annotations;
 }
开发者ID:jaz303,项目名称:spitfire,代码行数:73,代码来源:Annotation.php

示例2: 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

示例3: _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

示例4: getAnnotation

function getAnnotation(Reflector $ref)
{
    $doc = $ref->getDocComment();
    $annotations = array();
    if ($doc !== false) {
        $pattern = '/@\\s*(\\w+)\\s*(?:\\((.+)\\))?/i';
        if (preg_match($pattern, $doc)) {
            preg_match_all($pattern, $doc, $annotation_matches);
            for ($i = 0; $i < count($annotation_matches[0]); $i++) {
                if (class_exists($annotation_matches[1][$i])) {
                    $_class = new $annotation_matches[1][$i]();
                    if ($_class instanceof Annotation) {
                        $annotations[$annotation_matches[1][$i]] = $_class;
                        if (!empty($annotation_matches[2][$i]) && preg_match('/^(?:\\s*\\w+\\s*=\\s*\\w+\\s*,?)+$/i', $annotation_matches[2][$i])) {
                            preg_match_all('/(\\w+)\\s*=\\s*(\\w+)\\s*,?/i', $annotation_matches[2][$i], $annotation_param_matches);
                            for ($j = 0; $j < count($annotation_param_matches[0]); $j++) {
                                $_property = $annotation_param_matches[1][$j];
                                if (property_exists($_class, $_property)) {
                                    $_class->{$_property} = $annotation_param_matches[2][$j];
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $annotations;
}
开发者ID:huashihongfeng,项目名称:demo-server-php,代码行数:29,代码来源:index.php

示例5: parseDocCommentSummary

 /**
  * Returns the first line of docblock.
  *
  * @param \Reflector $reflection
  * @return string
  */
 protected function parseDocCommentSummary($reflection)
 {
     $docLines = preg_split('~\\R~u', $reflection->getDocComment());
     if (isset($docLines[1])) {
         return trim($docLines[1], "\t *");
     }
     return '';
 }
开发者ID:snivs,项目名称:semanti,代码行数:14,代码来源:DefaultController.php

示例6: loadClassEntity

 /**
  * @param $className
  * @return ClassEntity
  */
 private function loadClassEntity($className)
 {
     if (empty($this->cache[$className])) {
         $reflector = new Reflector($className, $this);
         $this->cache[$className] = $reflector->getClassEntity();
     }
     return $this->cache[$className];
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:12,代码来源:FunctionFinder.php

示例7: __construct

 /**
  *  create an annotation from the given reflection
  *
  *  @param  \Reflector  $reflection   
  */
 public function __construct(\Reflector $reflection)
 {
     $this->reflection = $reflection;
     if ($docblock = $reflection->getDocComment()) {
         $this->rdocblock = new ReflectionDocBlock($docblock);
     }
     //if
 }
开发者ID:Jaymon,项目名称:Montage,代码行数:13,代码来源:Annotation.php

示例8: getConstants

 /**
  * Get defined constants for the given class or object Reflector.
  *
  * @param \Reflector $reflector        	
  *
  * @return array
  */
 protected function getConstants(\Reflector $reflector)
 {
     $constants = array();
     foreach ($reflector->getConstants() as $name => $constant) {
         $constants[$name] = new ReflectionConstant($reflector, $name);
     }
     // TODO: this should be natcasesort
     ksort($constants);
     return $constants;
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:17,代码来源:ClassConstantEnumerator.php

示例9: getConstants

 /**
  * Get defined constants for the given class or object Reflector.
  *
  * @param \Reflector $reflector
  *
  * @return array
  */
 protected function getConstants(\Reflector $reflector)
 {
     $constants = array();
     foreach ($reflector->getConstants() as $name => $constant) {
         $constants[$name] = new ReflectionConstant($reflector, $name);
     }
     // Removed task from comment. SPV
     ksort($constants);
     return $constants;
 }
开发者ID:jaambageek,项目名称:cakeboot-template,代码行数:17,代码来源:ClassConstantEnumerator.php

示例10: getDocCommentText

 /**
  * @param  \Reflector $reflected
  * @return string
  */
 public function getDocCommentText(\Reflector $reflected)
 {
     $comment = $reflected->getDocComment();
     // Remove PHPDoc
     $comment = preg_replace('/^\\s+\\* @[\\w0-9]+.*/msi', '', $comment);
     // let's clean the doc block
     $comment = str_replace('/**', '', $comment);
     $comment = str_replace('*/', '', $comment);
     $comment = preg_replace('/^\\s*\\* ?/m', '', $comment);
     return trim($comment);
 }
开发者ID:NAYZO,项目名称:NayzoApiDocBundle,代码行数:15,代码来源:DocCommentExtractor.php

示例11: getMethods

 /**
  * Get defined methods for the given class or object Reflector.
  *
  * @param bool       $showAll   Include private and protected methods.
  * @param \Reflector $reflector
  *
  * @return array
  */
 protected function getMethods($showAll, \Reflector $reflector)
 {
     $methods = array();
     foreach ($reflector->getMethods() as $name => $method) {
         if ($showAll || $method->isPublic()) {
             $methods[$method->getName()] = $method;
         }
     }
     // Removed task from comment. SPV
     ksort($methods);
     return $methods;
 }
开发者ID:jaambageek,项目名称:cakeboot-template,代码行数:20,代码来源:MethodEnumerator.php

示例12: getProperties

 /**
  * Get defined properties for the given class or object Reflector.
  *
  * @param bool       $showAll   Include private and protected properties.
  * @param \Reflector $reflector
  *
  * @return array
  */
 protected function getProperties($showAll, \Reflector $reflector)
 {
     $properties = array();
     foreach ($reflector->getProperties() as $property) {
         if ($showAll || $property->isPublic()) {
             $properties[$property->getName()] = $property;
         }
     }
     // Removed task from comment. SPV
     ksort($properties);
     return $properties;
 }
开发者ID:jaambageek,项目名称:cakeboot-template,代码行数:20,代码来源:PropertyEnumerator.php

示例13: getMethods

 /**
  * Get defined methods for the given class or object Reflector.
  *
  * @param boolean    $showAll   Include private and protected methods.
  * @param \Reflector $reflector
  *
  * @return array
  */
 protected function getMethods($showAll, \Reflector $reflector)
 {
     $methods = array();
     foreach ($reflector->getMethods() as $name => $method) {
         if ($showAll || $method->isPublic()) {
             $methods[$method->getName()] = $method;
         }
     }
     // TODO: this should be natcasesort
     ksort($methods);
     return $methods;
 }
开发者ID:fulore,项目名称:psysh,代码行数:20,代码来源:MethodEnumerator.php

示例14: parseAnnotation

 /**
  * Returns an annotation value.
  * @return string|NULL
  */
 public static function parseAnnotation(\Reflector $ref, $name)
 {
     static $ok;
     if (!$ok) {
         if (!(new \ReflectionMethod(__METHOD__))->getDocComment()) {
             throw new Nette\InvalidStateException('You have to enable phpDoc comments in opcode cache.');
         }
         $ok = TRUE;
     }
     if ($ref->getDocComment() && preg_match("#[\\s*]@{$name}(?:\\s++([^@]\\S*)?|\$)#", trim($ref->getDocComment(), '/*'), $m)) {
         return isset($m[1]) ? $m[1] : '';
     }
 }
开发者ID:Northys,项目名称:di,代码行数:17,代码来源:PhpReflection.php

示例15: get_comment

function get_comment(Reflector $reflector)
{
    $comments = explode("\n", $reflector->getDocComment());
    foreach ($comments as $line) {
        $nameStart = strpos($line, '@desc: ');
        if (FALSE === $nameStart) {
            continue;
        } else {
            return trim(substr($line, $nameStart + 6));
        }
    }
    return 'No description available!';
}
开发者ID:BackupTheBerlios,项目名称:medick-svn,代码行数:13,代码来源:main_helper.php


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