path = $path; $this->method = $method; $this->result = $result; $this->name = $name; $this->beforeAction = array(); $this->afterAction = array(); $this->afterResult = array(); } public function addBeforeAction($event_handler){ if($this->eventHandlerFormatCheck($event_handler, $match)){ $this->beforeAction[] = $event_handler; return $this; } else{ throw new \Exception("Wrong event handler format: $event_handler"); } } public function addAfterAction($event_handler){ if($this->eventHandlerFormatCheck($event_handler, $match)){ $this->afterAction[] = $event_handler; return $this; } else{ throw new \Exception("Wrong event handler format: $event_handler"); } } public function addAfterResult($event_handler){ if($this->eventHandlerFormatCheck($event_handler, $match)){ $this->afterResult[] = $event_handler; return $this; } else{ throw new \Exception("Wrong event handler format: $event_handler"); } } public static function eventHandlerFormatCheck($event_handler, &$match){ $pattern = '#^((?[a-z0-9\\\\]+)::)?(?[a-z0-9]+)(\\((?[a-z0-9;,- ]+)?\\))?$#i'; if(preg_match($pattern, $event_handler, $match)){ if(isset($match['arguments'])){ $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match); return $result; } else{ return 1; } } else{ return 0; } } public static function eventHandlerArgumentsFormatCheck($arguments, &$match){ $match = explode(',', $arguments); return $match; } }