[PHPCR-117] cp Created: 21/Dec/13  Updated: 15/Feb/14  Resolved: 15/Feb/14

Status: Closed
Project: Doctrine PHPCR
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Roger Mbiama Assogo Assignee: Lukas Kahwe
Resolution: Incomplete Votes: 0
Labels: oracle
Environment:

cpsess8119434838/frontend


Attachments: File CGI.pm    

 Description   

*/
final class PhpParser
{
/**

  • Parses a class.
    *
  • @param \ReflectionClass $class A <code>ReflectionClass</code> object.
  • @return array A list with use statements in the form (Alias => FQN).
    */
    public function parseClass(\ReflectionClass $class)
    {
    if (method_exists($class, 'getUseStatements')) { return $class->getUseStatements(); }

if (false === $filename = $class->getFilename())

{ return array(); }

$content = $this->getFileContent($filename, $class->getStartLine());

if (null === $content) { return array(); }

$namespace = preg_quote($class->getNamespaceName());
$content = preg_replace('/^.?(\bnamespace\s+' . $namespace . '\s[;

{].*)$/s', '\\1', $content); $tokenizer = new TokenParser('<?php ' . $content); $statements = $tokenizer->parseUseStatements($class->getNamespaceName()); return $statements; }

/**

  • Get the content of the file right up to the given line number.
    *
  • @param string $filename The name of the file to load.
  • @param int $lineNumber The number of lines to read from file.
  • @return string The content of the file.
    */
    private function getFileContent($filename, $lineNumber)
    {
    if ( ! is_file($filename)) { return null; }

$content = '';
$lineCnt = 0;
$file = new SplFileObject($filename);
while (!$file->eof()) {
if ($lineCnt++ == $lineNumber)

{ break; }

$content .= $file->fgets();
}

return $content;
}
}


Generated at Mon Jul 28 16:46:52 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.