/** * * Starts Solar: loads configuration values and and sets up the environment. * * Note that this method is overloaded; you can pass in different * value types for the $config parameter. * * * `null|false` -- This will not load any new configuration values; * you will get only the default [[Solar::$config]] array values defined * in the Solar class. * * * `string` -- The string is treated as a path to a Solar.config.php * file; the return value from that file will be used for [[Solar_Config::load()]]. * * * `array` -- This will use the passed array for the [[Solar_Config::load()]] * values. * * * `object` -- The passed object will be cast as an array, and those * values will be used for [[Solar_Config::load()]]. * * Here are some examples of starting with alternative configuration parameters: * * {{code: php * require_once 'Solar.php'; * * // don't load any config values at all * Solar::start(); * * // point to a config file (which returns an array) * Solar::start('/path/to/another/config.php'); * * // use an array as the config source * $config = array( * 'Solar' => array( * 'ini_set' => array( * 'error_reporting' => E_ALL, * ), * ), * ); * Solar::start($config); * * // use an object as the config source * $config = new StdClass; * $config->Solar = array( * 'ini_set' => array( * 'error_reporting' => E_ALL, * ), * ); * Solar::start($config); * }} * * @param mixed $config The configuration source value. * * @return void * * @see Solar::cleanGlobals() * */ public static function start($config = null) { // don't re-start if we're already running. if (Solar::$_status) { return; } // make sure these classes are loaded $list = array('Base', 'Class', 'Config', 'File'); $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Solar'; foreach ($list as $name) { // don't use the autoloader when checking for existence if (!class_exists('Solar_' . $name, false)) { require $dir . DIRECTORY_SEPARATOR . "{$name}.php"; } } // register autoloader spl_autoload_register(array('Solar_Class', 'autoload')); // clear out registered globals if (ini_get('register_globals')) { Solar::cleanGlobals(); } // load config values Solar_Config::load($config); // make sure we have the Solar arch-class configs $arch_config = Solar_Config::get('Solar'); if (!$arch_config) { Solar_Config::set('Solar', null, Solar::$_Solar); } else { Solar_Config::set('Solar', null, array_merge(Solar::$_Solar, (array) $arch_config)); } // set the system directory Solar::$system = Solar_Config::get('Solar', 'system'); // process ini settings from config file $settings = Solar_Config::get('Solar', 'ini_set', array()); foreach ($settings as $key => $val) { ini_set($key, $val); } // user-defined registry entries $register = Solar_Config::get('Solar', 'registry_set', array()); foreach ($register as $name => $list) { // make sure we have the class-name and a config $list = array_pad((array) $list, 2, null); list($spec, $config) = $list; // register the item Solar_Registry::set($name, $spec, $config); } // Solar itself needs these default objects registered ... $name_class = array('inflect' => 'Solar_Inflect', 'locale' => 'Solar_Locale', 'rewrite' => 'Solar_Uri_Rewrite', 'request' => 'Solar_Request', 'response' => 'Solar_Http_Response'); // ... but only if not already registered by the user. foreach ($name_class as $name => $class) { if (!Solar_Registry::exists($name)) { Solar_Registry::set($name, $class); } } // run any 'start' hooks $hooks = Solar_Config::get('Solar', 'start', array()); Solar::callbacks($hooks); // and we're done! Solar::$_status = true; }