Пример #1
0
 /**
  * Dispatch event to all listener subscribed
  *
  * @param mixed $event
  * @param mixed|array $parameters
  * @return BaseEvent mixed
  */
 public function dispatchEvent($event, $parameters = array())
 {
     if (is_string($event)) {
         $event = new BaseEvent($event, $parameters);
     }
     $eventName = $event->getName();
     $event->setDispatcher($this);
     if ($this->hasListeners($eventName)) {
         foreach ($this->_listeners[$eventName] as $priority => $listeners) {
             foreach ($listeners as $listener) {
                 if ($event->isPropagationStopped($priority)) {
                     break;
                 }
                 call_user_func($listener, $event);
             }
         }
     }
     return $event;
 }
Пример #2
0
 public function onRequestBuild(BaseEvent $event)
 {
     /**
      * @var Request $request
      */
     $request = $event->getParameters();
     $params = array_splice($_SERVER['argv'], 1);
     $uri = str_replace(':', '/', array_shift($params));
     if (empty($uri)) {
         $uri = '/';
     }
     $request->setUri($uri);
     $index = 0;
     foreach ($params as $param) {
         $m = array();
         preg_match('#--(?P<key>[-\\.\\w\\d]+)(\\s?=\\s?(?P<value>.+))?#is', $param, $m);
         if (!empty($m)) {
             $request->setVar($m['key'], array_key_exists('value', $m) ? $m['value'] : true);
         } else {
             $request->getVars()->setDeepValue('params/' . $index++, trim($param));
         }
     }
 }