/** * Initializes the framework. This can only be called once. * * @access public * @return void */ public static function init($config) { if (static::$initialized) { throw new \Exception("You can't initialize Fuel more than once."); } register_shutdown_function('fuel_shutdown_handler'); set_exception_handler('fuel_exception_handler'); set_error_handler('fuel_error_handler'); // Start up output buffering ob_start(); static::$profiling = isset($config['profiling']) ? $config['profiling'] : false; if (static::$profiling) { \Profiler::init(); \Profiler::mark(__METHOD__ . ' Start'); } static::$cache_dir = isset($config['cache_dir']) ? $config['cache_dir'] : APPPATH . 'cache/'; static::$caching = isset($config['caching']) ? $config['caching'] : false; static::$cache_lifetime = isset($config['cache_lifetime']) ? $config['cache_lifetime'] : 3600; if (static::$caching) { static::$path_cache = static::cache('Fuel::path_cache'); } \Config::load($config); static::$_paths = array_merge(\Config::get('module_paths', array()), array(APPPATH, COREPATH)); static::$is_cli = (bool) (php_sapi_name() == 'cli'); if (!static::$is_cli) { if (\Config::get('base_url') === null) { \Config::set('base_url', static::generate_base_url()); } \Uri::detect(); } // Run Input Filtering \Security::clean_input(); static::$env = \Config::get('environment'); static::$locale = \Config::get('locale'); //Load in the packages foreach (\Config::get('always_load.packages', array()) as $package) { static::add_package($package); } // Set some server options setlocale(LC_ALL, static::$locale); // Always load classes, config & language set in always_load.php config static::always_load(); static::$initialized = true; if (static::$profiling) { \Profiler::mark(__METHOD__ . ' End'); } }
/** * Accessor method for the class path templates which `Libraries` uses to look up and load * classes. Using this method, you can define your own types of classes, or modify the default * organization of built-in class types. * * For example, in a queuing application, you can define a class type called `'job'`: * {{{ * Libraries::paths(array('job' => '{:library}\extensions\job\{:name}')); * }}} * * Then, any classes you add to the `extensions/job` directory in your application will be * automatically detected when calling `Libraries::locate('job')`. Additionally, any matching * classes in the `extensions/job` directory of any plugin or vendor library you add to your * application will also be detected. * * Supposing you wanted to have the option of further organizing jobs by class type (some jobs * are related to updating caches, others to sending notifications, etc.), you can specify * multiple paths per class type, with varying levels of specificity: * {{{ * Libraries::paths(array('job' => array( * '{:library}\extensions\job\{:class}\{:name}', * '{:library}\extensions\job\{:name}' * ))); * }}} * * This allows you to, for example, have two different classes called `Cleanup`. One may be * located in `app\extensions\job\Cleanup`, while the other is in * `app\extensions\job\cache\Cleanup`. Calling: {{{Libraries::locate('job');}}} will find * both classes, while {{{Libraries::locate('job.cache');}}} will only find the second. You can * also find individual jobs by name: {{{Libraries::locate('job', 'Cleanup');}}} * * See `Libraries::locate()` for more information on using built-in and user-defined paths to * look up classes. * * In addition to adding custom class types, `paths()` allows you to redefine the naming and * organization of existing types. For example, if you wished to reference your model classes * as `app\models\PostModel` instead of `app\models\Post`, you can do the following: * {{{Libraries::paths(array('models' => '{:library}\models\{:name}Model'));}}} Note, however, * that this is a destructive, not an additive operation, and will replace any existing paths * defined for that type. If you wish to add a search path for an existing type, you must do * the following: * {{{ * $existing = Libraries::paths('controllers'); * Libraries::paths(array('controller' => array_merge( * array('{:library}\extensions\controllers\{:name}Controller'), (array) $existing * ))); * }}} * * @see lithium\core\Libraries::locate() * @see lithium\core\Libraries::$_paths * @param mixed $path If `$path` is a string, returns the path(s) associated with that path * type, or `null` if no paths are defined for that type. * @return mixed */ public static function paths($path = null) { if (empty($path)) { return static::$_paths; } if (is_string($path)) { return isset(static::$_paths[$path]) ? static::$_paths[$path] : null; } static::$_paths = array_filter(array_merge(static::$_paths, (array) $path)); }
/** * Initializes the framework. * This can only be called once. * * @access public * @return void */ public static function init($config) { if (static::$initialized) { throw new \FuelException("You can't initialize Fuel more than once."); } // BC FIX FOR APPLICATIONS <= 1.6.1, makes Redis_Db available as Redis, // like it was in versions before 1.7 class_exists('Redis', false) or class_alias('Redis_Db', 'Redis'); static::$_paths = array(APPPATH, COREPATH); // Is Fuel running on the command line? static::$is_cli = (bool) defined('STDIN'); \Config::load($config); // Start up output buffering static::$is_cli or ob_start(\Config::get('ob_callback', null)); if (\Config::get('caching', false)) { \Finder::instance()->read_cache('FuelFileFinder'); } static::$profiling = \Config::get('profiling', false); static::$profiling and \Profiler::init(); // set a default timezone if one is defined try { static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get(); date_default_timezone_set(static::$timezone); } catch (\Exception $e) { date_default_timezone_set('UTC'); throw new \PHPErrorException($e->getMessage()); } static::$encoding = \Config::get('encoding', static::$encoding); MBSTRING and mb_internal_encoding(static::$encoding); static::$locale = \Config::get('locale', static::$locale); if (!static::$is_cli) { if (\Config::get('base_url') === null) { \Config::set('base_url', static::generate_base_url()); } } // Run Input Filtering \Security::clean_input(); \Event::register('fuel-shutdown', 'Fuel::finish'); // Always load classes, config & language set in always_load.php config static::always_load(); // Load in the routes \Config::load('routes', true); \Router::add(\Config::get('routes')); // Set locale, log warning when it fails if (static::$locale) { setlocale(LC_ALL, static::$locale) or logger(\Fuel::L_WARNING, 'The configured locale ' . static::$locale . ' is not installed on your system.', __METHOD__); } static::$initialized = true; // fire any app created events \Event::instance()->has_events('app_created') and \Event::instance()->trigger('app_created', '', 'none'); if (static::$profiling) { \Profiler::mark(__METHOD__ . ' End'); } }
/** * Initializes the framework. This can only be called once. * * @access public * @return void */ public static function init($config) { if (static::$initialized) { throw new \FuelException("You can't initialize Fuel more than once."); } static::$_paths = array(APPPATH, COREPATH); // Is Fuel running on the command line? static::$is_cli = (bool) defined('STDIN'); \Config::load($config); // Start up output buffering ob_start(\Config::get('ob_callback', null)); static::$profiling = \Config::get('profiling', false); if (static::$profiling) { \Profiler::init(); \Profiler::mark(__METHOD__ . ' Start'); } static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/'); static::$caching = \Config::get('caching', false); static::$cache_lifetime = \Config::get('cache_lifetime', 3600); if (static::$caching) { \Finder::instance()->read_cache('Fuel::paths'); } // set a default timezone if one is defined static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get(); date_default_timezone_set(static::$timezone); static::$encoding = \Config::get('encoding', static::$encoding); MBSTRING and mb_internal_encoding(static::$encoding); static::$locale = \Config::get('locale', static::$locale); if (!static::$is_cli) { if (\Config::get('base_url') === null) { \Config::set('base_url', static::generate_base_url()); } } // Run Input Filtering \Security::clean_input(); \Event::register('shutdown', 'Fuel::finish'); // Always load classes, config & language set in always_load.php config static::always_load(); // Load in the routes \Config::load('routes', true); \Router::add(\Config::get('routes')); // Set locale, log warning when it fails if (static::$locale) { setlocale(LC_ALL, static::$locale) or logger(\Fuel::L_WARNING, 'The configured locale ' . static::$locale . ' is not installed on your system.', __METHOD__); } static::$initialized = true; // fire any app created events \Event::instance()->has_events('app_created') and \Event::instance()->trigger('app_created', '', 'none'); if (static::$profiling) { \Profiler::mark(__METHOD__ . ' End'); } }
/** * Initializes the framework. This can only be called once. * * @access public * @return void */ public static function init($config) { \Config::load($config); if (static::$initialized) { throw new \Fuel_Exception("You can't initialize Fuel more than once."); } register_shutdown_function('fuel_shutdown_handler'); set_exception_handler('fuel_exception_handler'); set_error_handler('fuel_error_handler'); // Start up output buffering ob_start(\Config::get('ob_callback', null)); static::$profiling = \Config::get('profiling', false); if (static::$profiling) { \Profiler::init(); \Profiler::mark(__METHOD__ . ' Start'); } static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/'); static::$caching = \Config::get('caching', false); static::$cache_lifetime = \Config::get('cache_lifetime', 3600); if (static::$caching) { static::$path_cache = static::cache('Fuel::path_cache'); } // set a default timezone if one is defined static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get(); date_default_timezone_set(static::$timezone); // set the encoding and locale to use static::$encoding = \Config::get('encoding', static::$encoding); static::$locale = \Config::get('locale', static::$locale); static::$_paths = array(APPPATH, COREPATH); if (!static::$is_cli) { if (\Config::get('base_url') === null) { \Config::set('base_url', static::generate_base_url()); } \Uri::detect(); } // Run Input Filtering \Security::clean_input(); static::$env = \Config::get('environment'); \Event::register('shutdown', 'Fuel::finish'); //Load in the packages foreach (\Config::get('always_load.packages', array()) as $package => $path) { is_string($package) and $path = array($package => $path); static::add_package($path); } // Load in the routes \Config::load('routes', true); \Router::add(\Config::get('routes')); // Set locale static::$locale and setlocale(LC_ALL, static::$locale); // Always load classes, config & language set in always_load.php config static::always_load(); static::$initialized = true; if (static::$profiling) { \Profiler::mark(__METHOD__ . ' End'); } }
/** * Initializes the framework. This can only be called once. * * @access public * @return void */ public static function init($config) { if (static::$initialized) { throw new \FuelException("You can't initialize Fuel more than once."); } static::$_paths = array(APPPATH, COREPATH); // Is Fuel running on the command line? static::$is_cli = (bool) defined('STDIN'); \Config::load($config); // Start up output buffering ob_start(\Config::get('ob_callback', null)); static::$profiling = \Config::get('profiling', false); if (static::$profiling) { \Profiler::init(); \Profiler::mark(__METHOD__ . ' Start'); } static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/'); static::$caching = \Config::get('caching', false); static::$cache_lifetime = \Config::get('cache_lifetime', 3600); if (static::$caching) { \Finder::instance()->read_cache('Fuel::paths'); } // set a default timezone if one is defined static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get(); date_default_timezone_set(static::$timezone); static::$encoding = \Config::get('encoding', static::$encoding); MBSTRING and mb_internal_encoding(static::$encoding); static::$locale = \Config::get('locale', static::$locale); if (!static::$is_cli) { if (\Config::get('base_url') === null) { \Config::set('base_url', static::generate_base_url()); } } // Run Input Filtering \Security::clean_input(); \Event::register('shutdown', 'Fuel::finish'); //Load in the packages foreach (\Config::get('always_load.packages', array()) as $package => $path) { is_string($package) and $path = array($package => $path); \Package::load($path); } // Always load classes, config & language set in always_load.php config static::always_load(); // Load in the routes \Config::load('routes', true); \Router::add(\Config::get('routes')); // Set locale static::$locale and setlocale(LC_ALL, static::$locale); static::$initialized = true; if (static::$profiling) { \Profiler::mark(__METHOD__ . ' End'); } }