/** * @param string $file Est le nom de la class sans son extension .class.php, qui doit être inclus * @return string */ public static function findDir($file) { Autoloader::$directory = ['application', 'models', 'views', 'controllers']; foreach (Autoloader::$directory as $dir) { $extension = ".class.php"; $path = realpath($dir . "/" . $file . $extension); if ($path) { return Autoloader::$pathClass = $path; } } }
/** * Registers own autoloader the SPL autoloader stack. * @param string $directory * @return boolean Returns true if registration was successful, false otherwise. */ public static function register($directory) { self::$directory = $directory; // as spl_autoload_register() disables __autoload() and // this behavior might be unwanted, we put it onto autoload stack if (function_exists('__autoload')) { spl_autoload_register('__autoload'); } // Registers own loader function conforming // https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md return spl_autoload_register(function ($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require Autoloader::$directory . $fileName; }); }
date_default_timezone_set(Config::app('timezone', 'UTC')); /* * Define the application error reporting level based on your environment */ switch (constant('ENV')) { case 'dev': ini_set('display_errors', true); error_reporting(-1); break; default: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); } /* * Set autoload directories to include your app models and libraries */ Autoloader::directory(array(APP . 'models', APP . 'libraries')); /** * Helpers */ require APP . 'helpers' . EXT; /** * Anchor setup */ Anchor::setup(); /** * Import defined routes */ if (is_admin()) { require APP . 'routes/admin' . EXT; require APP . 'routes/categories' . EXT; require APP . 'routes/comments' . EXT;
$pool = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 1); $value = ''; for ($i = 0; $i < $length; $i++) { $value .= $pool[mt_rand(0, 61)]; } return $value; } /* Include some files. */ require PATH . 'system/classes/autoload.php'; require PATH . 'system/classes/helpers.php'; // map classes Autoloader::map(array('Schema' => PATH . 'upgrade/classes/schema.php', 'Migrations' => PATH . 'upgrade/classes/migrations.php')); // tell the autoloader where to find classes Autoloader::directory(array(PATH . 'system/classes/')); // register the auto loader Autoloader::register(); /** Report all errors let our error class decide which to display */ error_reporting(-1); /** Error display will be handled by our error class */ ini_safe_set('display_errors', false); // Register the default timezone for the application. date_default_timezone_set(Config::get('application.timezone')); // Register the PHP exception handler. set_exception_handler(array('Error', 'exception')); // Register the PHP error handler.
} /** Magic Quotes Fix note: magic quotes is deprecated in PHP 5.3 src: php.net/manual/en/security.magicquotes.disabling.php */ if (magic_quotes()) { $magics = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); foreach ($magics as &$magic) { $magic = array_strip_slashes($magic); } } // get our autoloader require PATH . 'system/core/autoload.php'; // tell the autoloader where to find classes Autoloader::directory(array(PATH . 'system/core/', PATH . 'system/library/')); // register the auto loader Autoloader::register(); /** Report all errors let our error class decide which to display */ error_reporting(-1); /** Error display will be handled by our error class */ ini_safe_set('display_errors', false); /** Check our installation */ if (Config::load(PATH . 'config.php') === false) { // looks like we are missing a config file
date_default_timezone_set(Config::app('timezone', 'UTC')); /* * Define the application error reporting level based on your environment */ switch (constant('ENV')) { case 'dev': ini_set('display_errors', true); error_reporting(-1); break; default: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); } /* * Set autoload directories to include your app models and libraries */ Autoloader::directory(array(APP . 'models', APP . 'libraries', PATH . 'anchor/libraries')); /** * Set the current uri from get */ if ($route = Arr::get($_GET, 'route', '/')) { Uri::$current = trim($route, '/') ?: '/'; } /* Helper functions */ function timezones() { $list = DateTimeZone::listIdentifiers(); $data = array(); foreach ($list as $id => $zone) { $now = new DateTime(null, new DateTimeZone($zone));