tailieunhanh - Pro PHP Patterns, Frameworks, Testing and more phần 4

API cho thành phần này đã không được phát triển đầy đủ, và nó có thể thay đổi. Ví dụ 5-15 là dự định như là một cuộc biểu tình của các API cuối cùng sẽ đến với nhau, nhưng không phải là dự định được sử dụng như cú pháp chính xác. Danh sách này được xây dựng một tài liệu XHTML cơ bản cho dòng đầu ra. | CHAPTER 7 REFLECTION API 89 public function printDocTokens foreach this- _tokens as token echo token 0 . echo docblock_token_name token 0 . print_r token 1 echo n public function getParsedTags return this- _tags public function getParsedComments return this- _comments The DocumentingReflectionMethod class extends from ReflectionMethod inheriting all the abilities of ReflectionMethod. Then it initializes the base class by calling parent _construct. This parent construction must be done as the first line in the overridden constructor otherwise you may get errors or even worse code that crashes without any error explanation. After the base class is initialized the documentation extensions go into effect. The class calls the static method you previously defined to parse the doccomment passing in its own doccomment and storing its results in several protected member variables. Finally several accessor methods are added to allow you to see that it s all working. With all the code in Listings 7-12 and 7-13 in you can test the results so far. Create another file named test. php and add the code shown in Listing 7-14. Listing 7-14. Testing the DocmentingReflection Classes require_once class demo This method is for demonstration purposes. It takes a single parameter and returns it. @param mixed param1 A variable to return. @returns mixed The input variable is returned. public function demoMethod param1 return param1 90 CHAPTER 7 REFLECTION API reflector new DocumentingReflectionMethod demo demoMethod reflector- printDocTokens print_r reflector- getParsedTags print_r reflector- getParsedComments The script in Listing 7-14 should result in the following output 1 DOCBLOCK_NEWLINE 1 DOCBLOCK_NEWLINE 2 DOCBLOCK_WHITESPACE 36 DOCBLOCK_TEXT This method is for demonstration purposes. 1 DOCBLOCK_NEWLINE 1 DOCBLOCK_NEWLINE 2 DOCBLOCK_WHITESPACE 36 DOCBLOCK_TEXT It takes a single parameter and returns it. 1 DOCBLOCK_NEWLINE 1