public function testAdditionalPathAfterInitialRegister() { Loader::register(); $this->assertEqual(Loader::getLookupPath(), array(THINKUP_WEBAPP_PATH . '_lib' . DS . 'model' . DS, THINKUP_WEBAPP_PATH . '_lib' . DS . 'controller' . DS, THINKUP_WEBAPP_PATH . '_lib' . DS . 'model' . DS . 'exceptions' . DS)); Loader::addPath(THINKUP_ROOT_PATH . 'tests' . DS . 'classes'); $this->assertEqual(Loader::getLookupPath(), array(THINKUP_WEBAPP_PATH . '_lib' . DS . 'model' . DS, THINKUP_WEBAPP_PATH . '_lib' . DS . 'controller' . DS, THINKUP_WEBAPP_PATH . '_lib' . DS . 'model' . DS . 'exceptions' . DS, THINKUP_ROOT_PATH . 'tests' . DS . 'classes')); }
public function testAdditionalPathAfterInitialRegister() { Loader::register(); $this->assertEqual(Loader::getLookupPath(), array(THINKUP_WEBAPP_PATH . '_lib/model/', THINKUP_WEBAPP_PATH . '_lib/controller/', THINKUP_WEBAPP_PATH . '_lib/model/exceptions/')); Loader::addPath(THINKUP_ROOT_PATH . 'tests/classes'); $this->assertEqual(Loader::getLookupPath(), array(THINKUP_WEBAPP_PATH . '_lib/model/', THINKUP_WEBAPP_PATH . '_lib/controller/', THINKUP_WEBAPP_PATH . '_lib/model/exceptions/', THINKUP_ROOT_PATH . 'tests/classes')); }
* @package core * @author stefano.azzolini@caffeinalab.com * @version 1.0 * @copyright Caffeina srl - 2014 - http://caffeina.co */ namespace phpcore; class Loader { protected static $paths = []; public static function addPath($path, $name = null) { static::$paths[$path] = $name; } public static function register() { ini_set('unserialize_callback_func', 'spl_autoload_call'); spl_autoload_register(function ($class) { $cfile = strtr($class, '_\\', '//') . '.php'; foreach (static::$paths as $path => $v) { $file = rtrim($path, '/') . '/' . $cfile; if (is_file($file)) { return include $file; } } return false; }, false, true); } } Loader::addPath(__DIR__); Loader::register();
/** * Initalize app * Load config file and required plugins * @throws Exception */ private function initalizeApp() { $classname = get_class($this); if ($classname != "InstallerController") { //Initialize config $config = Config::getInstance(); if ($config->getValue('debug')) { ini_set("display_errors", 1); ini_set("error_reporting", E_STRICT); } if ($classname != "BackupController") { //Init plugins $plugin_dao = DAOFactory::getDAO('PluginDAO'); $active_plugins = $plugin_dao->getActivePlugins(); Loader::definePathConstants(); foreach ($active_plugins as $active_plugin) { //add plugin's model and controller folders as Loader paths here Loader::addPath(THINKUP_WEBAPP_PATH . 'plugins/' . $active_plugin->folder_name . "/model/"); Loader::addPath(THINKUP_WEBAPP_PATH . 'plugins/' . $active_plugin->folder_name . "/controller/"); //require the main plugin registration file here if (file_exists(THINKUP_WEBAPP_PATH . 'plugins/' . $active_plugin->folder_name . "/controller/" . $active_plugin->folder_name . ".php")) { require_once THINKUP_WEBAPP_PATH . 'plugins/' . $active_plugin->folder_name . "/controller/" . $active_plugin->folder_name . ".php"; } } } } }
/** * Initalize app * Load config file and required plugins * @throws Exception */ private function initalizeApp() { if (get_class($this) != "InstallerController") { //Initialize config $config = Config::getInstance(); if ($config->getValue('timezone')) { date_default_timezone_set($config->getValue('timezone')); } if ($config->getValue('debug')) { ini_set("display_errors", 1); ini_set("error_reporting", E_ALL); } //Init plugins $pdao = DAOFactory::getDAO('PluginDAO'); $active_plugins = $pdao->getActivePlugins(); foreach ($active_plugins as $ap) { Utils::defineConstants(); //add plugin's model and controller folders as Loader paths here Loader::addPath(THINKUP_WEBAPP_PATH . 'plugins/' . $ap->folder_name . "/model/"); Loader::addPath(THINKUP_WEBAPP_PATH . 'plugins/' . $ap->folder_name . "/controller/"); //require the main plugin registration file here require_once THINKUP_WEBAPP_PATH . 'plugins/' . $ap->folder_name . "/controller/" . $ap->folder_name . ".php"; } } }
/** * Set up class properties etc. */ private function Setup() { // place for additional sets // e.g. $this->aConfig[ section_key ][ value_key ] = value $sAppConfigIni = DOCROOT . $this->oConfig->getValue(sprintf('applications.%s.config_file', $this->oRouter->getApplicationName())); $this->oConfig->loadIniFile($sAppConfigIni); $this->sLogsDirectory = $this->getConfig('General.Logs_directory', DOCROOT . 'logs/'); $this->sLogsDirectory .= date('Y-m-d') . '/'; // set main framework path $this->addPath('Lithium'); // set application path received from config file if ($sAppPath = $this->getConfig('General.App_path')) { $this->addPath($sAppPath); Loader::addPath(DOCROOT . $sAppPath); } // add path for external classes Loader::addPath(DOCROOT); // set language if ($sLanguage = $this->getConfig('Locale.Language')) { $this->sLanguage = $sLanguage; } Core_Model::setLithium($this); Core_Module::setLithium($this); Database_Driver::setLithium($this); // initialize router $this->oRouter->init(); View::setRouter($this->oRouter); Module_Sorter::setRouter($this->oRouter); Module_Pagination::setRouter($this->oRouter); }
/** * Add module name to autoloader * @param string $module * @return void */ private function setModule($module) { self::$module = $module; \Loader::addPath($module, "api/{$module}"); }
<?php /** * Front Controller */ define('APP_DIR', dirname(__DIR__)); define('APP_MODE_CLI', false); require APP_DIR . '/vendor/autoload.php'; $_response_send = new Deferred(function () { Response::sent() || Response::send(); }); // Load Classes Loader::addPath(APP_DIR . '/classes'); // Load options Options::loadPHP(APP_DIR . '/config.php'); // Temp directory define('TEMP_DIR', Options::get('cache.directory', sys_get_temp_dir())); // Caching strategy Cache::using(['files' => ['cache_dir' => TEMP_DIR]]); // Init Views View::using(new View\Twig(APP_DIR . '/templates', ['cache' => Options::get('cache.views', true) ? TEMP_DIR : false, 'auto_reload' => Options::get('debug', false)])); View::addGlobals(['BASE_URL' => rtrim(dirname($_SERVER['PHP_SELF']), '/') . '/', 'CACHEBUST' => Options::get('debug', false) ? '?v=' . time() : '']); // App bootstrap include APP_DIR . '/boot.php'; Event::trigger('app.run'); // Routes foreach (glob(APP_DIR . '/routes/*.php') as $routedef) { include $routedef; } Event::trigger('app.dispatch'); Route::dispatch();