TheSeer\phpDox\DocBlock\Parser::parse PHP Method

parse() public method

public parse ( $block, array $aliasMap )
$aliasMap array
    public function parse($block, array $aliasMap)
    {
        $this->aliasMap = $aliasMap;
        $this->current = null;
        $docBlock = $this->factory->getDocBlock();
        $lines = $this->prepare($block);
        if (count($lines) > 1) {
            $this->startParser('description');
        }
        $buffer = array();
        foreach ($lines as $line) {
            if ($line == '' || $line == '/') {
                if (count($buffer)) {
                    $buffer[] = '';
                }
                continue;
            }
            if ($line[0] == '@') {
                if ($this->current !== null) {
                    $docBlock->appendElement($this->current->getObject($buffer));
                }
                $buffer = array();
                preg_match('/^\\@([a-zA-Z0-9_]+)(.*)$/', $line, $lineParts);
                $name = isset($lineParts[1]) ? $lineParts[1] : '(undefined)';
                $payload = isset($lineParts[2]) ? trim($lineParts[2]) : '';
                $this->startParser($name, $payload);
                continue;
            }
            $buffer[] = $line;
        }
        if (!$this->current) {
            // A Single line docblock with no @ annotation is considered a description
            $this->startParser('description');
        }
        $docBlock->appendElement($this->current->getObject($buffer));
        return $docBlock;
    }

Usage Example

Example #1
0
 /**
  * @ covers TheSeer\phpDox\DocBlock\Parser::__construct
  * @ covers TheSeer\phpDox\DocBlock\Parser::parse
  *
  * @dataProvider docblockSources
  */
 public function testParse($src)
 {
     $expected = new fDOMDocument();
     $dir = __DIR__ . '/../../data/docbock/';
     $block = file_get_contents($dir . $src);
     $expected->load($dir . $src . '.xml');
     $factory = new Factory();
     $parser = new Parser($factory);
     $result = $parser->parse($block, array());
     $this->assertInstanceOf('TheSeer\\phpDox\\DocBlock\\DocBlock', $result);
     $dom = new fDOMDocument();
     $dom->appendChild($result->asDom($dom));
     $this->assertEquals($expected->documentElement, $dom->documentElement);
 }
All Usage Examples Of TheSeer\phpDox\DocBlock\Parser::parse