Beispiel #1
0
 /**
  * puts any params in the url into an assoc array in the dispatcher
  * for example given this url
  *		/en/employer/profile/edit/id/5/company/6/email/test@test.com
  * then in the controller
  *		$this->dispatcher->getParam('id') = 5
  *		$this->dispatcher->getParam('company') = 6
  *		$this->dispatcher->getParam('email') = test@test.com
  * @param Event $event
  * @param Dispatcher $dispatcher
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $key_params = array();
     $params = $dispatcher->getParams();
     foreach ($params as $number => $value) {
         if ($number & 1) {
             $key_params[$params[$number - 1]] = $value;
         }
     }
     //loop again so we don't overwrite any params named in the route (like 'lang')
     foreach ($key_params as $param => $value) {
         if ($dispatcher->getParam($param) === null) {
             $dispatcher->setParam($param, $value);
         }
     }
 }
 /**
  * @param \Phalcon\Events\Event $event
  * @param \Phalcon\Mvc\Dispatcher $dispatcher
  * @param array $params
  * @return mixed
  */
 public function action(Event $event, Dispatcher $dispatcher, $params)
 {
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $key = $controller . '/' . $action;
     // $cname = $dispatcher->getDI()->get(AppConstant::DI_SERVICE_API)->getApiClass($key);
     //非注册Api,不需要做校验
     // if ($cname == null) return;
     $cname = 'Account\\register';
     $c = new \ReflectionClass($cname);
     $object = $c->newInstance();
     //赋值
     $this->arrToObj($object, $params);
     $this->validate($cname, $object);
     $dispatcher->setParam(AppConstant::HTTP_PROTOCOL_DATA, $object);
 }
Beispiel #3
0
 /**
  * @param Event $event
  * @param Dispatcher $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     $role = 'guest';
     if ($this->session->has('user_id')) {
         $userId = $this->session->get('user_id');
         if ($userId) {
             $user = User::findFirst($userId);
             if ($user instanceof User) {
                 $role = 'user';
                 $dispatcher->setParam('user', $user);
             }
         }
     }
     $controller = strtolower($dispatcher->getControllerName());
     $action = strtolower($dispatcher->getActionName());
     if (!$this->acl->isAllowed($role, $controller, $action)) {
         $this->session->set('__callback_url', $this->request->getServer('REQUEST_URI'));
         $dispatcher->forward(['controller' => 'auth', 'action' => 'signIn']);
         return false;
     }
     return true;
 }