예제 #1
0
 public static function init(array $settings = NULL)
 {
     if (JsonApiApplication::$_init) {
         return;
     }
     JsonApiApplication::$_init = TRUE;
     if (isset($settings["profile"])) {
         JsonApiApplication::$profiling = (bool) $settings["profile"];
     }
     ob_start();
     if (isset($settings["errors"])) {
         JsonApiApplication::$errors = (bool) $settings["errors"];
     }
     if (JsonApiApplication::$errors === TRUE) {
         set_exception_handler(array("JsonApiApplication_Exception", "handler"));
         set_error_handler(array("JsonApiApplication", "error_handler"));
     }
     if (JsonApiApplication::$environment == JsonApiApplication::DEVELOPMENT and extension_loaded("xdebug")) {
         ini_set("xdebug.collect_params", 3);
     }
     register_shutdown_function(array("JsonApiApplication", "shutdown_handler"));
     if (ini_get("register_globals")) {
         JsonApiApplication::globals();
     }
     if (isset($settings["cache_dir"])) {
         if (!is_dir($settings["cache_dir"])) {
             try {
                 mkdir($settings["cache_dir"], 0755, TRUE);
                 chmod($settings["cache_dir"], 0755);
             } catch (Exception $e) {
                 throw new JsonApiApplication_Exception("Could not create cache directory :dir", array(':dir' => Debug::path($settings["cache_dir"])));
             }
         }
         JsonApiApplication::$cache_dir = realpath($settings["cache_dir"]);
     } else {
         JsonApiApplication::$cache_dir = APPPATH . "cache";
     }
     if (!is_writable(JsonApiApplication::$cache_dir)) {
         throw new JsonApiApplication_Exception('Directory :dir must be writable', array(':dir' => Debug::path(JsonApiApplication::$cache_dir)));
     }
     if (isset($settings["cache_life"])) {
         JsonApiApplication::$cache_life = (int) $settings["cache_life"];
     }
     if (isset($settings['caching'])) {
         JsonApiApplication::$caching = (bool) $settings["caching"];
     }
     if (JsonApiApplication::$caching === TRUE) {
         JsonApiApplication::$_files = JsonApiApplication::cache("JsonApiApplication::find_file()");
     }
     JsonApiApplication::$magic_quotes = (bool) get_magic_quotes_gpc();
     $_GET = JsonApiApplication::sanitize($_GET);
     $_POST = JsonApiApplication::sanitize($_POST);
     $_COOKIE = JsonApiApplication::sanitize($_COOKIE);
     if (!JsonApiApplication::$log instanceof Log) {
         JsonApiApplication::$log = Log::instance();
     }
     if (!JsonApiApplication::$config instanceof Config) {
         JsonApiApplication::$config = new Config();
     }
     JsonApiApplication::$_modules = JsonApiApplication::$_files = array();
 }