Example #1
0
 static function init()
 {
     $version_file = APP_PATH . '/../version';
     if (file_exists($version_file)) {
         self::$version = trim(@file_get_contents($version_file));
     }
     $config_file = APP_PATH . '/config/config.php';
     if (!file_exists($config_file)) {
         throw new Exception("No config file");
     }
     $config = (include $config_file);
     self::$config = $config;
     self::$env = $config['env'];
     #self::$context = new stdClass();
     self::$context = new Context();
     Logger::init($config['logger']);
     if (isset($config['db'])) {
         Db::init($config['db']);
     }
     if (get_magic_quotes_gpc()) {
         foreach ($_GET as $k => $v) {
             $_GET[$k] = Text::stripslashes($v);
         }
         foreach ($_POST as $k => $v) {
             $_POST[$k] = Text::stripslashes($v);
         }
         foreach ($_COOKIE as $k => $v) {
             $_COOKIE[$k] = Text::stripslashes($v);
         }
     }
     $_REQUEST = $_GET + $_POST + $_COOKIE;
 }
Example #2
0
 public static function reset()
 {
     if (App::env() !== "test") {
         return;
     }
     self::$data = array();
     self::$groups = array();
     self::$conditions = array();
 }
Example #3
0
 public static function createTmp($data = null)
 {
     $name = self::storagePath() . 'tmp/~' . str_replace(' ', '-', microtime()) . '.tmp';
     if (file_exists($name)) {
         return self::createTmp($data);
     }
     self::autoclean('tmp', App::env('appdata_expires'));
     $handle = fopen($name, 'wb');
     if ($handle === false) {
         return false;
     }
     if ($data !== null) {
         fwrite($handle, $data);
     }
     fclose($handle);
     return $name;
 }
Example #4
0
 public static function isAvailable($resource, $method)
 {
     if (App::env() === "cli") {
         return true;
     }
     list($controller, $action) = Url::route($resource, $method);
     $module = Url::module($controller);
     return Module::isActive($module) && Access::isHandlerPermitted($resource, $action);
 }
 /**
  *
  */
 public static function getPath($full = true)
 {
     return $full ? static::host() . \App::env() : static::host();
 }
Example #6
0
 /**
  * @covers \Phix\App::env
  */
 public function testEnv()
 {
     $app = new App();
     $this->assertEquals(App::ENV_PRODUCTION, $app->env());
     $app->env(null);
     $_SERVER['PHIX_ENV'] = App::ENV_STAGING;
     $this->assertEquals(App::ENV_STAGING, $app->env());
     unset($_SERVER['PHIX_ENV']);
     $app->env(null);
     $this->assertEquals(App::ENV_PRODUCTION, $app->env());
     $app->env(null);
     if (function_exists('setenv') && setenv('PHIX_ENV', App::ENV_TESTING)) {
         $this->assertEquals(App::ENV_TESTING, $app->env());
         setenv('PHIX_ENV', '');
         $app->env(null);
     }
     $app->env(App::ENV_DEVELOPMENT);
     $this->assertEquals(App::ENV_DEVELOPMENT, $app->env());
     $app->env(null);
     $ret = $app->env(function () {
         return 'callback';
     });
     $this->assertEquals('callback', $app->env());
     $this->assertEquals($ret, $app);
     $app->env(null);
 }