Ejemplo n.º 1
0
 public static function &getInstance($args = array())
 {
     if (is_null(self::$instance)) {
         self::$instance = new Request();
         self::$instance->args = $args;
         if (!isset($_SESSION[Config::Core_get('session_flash_varname')])) {
             $_SESSION[Config::Core_get('session_flash_varname')] = array('new' => array(), 'old' => array());
         }
         $_SESSION[Config::Core_get('session_flash_varname')]['old'] = $_SESSION[Config::Core_get('session_flash_varname')]['new'];
         $_SESSION[Config::Core_get('session_flash_varname')]['new'] = array();
         self::$instance->protocol = strtolower(explode('/', $_SERVER['SERVER_PROTOCOL'])[0]);
         self::$instance->host = $_SERVER['HTTP_HOST'];
         self::$instance->urn = $_SERVER['REQUEST_URI'];
         self::$instance->uri = self::$instance->protocol . '://' . self::$instance->host . self::$instance->urn;
         self::$instance->url = self::$instance->protocol . '://' . self::$instance->host;
         self::$instance->method = strtolower($_SERVER['REQUEST_METHOD']);
         if (!isset($_SESSION[Config::Core_get('session_history_varname')])) {
             $_SESSION[Config::Core_get('session_history_varname')] = array_fill(0, 10, self::$instance->url);
         }
         if (self::$instance->method = 'post') {
             foreach ($_FILES as $key => &$value) {
                 if (is_array($_FILES[$key]['name'])) {
                     $value = Tools::diverse_array($value);
                 }
                 $value = (object) $value;
             }
         }
         self::$instance->addReferer(self::$instance->uri);
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
 static function loadFor($apps)
 {
     if (empty(self::$app_config)) {
         self::$loaded = true;
         if (false === ($cache = Cache::get('appconfig', join(DIRECTORY_SEPARATOR, array_filter($apps))))) {
             $appspath = array('');
             $buffer = '';
             foreach ($apps as $app) {
                 if (!empty($app)) {
                     $buffer .= DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . $app;
                     $appspath[] = $buffer;
                 }
             }
             foreach ($appspath as $currentpath) {
                 $app_config = array();
                 $path = ROOT . DIRECTORY_SEPARATOR . 'app' . $currentpath . DIRECTORY_SEPARATOR . 'config';
                 $configfiles = is_dir($path) ? Tools::file_get_contents_loop($path) : array();
                 foreach ($configfiles as $name => $content) {
                     $app_config[$name] = json_decode($content, true);
                 }
                 $app_config = Tools::flatten($app_config);
                 self::$app_config = array_merge(self::$app_config, $app_config);
             }
             Cache::create('appconfig', join(DIRECTORY_SEPARATOR, array_filter($apps)), self::$app_config, 'on_demand');
         } else {
             self::$app_config = $cache;
         }
     }
 }
Ejemplo n.º 3
0
 public function anyTestAction($req, $res, $code, $args)
 {
     if (!is_null($req->getArg(0))) {
         list($uri, $msg) = unserialize(Tools::base64url_decode($req->getArg(0)));
     } else {
         if (empty($code)) {
             $code = $args[0];
             $msg = '';
         } else {
             $msg = $args[0];
         }
     }
     echo 'URL : /' . (isset($uri) ? $uri : FrontController::$uri) . "\n";
     echo 'Error : ' . $code . ' ' . $this->MessageFor($code) . "\n";
     echo 'Message : ' . $msg . "\n";
     return $res->setViewAbs('', 'buffer')->setHeader('Content-Type', 'text/plain');
 }
Ejemplo n.º 4
0
 static function init($rootDir, $dev = false)
 {
     session_start();
     self::$root = $rootDir;
     define('ROOT', self::$root);
     define('DEV_ENV', $dev);
     define('PROD_ENV', !$dev);
     $autoloader = new Autoloader();
     $autoloader->registerAutoload();
     if ($dev) {
         @Tools::rrmdir(ROOT . DIRECTORY_SEPARATOR . 'private' . DIRECTORY_SEPARATOR . 'cache');
     }
     //include(__DIR__.DIRECTORY_SEPARATOR.'alias.php');
     Config::Init();
     if (!empty(Config::Core_get('session_user_lifetime'))) {
         ini_set('session.cookie_lifetime', Config::Core_get('session_client_lifetime'));
         ini_set('session.gc_maxlifetime', Config::Core_get('session_server_lifetime'));
     }
 }
Ejemplo n.º 5
0
 public static function getView($view, $vars = array(), $return = false)
 {
     $apps = explode('\\', get_called_class());
     $apps = array_splice($apps, 1, -2);
     $path = Tools::pathfor($apps, 'views' . DIRECTORY_SEPARATOR . str_replace('..', '.', $view) . '.php');
     ob_start();
     include $path;
     $output = ob_get_clean();
     if ($return) {
         return $output;
     }
     echo $output;
 }
Ejemplo n.º 6
0
 static function values2dimensions($values, &$arr)
 {
     $e = array_shift($values);
     if (!is_null($e)) {
         if (!isset($arr[$e])) {
             $arr[$e] = array();
         }
         Tools::values2dimensions($values, $arr[$e]);
     }
 }
Ejemplo n.º 7
0
 static function redirect($apps = array(), $controller = '', $method = '', $args = array())
 {
     self::redirectURL(Tools::urlfor($apps, $controller, $method, $args), true, true);
 }