Skip to content
Snippets Groups Projects
Commit f847f681 authored by Ray Andrew's avatar Ray Andrew
Browse files

add autoload namespace for elegant require file

parent cb55106d
1 merge request!1add autoload namespace for elegant require file
<?php
session_start();
define("MOTAFW", true);
define("APPDIR", __DIR__ . '/app/');
define("PUBLICDIR", '/public/');
define("CSS", PUBLICDIR . 'css/');
define("JS", PUBLICDIR . 'js/');
define("IMG", PUBLICDIR . 'img/');
require_once __DIR__ . '/vendor/autoload.php';
use \MotaRaido\Core\Route;
$route = new Route();
// include all routes
$dir = new RecursiveDirectoryIterator(APPDIR);
$iter = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($iter, '/^.+\.routes\.php$/', RecursiveRegexIterator::GET_MATCH); // an Iterator, not an array
foreach ( $files as $file ) {
foreach($file as $route_file) {
require_once $route_file;
}
}
$route->dispatch();
<?php
spl_autoload_register(function ($class) {
$prefix = 'MotaRaido\\';
$base_dir = APPDIR;
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment