public function __construct() { // Required because some times Doctrine and more generally spl_autoload_register() // doesn't work when used with an opcode cache (APC) register_shutdown_function("session_write_close"); session_start(); $this->container = Seringue::get_instance(); $this->container->page = new Utilities\Page($GLOBALS['env']['environment'] == "production" ? false : true); $this->route = Route::get_instance(); $this->request = Request::get_instance(); $this->response = Response::get_instance(); $this->log = $this->container->log_nano; $this->i18n = Utilities\I18N::get_instance(); $this->set_view_engine($this->container->configuration['view']['engine']); $this->cache = new Cache\Cache(new Cache\File(DIR_CACHE)); $this->get_cache_config(); $this->security = Security::get_instance(); }
static function render_for_javascripts() { return Kernel\Seringue::get_instance()->page->render_for_javascripts(); }
/** * Constructor * @param string $stringException * @param integer $levelException http://fr.php.net/manual/fr/ref.errorfunc.php#errorfunc.constants */ function __construct($string, $level = E_NOTICE) { parent::__construct($string); $this->_level = $level; $this->log = Seringue::get_instance()->log_nano; }
public function __construct() { $this->log = Seringue::get_instance()->log_nano; }
/** * Route decoding * * This one decodes the route accordingly to the configuration/route.php file * module, controller, action and additionnal parameters are returned as an array if the route decodes successfully * * @returns array module, controller, action and parameters */ public function route_decode($url = null) { if ($url == null) { $url = $_SERVER["REQUEST_URI"]; } $current_route = $variables_array = $parameters = array(); $route_found = false; // Get the route config into $this->route_config $this->get_route_config(); $module_config = $this->route_config[$GLOBALS['env']['MODULE_NAME']]; // Strip all the parameters after the ? (they are in the $_GET array) $query = preg_replace("/\\?(.*)\$/", '', $url); unset($_GET[$query]); // Strip the first parameter if it's /xxx.php $query = preg_replace("/^\\/(.*)\\.php/", '', $query); // Look on each routes to find a match foreach ($module_config["routes"] as $route_name => $route) { // Extract the parameter from the toute $route_parameters = $this->get_parameters($route["route"]); // Create a regexp to check if the route matches the query $match_reg = "{$route['route']}"; $match_reg = str_replace('/', '\\/', $match_reg); $match_reg = "/{$match_reg}\$/"; // Match a parameter foreach ($route_parameters as $route_parameter) { $match_reg = str_replace(":{$route_parameter}", "([a-zA-Z0-9_\\-=%\\.]+)", $match_reg); } // Check if the route matches the url if (preg_match($match_reg, $query, $query_parameters)) { $route_found = true; $current_route = $route; break; } } $parameters['module'] = $GLOBALS['env']['MODULE_NAME']; // Route not found if ($route_found === false) { Seringue::get_instance()->log_nano->addInfo(_('Route schema not found routing to default controller/action')); $parameters['controller'] = $module_config['default_controller']; $parameters['action'] = $module_config['default_action']; } else { // Extract the parameters from the query foreach ($route_parameters as $i => $route_parameter) { // The first element of $query_parameters is the query itself, we don't need it $variables_array[$route_parameter] = $query_parameters[$i + 1]; } // Get the controller/action from the variables, route or default module config if (isset($variables_array["controller"])) { $parameters['controller'] = $variables_array["controller"]; } else { if (isset($current_route["controller"])) { $parameters['controller'] = $current_route["controller"]; } else { $parameters['controller'] = $module_config["default_controller"]; } } if (isset($variables_array["action"])) { $parameters['action'] = $variables_array["action"]; } else { if (isset($current_route["action"])) { $parameters['action'] = $current_route["action"]; } else { $parameters['action'] = $module_config["default_action"]; } } Seringue::get_instance()->log_nano->addInfo(_("Route found : {$route['route']} -> {$parameters['controller']}/{$parameters['action']}")); } // Mix all parameters together $parameters = array_merge($parameters, $_FILES); $parameters = array_merge($parameters, $_POST); $parameters = array_merge($parameters, $_GET); $parameters = array_merge($parameters, $variables_array); // Add the controller's namespace in front of the controller's class $parameters['controller'] = $parameters['controller']; return $parameters; }