Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^92) CHAPTER 7 ■ REFLECTION API
public function getDeclaringFunction() {
return $this->_reflectionMethod;
}
public function getComment() {
return $this->_comment;
}
public function getType() {
return $this->_type;
}
private function _isParamTag($paramName, $paramData) {
$paramSplit = preg_split("/[\s\t]+/", $paramData, 3);
$explodedName = trim($paramSplit[1], ' $,.');
if($explodedName == $paramName) {
return true;
} else {
return false;
}
}
}
This class is a lot more complicated than the previous classes. Most of the comment
processing for this class is done in the constructor.
First, you construct the class and call the parent methods. Default values are assigned for
cases where there is no documentation associated. Then processing begins.
Using the information passed to the constructor, a DocumentingReflectionMethod is instan-
tiated. This class will give you access to the documentation information via the getParsedTags()
method. Next, it checks for the presence of 'param' in the $tags array. If it’s there, it determines
whether the entry is an array or a single string value and processes accordingly.
During this process, the private member function _isParamTag() is called to determine
if the parameter is the one described by the tag. The function determines this by splitting the
param tag into three parts. The split is based on a regular expression that divides the string into
tokens, separating them where there are one or more of tabs or spaces. The third parameter to
the function limits string splitting to three times. This will produce an array with the type, vari-
able name, and the comment.
The variable name entry is checked against the ReflectionParameter class’s own name.
If there is a match, the tag currently being tested is known to belong to the parameter.
Once the correct tag is found, the data is split up and stored in the protected member variables
_comment and _type. This data can be later accessed by get functions.
You can now experiment with this class, as shown in Listing 7-16.
McArthur_819-9C07.fm Page 92 Friday, February 22, 2008 8:59 AM

Free download pdf