예제 #1
0
파일: Route.php 프로젝트: romeoz/rock
 public function run($new = false)
 {
     $self = $this;
     if ($new) {
         $config = ['class' => static::className(), 'response' => $this->response];
         /** @var static $self */
         $self = Instance::ensure($config);
     }
     Event::trigger($self, self::EVENT_BEGIN_ROUTER);
     $self->provide();
     Event::trigger($self, self::EVENT_END_ROUTER);
 }
예제 #2
0
 public function trigger($name, Event $event = null)
 {
     $this->ensureBehaviors();
     if (!empty($this->_events[$name])) {
         if ($event === null) {
             $event = new Event();
         }
         if ($event->owner === null) {
             $event->owner = $this;
         }
         $event->handled = false;
         $event->name = $name;
         foreach ($this->_events[$name] as $handler) {
             call_user_func($handler, $event);
             // stop further handling if the event is handled
             if ($event->handled) {
                 return;
             }
         }
     }
     // invoke class-level attached handlers
     Event::trigger($this, $name, $event);
 }
예제 #3
0
파일: Rock.php 프로젝트: romeoz/rock
 /**
  * Bootstrap
  *
  * @param array $config
  * @throws \rock\base\BaseException
  */
 public static function bootstrap(array $config)
 {
     Trace::beginProfile(Trace::APP, Trace::TOKEN_APP_RUNTIME);
     static::$components = $config['components'];
     unset($config['components']);
     static::$config = $config;
     Container::registerMulti(static::$components);
     $response = static::$app->response;
     try {
         // Triggered at the beginning
         Event::trigger(static::className(), self::EVENT_BEGIN_APP);
         // Routing
         $route = static::$app->route;
         $route->response = $response;
         $route->run();
     } catch (\Exception $e) {
         ErrorHandler::display($e, Log::CRITICAL, $response);
     }
     //var_dump(Trace::getTime(Trace::APP_TIME));
     Trace::endProfile(Trace::APP, Trace::TOKEN_APP_RUNTIME);
     //var_dump(Trace::get('db.query'), Trace::get(\rock\helpers\Trace::APP));
     // Triggered at the end
     Event::trigger(static::className(), self::EVENT_END_APP);
     $response->send();
 }
예제 #4
0
 /**
  * Marks the ending of an HTML page.
  * @return string
  */
 public function endPage()
 {
     Event::trigger($this, self::EVENT_END_PAGE);
     $this->clear();
     return '</html>';
 }
예제 #5
0
파일: Route.php 프로젝트: romeoz/rock-route
 public function run($new = false)
 {
     $route = $this;
     if ($new) {
         $config = ['class' => static::className(), 'response' => $this->response];
         /** @var static $route */
         $route = Instance::ensure($config);
     }
     Event::trigger($route, self::EVENT_BEGIN_ROUTER);
     if (!empty($route->groups)) {
         $check = $route->checkGroups($route->getRawGroups());
     } else {
         $check = $route->checkRules($route->getRawRules());
     }
     if (!$check) {
         $this->callFail();
     }
     Event::trigger($route, self::EVENT_END_ROUTER);
 }