/** * Constructs a FunctionParser from a reflected function. Triggers all code parsing from the constructor. * * @param \ReflectionFunctionAbstract $reflection The reflected function or method. */ public function __construct(\ReflectionFunctionAbstract $reflection) { if (!$reflection->isUserDefined()) { throw new \InvalidArgumentException('You can only parse the code of user-defined functions.'); } $this->reflection = $reflection; $this->tokenizer = $this->fetchTokenizer(); $this->parameters = $this->fetchParameters(); $this->code = $this->parseCode(); $this->body = $this->parseBody(); $this->context = $this->parseContext(); }
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); }
/** * Constructor. * * @param string|array $function Defining function/method * @param string $paramName Parameter name * @param \TokenReflection\Broker $broker Reflection broker * @param \ReflectionFunctionAbstract $parent Parent reflection object */ public function __construct($function, $paramName, Broker $broker, InternalReflectionFunctionAbstract $parent) { parent::__construct($function, $paramName); $this->broker = $broker; $this->userDefined = $parent->isUserDefined(); }