/** * construct * c'est le bordel ici * @param Request $request the request */ public function __construct() { EventManager::getInstance()->event('controller.construct', $this); $this->request = Request::getInstance(); $name = explode('\\', get_class($this)); if ($this->collection === 'default') { $modelName = str_replace('Controller', '', $name[2]); } else { $modelName = $this->collection; } $this->{$modelName} = MasterModel::load($modelName); $this->_loadTools(); $this->_iniView(); }
/** * render the view */ public function render() { EventManager::getInstance()->event('view.render.before', $this); $this->makePath(); $this->loadHelper(); extract($this->data); ob_start(); require $this->viewPath; $this->content = ob_get_clean(); if ($this->displayLayout) { require $this->layoutPath; } else { echo $this->content; } }
public function login() { if ($this->request->isPost()) { $data = $this->request->data; $user = $this->User->findOne(['username' => $data->username]); if (!empty($user)) { if (password_verify($data->password, $user->password)) { $user->_id = $user->_id->__toString(); //MongoDB\BSON\ObjectID fatal error session $link = Auth::getInstance()->setAuth($user); EventManager::getInstance()->event('users.login', $this); $this->Flash->set('success', ['class' => 'success']); $this->request->redirect($link); } } $this->Flash->set('invalide login or password', ['class' => 'warning']); } Auth::getInstance()->setBackLink(); }
public function __construct() { try { Config::getConf(); Auth::loadClass(); //we c'est un peux de la triche Session::start(); EventManager::init(); $this->request = Request::getInstance(); $this->router = Router::getInstance(); $this->auth = Auth::getInstance(); include_once APP_FOLDER . DS . 'config' . DS . 'bootstrap.php'; $this->request->securePost(); $view = $this->router->execute(); $view->render(); } catch (Exception $e) { $this->controller = new ErrorController($e); } }
/** * redirect the request to a new link * @param array $link a array description of the link */ public function redirect($link = []) { EventManager::getInstance()->event('request.redirect', $this); Auth::getInstance()->notDirect(); $url = ''; //debug($link); if (is_string($link)) { $url = $this->url(Router::getInstance()->getRouteByName($link)); } else { $url = $this->url($link); } //debug($url); header('Location: ' . $url); exit; }
function firstStep() { EventManager::getInstance()->event('auth.firstStep', $this); }
/** * construct * @param string $name the name of the collection */ function __construct($name) { $this->collectionName = strtolower($name); $this->loadBehavior(); EventManager::getInstance()->event('model.construct', $this); }
/** * delete document * @param array $query the query * @return MongoDB\DeleteResult | false */ public function delete($query = []) { if (!empty($query)) { EventManager::getInstance()->event('model.query.delete', $this, $query); return $this->collection->deleteOne($query); } return false; }
public function getElement($link) { EventManager::getInstance()->event('router.element.before', $this); $cName = $this->makeControllerName($link); $controller = Factory::load($cName); $method = new \ReflectionMethod($controller, $link['action']); if (!isset($this->permission)) { $method->invokeArgs($controller, $link['params']); return $controller->_getView(); } else { if ($method->isPublic()) { if ($this->permission->checkPublicAccess($link)) { $method->invokeArgs($controller, $link['params']); return $controller->_getView(); } } elseif ($method->isProtected()) { if ($this->permission->checkProtectedAccess($link)) { $method->setAccessible(true); $method->invokeArgs($controller, $link['params']); return $controller->_getView(); } } elseif ($method->isPrivate()) { if ($this->permission->checkPrivateAccess($link)) { $method->setAccessible(true); $method->invokeArgs($controller, $link['params']); return $controller->_getView(); } } } EventManager::getInstance()->event('router.element.after', $this); return false; }
/** * find query * @param array $query the query * @return array entity liste */ public function find($option = []) { $option = array_replace_recursive($this->defaultQuery, $option); $this->convertId($option['query']); $query = $option['query']; EventManager::getInstance()->event('collection.query.find', $this, $option, get_class($this)); unset($option['query']); $cursor = $this->collection->find($query, $option); $retour = []; foreach ($cursor as $entityData) { $retour[] = $this->createEntity($entityData); } return $retour; }