コード例 #1
0
ファイル: Method.php プロジェクト: jnvsor/kint
 public function __construct(ReflectionFunctionAbstract $method)
 {
     $this->name = $method->getShortName();
     $this->filename = $method->getFilename();
     $this->startline = $method->getStartLine();
     $this->endline = $method->getEndLine();
     $this->docstring = $method->getDocComment();
     $this->operator = $this->static ? Kint_Object::OPERATOR_STATIC : Kint_Object::OPERATOR_OBJECT;
     $this->access = Kint_Object::ACCESS_PUBLIC;
     if ($method instanceof ReflectionMethod) {
         $this->static = $method->isStatic();
         $this->abstract = $method->isAbstract();
         $this->final = $method->isFinal();
         $this->owner_class = $method->getDeclaringClass()->name;
         if ($method->isProtected()) {
             $this->access = Kint_Object::ACCESS_PROTECTED;
         } elseif ($method->isPrivate()) {
             $this->access = Kint_Object::ACCESS_PRIVATE;
         }
     }
     foreach ($method->getParameters() as $param) {
         $this->parameters[] = new Kint_Object_Parameter($param);
     }
     if ($this->docstring) {
         if (preg_match('/@return\\s+(.*)\\r?\\n/m', $this->docstring, $matches)) {
             if (!empty($matches[1])) {
                 $this->returntype = $matches[1];
             }
         }
     }
     $docstring = new Kint_Object_Representation_Docstring($this->docstring, $this->filename, $this->startline);
     $docstring->implicit_label = true;
     $this->addRepresentation($docstring);
 }
コード例 #2
0
ファイル: Code.php プロジェクト: oncesk/runkit
 /**
  * @param \ReflectionFunctionAbstract $reflection
  *
  * @return string
  */
 protected function fetchCode(\ReflectionFunctionAbstract $reflection)
 {
     $file = $reflection->getFileName();
     if (!file_exists($file)) {
         return '';
     }
     $startLine = $reflection->getStartLine();
     return implode('', array_slice(file($file), $startLine, $reflection->getEndLine() - $startLine - 1));
 }
コード例 #3
0
 /**
  *
  * @param \ReflectionFunctionAbstract $function        	
  */
 public static function getFunctionBody(\ReflectionFunctionAbstract $function)
 {
     $source = file($function->getFileName());
     $start = $function->getStartLine() - 1;
     $end = $function->getEndLine();
     $body = implode('', array_slice($source, $start, $end - $start));
     $open = strpos($body, '{');
     $close = strrpos($body, '}');
     return trim(substr($body, $open + 1, (strlen($body) - $close) * -1));
 }
コード例 #4
0
ファイル: FunctionLocation.php プロジェクト: timetoogo/pinq
 /**
  * Creates a function location instance from the supplied reflection.
  *
  * @param \ReflectionFunctionAbstract $reflection
  *
  * @return self
  */
 public static function fromReflection(\ReflectionFunctionAbstract $reflection)
 {
     if ($reflection instanceof \ReflectionFunction) {
         $namespace = $reflection->getNamespaceName();
     } elseif ($reflection instanceof \ReflectionMethod) {
         $namespace = $reflection->getDeclaringClass()->getNamespaceName();
     } else {
         $namespace = null;
     }
     return new self($reflection->getFileName(), $namespace, $reflection->getStartLine(), $reflection->getEndLine());
 }
コード例 #5
0
ファイル: Reader.php プロジェクト: timetoogo/penumbra
 private function LoadSourceLines(\ReflectionFunctionAbstract $Reflection)
 {
     if (!$Reflection->isUserDefined()) {
         throw new Functional\FunctionException('Cannot parse function: Function must be user defined');
     }
     $FileName = $Reflection->getFileName();
     if (!file_exists($FileName)) {
         throw new Functional\FunctionException('Cannot parse function: Function does not belong to a valid file (cannot be eval\'d code)');
     }
     $SourceLines = [];
     $File = new \SplFileObject($Reflection->getFileName());
     $StartLine = $Reflection->getStartLine() - 2;
     $File->seek($StartLine);
     $EndLine = $Reflection->getEndLine() - 2;
     while ($File->key() <= $EndLine) {
         $SourceLines[] = trim($File->fgets());
     }
     unset($File);
     $FirstLine =& $SourceLines[0];
     $FirstLine = substr($FirstLine, stripos($FirstLine, 'function'));
     $LastLine =& $SourceLines[count($SourceLines) - 1];
     $LastLine = substr($LastLine, 0, strrpos($LastLine, '}') + 1);
     return array_filter($SourceLines);
 }
コード例 #6
0
ファイル: Wizard.php プロジェクト: ezrra/PHP
 /**
  * @param \ReflectionFunctionAbstract $functionOrMethod
  */
 private function processFunctionOrMethod(\ReflectionFunctionAbstract $functionOrMethod)
 {
     if ($functionOrMethod->isInternal()) {
         return;
     }
     $name = $functionOrMethod->getName();
     if ($functionOrMethod instanceof \ReflectionMethod) {
         $name = $functionOrMethod->getDeclaringClass()->getName() . '::' . $name;
     }
     if (!isset($this->lookupTable[$functionOrMethod->getFileName()])) {
         $this->lookupTable[$functionOrMethod->getFileName()] = [];
     }
     foreach (range($functionOrMethod->getStartLine(), $functionOrMethod->getEndLine()) as $line) {
         $this->lookupTable[$functionOrMethod->getFileName()][$line] = $name;
     }
 }
コード例 #7
0
 /**
  * @param string                      $messageFormat
  * @param \ReflectionFunctionAbstract $reflection
  *
  * @return self
  */
 public static function invalidFunctionMessage($messageFormat, \ReflectionFunctionAbstract $reflection)
 {
     return self::construct(array_merge(['Invalid function %s defined in %s lines %d-%d: ' . $messageFormat, $reflection->getName(), $reflection->getFileName(), $reflection->getStartLine(), $reflection->getEndLine()], array_slice(func_get_args(), 2)));
 }
コード例 #8
0
 private function FunctionHash(\ReflectionFunctionAbstract $Reflection)
 {
     return md5(implode(' ', [$Reflection->getFileName(), $Reflection->getStartLine(), $Reflection->getEndLine()]));
 }