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