Overview

Namespaces

  • TokenReflection
    • Broker
      • Backend
    • Dummy
    • Exception
    • Invalid
    • Php
    • Stream

Classes

  • Broker
  • ReflectionAnnotation
  • ReflectionBase
  • ReflectionClass
  • ReflectionConstant
  • ReflectionElement
  • ReflectionFile
  • ReflectionFileNamespace
  • ReflectionFunction
  • ReflectionFunctionBase
  • ReflectionMethod
  • ReflectionNamespace
  • ReflectionParameter
  • ReflectionProperty
  • Resolver

Interfaces

  • IReflection
  • IReflectionClass
  • IReflectionConstant
  • IReflectionExtension
  • IReflectionFunction
  • IReflectionFunctionBase
  • IReflectionMethod
  • IReflectionNamespace
  • IReflectionParameter
  • IReflectionProperty
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP Token Reflection
  4:  *
  5:  * Version 1.3.1
  6:  *
  7:  * LICENSE
  8:  *
  9:  * This source file is subject to the new BSD license that is bundled
 10:  * with this library in the file LICENSE.
 11:  *
 12:  * @author Ondřej Nešpor
 13:  * @author Jaroslav Hanslík
 14:  */
 15: 
 16: namespace TokenReflection;
 17: 
 18: use TokenReflection\Stream\StreamBase as Stream, TokenReflection\Exception;
 19: 
 20: /**
 21:  * Processed file class.
 22:  */
 23: class ReflectionFile extends ReflectionBase
 24: {
 25:     /**
 26:      * Namespaces list.
 27:      *
 28:      * @var array
 29:      */
 30:     private $namespaces = array();
 31: 
 32:     /**
 33:      * Returns an array of namespaces in the current file.
 34:      *
 35:      * @return array
 36:      */
 37:     public function getNamespaces()
 38:     {
 39:         return $this->namespaces;
 40:     }
 41: 
 42:     /**
 43:      * Returns the string representation of the reflection object.
 44:      *
 45:      * @throws \TokenReflection\Exception\RuntimeException If the method is called, because it's unsupported.
 46:      */
 47:     public function __toString()
 48:     {
 49:         throw new Exception\RuntimeException('Casting to string is not supported.', Exception\RuntimeException::UNSUPPORTED, $this);
 50:     }
 51: 
 52:     /**
 53:      * Exports a reflected object.
 54:      *
 55:      * @param \TokenReflection\Broker $broker Broker instance
 56:      * @param string $argument Reflection object name
 57:      * @param boolean $return Return the export instead of outputting it
 58:      * @throws \TokenReflection\Exception\RuntimeException If the method is called, because it's unsupported.
 59:      */
 60:     public static function export(Broker $broker, $argument, $return = false)
 61:     {
 62:         throw new Exception\RuntimeException('Export is not supported.', Exception\RuntimeException::UNSUPPORTED);
 63:     }
 64: 
 65:     /**
 66:      * Outputs the file source code.
 67:      *
 68:      * @return string
 69:      */
 70:     public function getSource()
 71:     {
 72:         return (string) $this->broker->getFileTokens($this->getName());
 73:     }
 74: 
 75:     /**
 76:      * Parses the token substream and prepares namespace reflections from the file.
 77:      *
 78:      * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream
 79:      * @param \TokenReflection\IReflection $parent Parent reflection object
 80:      * @return \TokenReflection\ReflectionFile
 81:      */
 82:     protected function parseStream(Stream $tokenStream, IReflection $parent = null)
 83:     {
 84:         $this->name = $tokenStream->getFileName();
 85: 
 86:         if (1 >= $tokenStream->count()) {
 87:             // No PHP content
 88:             $this->docComment = new ReflectionAnnotation($this, null);
 89:             return $this;
 90:         }
 91: 
 92:         $docCommentPosition = null;
 93: 
 94:         if (!$tokenStream->is(T_OPEN_TAG)) {
 95:             $this->namespaces[] = new ReflectionFileNamespace($tokenStream, $this->broker, $this);
 96:         } else {
 97:             $tokenStream->skipWhitespaces();
 98: 
 99:             while (null !== ($type = $tokenStream->getType())) {
100:                 switch ($type) {
101:                     case T_DOC_COMMENT:
102:                         if (null === $docCommentPosition) {
103:                             $docCommentPosition = $tokenStream->key();
104:                         }
105:                     case T_WHITESPACE:
106:                     case T_COMMENT:
107:                         break;
108:                     case T_DECLARE:
109:                         // Intentionally twice call of skipWhitespaces()
110:                         $tokenStream
111:                             ->skipWhitespaces()
112:                             ->findMatchingBracket()
113:                             ->skipWhitespaces()
114:                             ->skipWhitespaces();
115:                         break;
116:                     case T_NAMESPACE:
117:                         $docCommentPosition = $docCommentPosition ?: -1;
118:                         break 2;
119:                     default:
120:                         $docCommentPosition = $docCommentPosition ?: -1;
121:                         $this->namespaces[] = new ReflectionFileNamespace($tokenStream, $this->broker, $this);
122:                         break 2;
123:                 }
124: 
125:                 $tokenStream->skipWhitespaces();
126:             }
127: 
128:             while (null !== ($type = $tokenStream->getType())) {
129:                 if (T_NAMESPACE === $type) {
130:                     $this->namespaces[] = new ReflectionFileNamespace($tokenStream, $this->broker, $this);
131:                 } else {
132:                     $tokenStream->skipWhitespaces();
133:                 }
134:             }
135:         }
136: 
137:         if (null !== $docCommentPosition && !empty($this->namespaces) && $docCommentPosition === $this->namespaces[0]->getStartPosition()) {
138:             $docCommentPosition = null;
139:         }
140:         $this->docComment = new ReflectionAnnotation($this, null !== $docCommentPosition ? $tokenStream->getTokenValue($docCommentPosition) : null);
141: 
142:         return $this;
143:     }
144: }
145: 
PHP Token Reflection API documentation generated by ApiGen 2.8.0