/** * construct * @param string $name the name of the collection */ function __construct($name) { $this->collectionName = strtolower($name); $dbConnect = Config::getDbConf('MongoDB'); $uri = 'mongodb://' . $dbConnect['host'] . ':' . $dbConnect['port']; $this->manager = new Manager($uri); $this->client = new Client($uri); }
/** * load a Controller * @param Request $request the client request * @return mixed a Controller */ static function load() { $request = Request::getInstance(); $fileName = Config::controllerDIR() . DS . $request->controller . 'Controller.php'; if (!file_exists($fileName)) { throw new \Exception("Controller {$request->controller} does not exist", 101); } require $fileName; $name = $request->namespace . '\\Controller\\' . $request->controller . 'Controller'; return new $name(); }
/** * create the path/to/folder for diferante view * @return void */ public function makePath() { $this->layoutPath = Config::layoutDir() . DS . $this->layout . '.ctp'; if (!file_exists($this->layoutPath)) { throw new \Exception("the layout file : {$this->layoutPath} does not exist", 601); } $viewFolder = strtolower(str_replace('Controller', '', $this->request->controller)); $this->viewPath = Config::viewDir() . DS . $viewFolder . DS . $this->request->action . '.ctp'; if (!file_exists($this->viewPath)) { throw new \Exception("the view file : {$this->viewPath} does not exist", 601); } }
public function __construct() { try { Session::start(); Config::getConf(); $this->request = Request::getInstance(); $this->router = new Router($this->request); $this->request->setRouter($this->router); $this->controller = MasterController::load(); } catch (\Exception $e) { $this->controller = new ErrorController($e); //c'est fait } }
/** * construct * @param Exception $exception the exception */ public function __construct($exception) { $this->request = Request::getInstance(); $save['controller'] = $this->request->controller; $this->request->controller = 'ErrorController'; $save['action'] = $this->request->action; if (Config::getDebug()) { $this->request->action = 'error'; } else { $this->request->action = 'error404'; } $this->request->params = ['error' => $exception]; $this->view = new MasterView(); $this->view->set($save); $this->view->layout = 'error'; $this->loadTools(); $this->execute(); }
public function find($collectionName, $query) { $collection = $this->getCollection($collectionName); $filter = $query['filter']; $option = $query['options']; $dOption = Config::get('paginator'); $option = array_replace_recursive($dOption, $option); $option['skip'] = $option['limit'] * ($option['page'] - 1); $option['count'] = $collection->count($filter); $result = $collection->find($filter, $option); $retour = []; foreach ($result as $data) { $retour[] = $data; } debug($filter); debug($option); $paginator = new Paginator($retour); unset($option['skip']); $paginator->setOption($option); return $paginator; }
/** * translates information of the request for application * @param Request &$request the request */ function __construct(Request &$request) { $this->routes = Config::getRoutes(); $params = []; $uri = $request->uri; if (array_key_exists($uri, $this->routes)) { $request->namespace = $this->routes[$uri]['options']['namespace']; $request->controller = ucfirst($this->routes[$uri]['options']['controller']); $request->action = $this->routes[$uri]['options']['action']; if (isset($this->routes[$uri]['params'])) { $request->params = $this->routes[$uri]['params']; } } else { $uri = substr($request->uri, 1); $tmp = explode('/', $uri); $request->namespace = Config::getDefaultNamespace(); $request->controller = ucfirst($tmp[0]); $request->action = isset($tmp[1]) ? $tmp[1] : Config::getDefaultAction(); if (isset($tmp[2]) && !empty($tmp[2])) { $request->params = array_slice($tmp, 2); } } }
/** * create the form object * @param array $data the data to put in input */ function __construct($data = []) { $this->data = $data; $this->dClass = Config::get('form.class'); }