Example #1
0
 /**
  * Construct a new App object
  *
  * @param String $uri an optional relative URI (e.g. "/folder/file")
  */
 public function __construct($uri = NULL)
 {
     if (is_null($uri)) {
         $uri = $_SERVER['REQUEST_URI'];
     }
     // Setup the config, prefix and assert checks
     $config = AppConfig::configure();
     load_helper('HTML', 'Text');
     load_tools('Log', 'Translate');
     $this->error_messages = array();
     $this->assert_checking($config);
     // Set the content type, folder and file
     $uri = preg_replace('/[\\?#].*/', '', $uri);
     $content_type = preg_match('/\\.(\\w+)$/', $uri, $matches) ? $matches[1] : DEFAULT_CONTENT_TYPE;
     if ($content_type === Symbol::TEST && !Config::get('TESTING_ENABLED')) {
         $content_type = DEFAULT_CONTENT_TYPE;
     }
     $uri = $this->set_lang_and_remove_prefix($uri);
     $this->parts = explode('/', $uri);
     $folder = $this->get_part(0, TRUE);
     // remove any extension
     $file = $this->get_part(1, TRUE);
     // remove any extension
     // Setup the application request environment
     $this->content_type = strtolower($content_type);
     // e.g. "html", "test"
     $this->folder = strlen($folder) > 0 ? $folder : DEFAULT_FOLDER;
     $this->file = strlen($file) > 0 ? $file : DEFAULT_FILE;
     $this->is_testing = $this->is_testing || array_key($_REQUEST, Symbol::TEST) || $content_type === Symbol::TEST;
     if ($this->is_testing) {
         Log::type(Symbol::TEST);
     }
     // If we're testing then use a test database
     require_once 'lib/Model.php';
     $model = new Model();
     $db_test = Config::get('DB_DATABASE_TEST', TRUE);
     $db_live = Config::get('DB_DATABASE_LIVE', TRUE);
     $database = $this->is_testing ? $db_test : $db_live;
     $model->set_database($database);
     // Setup the language translations
     Translate::add_translations(Config::load('validate'));
     Translate::add_translations(Config::load('translate'));
     // Register this app as a prop
     YAWF::prop(Symbol::APP, $this);
 }