Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 7 ■ REFLECTION API^101

function setMethod(ReflectionMethod $method) {
$this->method = $method;
}

function getMethod() {
return $this->method;
}

}

class WebServiceMethodAttribute extends Attribute {

protected $data;

function __construct($data) {
$this->data = $data;
}

function getData() {
return $this->data;
}

}

?>

Finally, create a demonstration class and use reflection to examine its attributes, as shown
in Listing 7-24.

Listing 7-24. Testing the Attributes (Testing.php)

<?php

require_once('DocumentingReflection.php');
require_once('Attributes.php');

class demo {

/**
* Add two numbers together
*
* @param int $a The first number to add
* @param int $b The second number to add
* @attribute WebServiceMethod Some Extra Info
*/
public function add($a, $b) { return $a+$b; }

McArthur_819-9C07.fm Page 101 Friday, February 22, 2008 8:59 AM

Free download pdf