예제 #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 actionSignin(User $user, CSRF $CSRF)
 {
     $placeholders = [];
     if ($user->isLogged()) {
         $placeholders['content'] = $this->getMessageLogout($CSRF, 'loginLogout');
         return $this->render('success', $placeholders);
     }
     $model = new SigninForm();
     // redirect
     Event::on($model, SigninForm::EVENT_AFTER_LOGIN, function (ModelEvent $event) use($user) {
         $this->login($user, $event->result);
         $this->response->refresh()->send(true);
     });
     $model->load($_POST);
     $placeholders['model'] = $model;
     return $this->render('index', $placeholders);
 }
예제 #3
0
 public function actionSignup(User $user, CSRF $CSRF, Session $session, Mail $mail)
 {
     if ($user->isLogged()) {
         $placeholders['content'] = $this->getMessageLogout($CSRF, 'signupLogout');
         return $this->render('success', $placeholders);
     }
     if (($message = $session->getFlash($this->keySessionFlash)) && isset($message['email'])) {
         $placeholders['content'] = $this->template->getChunk('@common.views/elements/alert-success', ['output' => i18n::t($this->keySessionFlash, ['email' => $message['email']])]);
         return $this->render('success', $placeholders);
     }
     $model = new SignupForm();
     // redirect
     Event::on($model, SignupForm::EVENT_AFTER_SIGNUP, function (ModelEvent $event) use($session, $mail, $model) {
         $this->sendMail($mail, $event->result, $model);
         $session->setFlash('successSignup', ['email' => $event->result->email]);
         $this->response->refresh()->send(true);
     });
     $model->load($_POST);
     $placeholders['model'] = $model;
     return $this->render('index.php', $placeholders);
 }
예제 #4
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);
 }
예제 #5
0
파일: ActionEvent.php 프로젝트: romeoz/rock
 /**
  * Constructor.
  *
  * @param string $action the action associated with this action event.
  * @param array $config name-value pairs that will be used to initialize the object properties
  */
 public function __construct($action, $config = [])
 {
     $this->action = $action;
     parent::__construct($config);
 }
예제 #6
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();
 }
예제 #7
0
 /**
  * Marks the ending of an HTML page.
  * @return string
  */
 public function endPage()
 {
     Event::trigger($this, self::EVENT_END_PAGE);
     $this->clear();
     return '</html>';
 }
예제 #8
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);
 }