Exemplo n.º 1
0
 /**
  * Initialize dispatch and detects if a custom dispatcher should be used within the current scope.
  * If no scope is defined, the default dispatcher will be instantiated.
  *
  * @access public
  * @return void
  * @static
  */
 public static function initialize()
 {
     $params = Router::current();
     $dispatch = null;
     if (!empty(self::$__mapping)) {
         // Specific controller and container
         if (isset(self::$__mapping[$params['container'] . '.' . $params['controller']])) {
             $dispatch = self::$__mapping[$params['container'] . '.' . $params['controller']];
             // All controllers within a specific container
         } else {
             if (isset(self::$__mapping[$params['container'] . '.*'])) {
                 $dispatch = self::$__mapping[$params['container'] . '.*'];
                 // Specific controller within any container
             } else {
                 if (isset(self::$__mapping['*.' . $params['controller']])) {
                     $dispatch = self::$__mapping['*.' . $params['controller']];
                     // Apply to all controllers and containers
                 } else {
                     if (isset(self::$__mapping['*.*'])) {
                         $dispatch = self::$__mapping['*.*'];
                     }
                 }
             }
         }
     }
     if ($dispatch) {
         $Dispatcher = $dispatch($params);
     } else {
         switch (Environment::detect()) {
             case 'development':
                 $Dispatcher = new \titon\modules\dispatchers\front\FrontDev($params);
                 break;
             default:
                 $Dispatcher = new \titon\modules\dispatchers\front\Front($params);
                 break;
         }
     }
     if ($Dispatcher instanceof \titon\modules\dispatchers\DispatcherInterface) {
         $Dispatcher->run();
         exit;
     }
     throw new Exception(sprintf('%s Dispatcher must implement the \\titon\\modules\\dispatchers\\DispatcherInterface.', $dispatch));
 }
Exemplo n.º 2
0
 /**
  * Initialize all classes required for runtime. Master initialize method.
  *
  * @access public
  * @return void
  * @static
  */
 public static function initialize()
 {
     // Try and autoload from include_paths first
     spl_autoload_register();
     spl_autoload_register('\\titon\\core\\App::autoload');
     // Initialize core components
     Environment::initialize();
     Debugger::initialize();
     Router::initialize();
     // Get super globals
     $get = $_GET;
     $post = $_POST;
     $files = array();
     if (!empty($_FILES)) {
         foreach ($_FILES as $model => $data) {
             foreach ($data as $meta => $values) {
                 $keys = array_keys($values);
                 $files[$model][$keys[0]][$meta] = $values[$keys[0]];
             }
         }
     }
     // Clear magic quotes, just in case
     if (get_magic_quotes_gpc() > 0) {
         $stripSlashes = function ($data) {
             return is_array($data) ? array_map($stripSlashes, $data) : stripslashes($data);
         };
         $get = $stripSlashes($get);
         $post = $stripSlashes($post);
         $files = $stripSlashes($files);
     }
     static::$data = array_merge_recursive($post, $files);
     static::$globals = array('_GET' => $get, '_POST' => $post, '_FILES' => $files, '_SERVER' => $_SERVER, '_ENV' => $_ENV);
 }
Exemplo n.º 3
0
Arquivo: Setup.php Projeto: hjr3/titon
<?php

/**
 * Setup and initialize any core components or modules.
 *
 * @copyright	Copyright 2009, Titon (A PHP Micro Framework)
 * @link		http://titonphp.com
 * @license		http://opensource.org/licenses/bsd-license.php (The BSD License)
 */
namespace app\config;

use titon\core\Environment;
use titon\system\Dispatch;
use titon\system\Hook;
/**
 * Overwrite the default dispatcher with a custom dispatcher.
 * Can also restrict the dispatcher to a specific scope.
 */
switch (Environment::detect()) {
    case 'production':
        Dispatch::setup(function ($params) {
            return new \titon\modules\dispatchers\front\Front($params);
        });
        break;
}
Exemplo n.º 4
0
<?php

/**
 * Setup all your environment configurations within this file. An environment is passed an array of configurtion options
 * which power certain aspects of the framework. These options can be retrieved or overwritten using the Config class.
 *
 * @copyright	Copyright 2009, Titon (A PHP Micro Framework)
 * @link		http://titonphp.com
 * @license		http://opensource.org/licenses/bsd-license.php (The BSD License)
 */
namespace app\config;

use titon\core\Environment;
/**
 * Setup your development environment by applying the core settings.
 * To setup a production environment, copy the code below and create a production version by switching the hosts.
 */
Environment::setup('development', array('Hosts' => array('localhost', '127.0.0.1'), 'App.name' => 'Titon', 'App.salt' => '', 'App.encoding' => 'UTF-8', 'Debug.level' => 2, 'Debug.email' => '', 'Cache.enabled' => false, 'Cache.expires' => '+1 hour', 'Locale.current' => 'en_US', 'Locale.default' => 'en_US', 'Locale.timezone' => 'America/Los_Angeles'));
/**
 * Set the default environment to use if an environment is found without a matching host.
 */
Environment::setDefault('development');