예제 #1
0
파일: Router.php 프로젝트: hmc-soft/mvc
 public static function init($config)
 {
     $hooks = Hooks::get();
     if (isset($config['STATIC'])) {
         foreach ($config['STATIC'] as $stat_r) {
             self::$static_routes[] = $stat_r;
         }
     }
     if (isset($config['ROUTES'])) {
         //Routes defined in the config file.
         Router::parseConfig($config['ROUTES']);
     }
     if (isset($config['HOOKS']) && isset($config['HOOKS']['ROUTES'])) {
         //These call a function on the controller to setup the routes.
         //This is the preferred method for projects with a large number of routes.
         foreach ($config['HOOKS']['ROUTES'] as $route) {
             Hooks::addHook('routes', $route);
         }
     }
     $hooks->run('routes');
 }
예제 #2
0
파일: index.php 프로젝트: hmc-soft/mvc
} else {
    echo "<h1>Please install via composer.json</h1>";
    echo "<p>Install Composer instructions: <a href='https://getcomposer.org/doc/00-intro.md#globally'>https://getcomposer.org/doc/00-intro.md#globally</a></p>";
    echo "<p>Once composer is installed navigate to the working directory in your terminal/command promt and enter 'composer install'</p>";
    exit;
}
use HMC\Config;
use HMC\Hooks;
use HMC\Router;
use HMC\View;
//Routes are defined in the config file.
$configFile = '.app_config.json';
//initiate config
Hooks::run('init');
$configFile = Hooks::run('pre-config', $configFile);
$config = Config::init($configFile);
Hooks::run('config-ready');
Hooks::addHook('headers', 'addNotice');
//Initialize Router
Router::init($config);
//if no route found
//Router::error('Core\Error@index');
//To route with the url/Controller/Method/args schema uncomment this.
Router::$fallback = true;
Hooks::run('pre-dispatch');
//execute matched routes
Router::dispatch();
function addNotice()
{
    View::addHeader('X-Uses: HMC-soft MVC');
}