@@ -24,34 +24,46 @@ You can install the component in the following ways:
2424Usage
2525-----
2626
27- The ReflectionDocBlock component is designed to work in an identical fashion to
28- PHP's own Reflection extension (http://php.net/manual/en/book.reflection.php ).
29-
30- Parsing can be initiated by instantiating the
31- ` \phpDocumentor\Reflection\DocBlock() ` class and passing it a string containing
32- a DocBlock (including asterisks) or by passing an object supporting the
33- ` getDocComment() ` method.
34-
35- > * Examples of objects having the ` getDocComment() ` method are the
36- > ` ReflectionClass ` and the ` ReflectionMethod ` classes of the PHP
37- > Reflection extension*
38-
39- Example:
40-
41- $class = new ReflectionClass('MyClass');
42- $phpdoc = new \phpDocumentor\Reflection\DocBlock($class);
43-
44- or
45-
46- $docblock = <<<DOCBLOCK
47- /**
48- * This is a short description.
49- *
50- * This is a *long* description.
51- *
52- * @return void
53- */
54- DOCBLOCK;
55-
56- $phpdoc = new \phpDocumentor\Reflection\DocBlock($docblock);
27+ In order to parse the DocBlock one needs a DocBlockFactory that can be
28+ instantiated using its ` createInstance ` factory method like this:
29+
30+ ``` php
31+ $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
32+ ```
33+
34+ Then we can use the ` create ` method of the factory to interpret the DocBlock.
35+ Please note that it is also possible to provide a class that has the
36+ ` getDocComment() ` method, such as an object of type ` ReflectionClass ` , the
37+ create method will read that if it exists.
38+
39+ ``` php
40+ $docComment = <<<DOCCOMMENT
41+ /**
42+ * This is an example of a summary.
43+ *
44+ * This is a Description. A Summary and Description are separated by either
45+ * two subsequent newlines (thus a whiteline in between as can be seen in this
46+ * example), or when the Summary ends with a dot (`.`) and some form of
47+ * whitespace.
48+ * /
49+ DOCCOMMENT;
50+
51+ $docblock = $factory- >create($docComment);
52+ ```
53+
54+ The ` create ` method will yield an object of type ` \phpDocumentor\Reflection\DocBlock `
55+ whose methods can be queried as shown in the following example.
56+
57+ ``` php
58+ // Should contain the summary for this DocBlock
59+ $summary = $docblock->getSummary();
60+
61+ // Contains an object of type \phpDocumentor\Reflection\DocBlock\Description;
62+ // you can either cast it to string or use the render method to get a string
63+ // representation of the Description.
64+ $description = $docblock->getDescription();
65+ ```
66+
67+ > For more examples it would be best to review the scripts in the ` /examples `
68+ > folder.
5769
0 commit comments