Compare commits

...
10 Commits
6 changed files with 84 additions and 8 deletions
+57
View File
@@ -0,0 +1,57 @@
The ReflectionDocBlock Component
================================
Introduction
------------
The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser
that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest).
With this component can a library provide support for annotations via DocBlocks
or otherwise retrieve information that is embedded in a DocBlock.
> **Note**: *this is a core component of phpDocumentor and is constantly being
> optimized for performance.*
Installation
------------
You can install the component in the following ways:
* Use the official Github repository (https://github.com/phpDocumentor/ReflectionDocBlock)
* Via Composer (http://packagist.org/packages/phpdocumentor/reflection-docblock)
Usage
-----
The ReflectionDocBlock component is designed to work in an identical fashion to
PHP's own Reflection extension (http://php.net/manual/en/book.reflection.php).
Parsing can be initiated by instantiating the
`\phpDocumentor\Reflection\DocBlock()` class and passing it a string containing
a DocBlock (including asterisks) or by passing an object supporting the
`getDocComment()` method.
> *Examples of objects having the `getDocComment()` method are the
> `ReflectionClass` and the `ReflectionMethod` classes of the PHP
> Reflection extension*
Example:
$class = new ReflectionClass('MyClass');
$phpdoc = new \phpDocumentor\Reflection\DocBlock($class);
or
$docblock = <<<DOCBLOCK
/**
* This is a short description.
*
* This is a *long* description.
*
* @return void
*/
DOCBLOCK;
$phpdoc = new \phpDocumentor\Reflection\DocBlock($docblock);
+3 -2
View File
@@ -6,9 +6,10 @@
{"name": "Mike van Riel", "email": "[email protected]"}
],
"require": {
"php": ">=5.3.2"
"php": ">=5.3.2",
"dflydev/markdown": "1.0.*"
},
"autoload": {
"psr-0": {"phpDocumentor\\Reflection": "src/phpDocumentor"}
"psr-0": {"phpDocumentor\\Reflection": "src/"}
}
}
+4 -4
View File
@@ -127,11 +127,11 @@ class DocBlock implements \Reflector
preg_match(
'/(?x)
\A (
[^\n]+
[^\n.]+
(?:
(?! (?<=\.) \n | \n{2} ) # disallow the first seperator here
\n (?! [ \t]* @\pL ) # disallow second seperator
[^\n]+
(?! \. \s | \n{2} ) # disallow the first seperator here
[\n.] (?! [ \t]* @\pL ) # disallow second seperator
[^\n.]+
)*
\.?
)
@@ -78,7 +78,7 @@ class LongDescription implements \Reflector
);
}
if (class_exists('\dflydev\markdown\MarkdownExtraParser()')) {
if (class_exists('\dflydev\markdown\MarkdownExtraParser')) {
$md = new \dflydev\markdown\MarkdownExtraParser();
$result = $md->transformMarkdown($result);
}
@@ -59,7 +59,7 @@ class Tag implements \Reflector
$tag_name = str_replace(
' ', '', ucwords(str_replace('-', ' ', $matches[1]))
).'Tag';
$class_name = '\\phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name;
$class_name = 'phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name;
return (@class_exists($class_name))
? new $class_name($matches[1], isset($matches[2]) ? $matches[2] : '')
@@ -44,4 +44,22 @@ DOCBLOCK;
$this->assertTrue($object->hasTag('see'));
$this->assertTrue($object->hasTag('return'));
}
public function testDotSeperation()
{
$fixture = <<<DOCBLOCK
/**
* This is a short description. This is a long description.
* This is a continuation of the long description.
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEquals(
'This is a short description.', $object->getShortDescription()
);
$this->assertEquals(
"This is a long description.\nThis is a continuation of the long description.", $object->getLongDescription()->getContents()
);
}
}