Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
public function __call($method, array $args) {}public function fire($arguments) {
$funcCreation = '$ob=new '.$this->getCallClassName().'();$ob->'.$this->getCallMethodName().'($arguments);';
eval($funcCreation);
}public function fire($arguments) {
$objClass = $this->getCallClassName();
$obj = new $objClass;
call_user_func_array(array($obj, $this->getCallMethodName()), $arguments);
}/*
* Base aspect class. Must be extended in all aspects
* IMPORTANT: Each aspect should have constructor without arguments
*/
abstract class Aspect {};
/*
* Base aspect class. Must be extended in all aspects
* IMPORTANT: Each aspect should have constructor without arguments
*/
abstract class Aspect {
final public function __construct() {}
};
class Event extends ArrayObject {
public function __invoke() {
foreach($this as $callback)
call_user_func_array($callback, func_get_args());
}
}
$test = new Event();
/* Setting up callbacks */
$test[] = function($msg, $txt) {
echo "This is the event!
";
};
$test[] = function($msg, $txt) {
echo "Message: $msg. Text: $txt
";
};
$test[] = function($msg, $txt) {
echo "Works great!
";
};
/* call */
$test("Some message", "Some text");
/*
* @After(Backet->order)
*/
public function backetOrderMessage($params) {
echo ‘Backed has been ordered’;
}/*
* @After(Backet->order)
*/
public function backetOrderMessage($params) {
echo ‘Backed has been ordered’;
}
PHP и Аспектно-ориентированное программирование