/**
  * registers listeners and binds them to events
  *
  * @param Delegator $d
  * @param array $listeners
  */
 public static function registerEventListeners(Delegator $d, array $listeners = null)
 {
     if (!$listeners) {
         $listeners = array();
         $ls = Application::getInstance()->listeners;
         if ($ls->listener) {
             foreach ($ls->listener as $l) {
                 $listeners[(string) $l->attributes()->listenFor] = (string) $l->attributes()->listener;
             }
         }
     }
     foreach ($listeners as $event => $listener) {
         if ($listener instanceof Closure) {
             Event::bind($event, $listener);
         } else {
             $split = explode("::", $event);
             $model = $split[0];
             $split2 = explode("::", $listener);
             $lclass = $split2[0];
             $lmethod = $split2[1];
             $x = $d->{$model} instanceof Aspect ? $d->{$model}->getObject() : $d->{$model};
             $l = new $lclass($x);
             Event::bind($event, $lmethod, $l);
         }
     }
 }
Пример #2
0
 /**
  * @param $path
  * @return array
  */
 private function implementRoutingOverrides($path)
 {
     /**
      * @var SimpleXmlElement[] $route
      */
     $uri = "/" . implode("/", $path);
     $route = Application::getInstance()->actions->xpath("action[@uri='{$uri}']");
     if (isset($route[0])) {
         $path[0] = (string) $route[0]->attributes()->class;
         $path[1] = (string) $route[0]->attributes()->method;
     } else {
         if (empty($path)) {
             $path = ["index", "__default"];
         } else {
             if (!isset($path[1])) {
                 $path[1] = "__default";
             }
         }
     }
     return $path;
 }