예제 #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
파일: Config.php 프로젝트: hmc-soft/mvc
 public static function init($configFile)
 {
     $opts = null;
     $apcEnabled = (bool) ini_get('apc.enabled');
     if ($apcEnabled && apc_exists('hmcsoftmvc-config')) {
         if (file_exists($configFile)) {
             $lastModTime = filemtime($configFile);
             $lastConfTime = 0;
             if (apc_exists('hmcsoftmvc-config-updated')) {
                 $lastConfTime = apc_fetch('hmcsoftmvc-config-updated');
             }
             if ($lastConfTime < $lastModTime) {
                 $opts = json_decode(file_get_contents($configFile), true);
                 apc_store('hmcsoftmvc-config', $opts);
                 apc_store('hmcsoftmvc-config-updated', $lastModTime);
             } else {
                 $opts = apc_fetch('hmcsoftmvc-config');
             }
         }
     } else {
         if (is_readable($configFile)) {
             $opts = json_decode(file_get_contents($configFile), true);
         }
     }
     $defaults = self::get_defaults();
     if ($opts !== null) {
         self::$options = (array) self::merge_defaults($defaults, (array) $opts);
     }
     self::$options = Hooks::run('config', self::$options);
     if (self::$options['SITE']['LANGUAGE'] == null) {
         //try to figure if we support the user's language.
         $userlangs = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
         $foundLang = false;
         foreach (self::$options['SITE']['LANGUAGES'] as $ourLang) {
             if (!$foundLang) {
                 foreach ($userlangs as $ulang) {
                     if (!$foundLang && $ulang === $ourLang) {
                         self::$options['SITE']['LANGUAGE'] = $ourLang;
                         $foundLang = true;
                     }
                 }
             }
         }
         if (!$foundLang) {
             self::$options['SITE']['LANGUAGE'] = self::$options['SITE']['DEFAULTLANG'];
         }
     }
     if (isset(self::$options['SITE'])) {
         if (isset(self::$options['ENVIRONMENT'])) {
             if (self::$options['SITE']['ENVIRONMENT'] == 'development') {
                 error_reporting(E_NONE);
             } else {
                 error_reporting(E_NONE);
             }
         }
         //set timezone
         if (isset(self::$options['SITE']['TIMEZONE'])) {
             date_default_timezone_set(self::$options['SITE']['TIMEZONE']);
         }
     }
     //turn on output buffering
     ob_start();
     //turn on custom error handling
     if (isset(self::$options['LOG'])) {
         \HMC\Logger::init(self::$options['LOG']);
         if (isset(self::$options['LOG']['EXCEPTIONS'])) {
             set_exception_handler(self::$options['LOG']['EXCEPTIONS']);
         } else {
             set_exception_handler('HMC\\Logger::exceptionHandler');
         }
         if (isset(self::$options['LOG']['ERRORS'])) {
             set_error_handler(self::$options['LOG']['ERRORS']);
         } else {
             set_error_handler('HMC\\Logger::errorHandler');
         }
     }
     //start sessions
     if (isset(self::$options['SESSION'])) {
         Session::init(self::$options['SESSION']);
     } else {
         Session::init();
     }
     return self::$options;
 }
예제 #3
0
파일: header.php 프로젝트: hmc-soft/mvc
<?php

use HMC\Config;
use HMC\Hooks;
?>
<!DOCTYPE html>
<html>
  <head>
    <title><?php 
echo $data['title'];
?>
 | <?php 
echo Config::SITE_TITLE();
?>
</title>
    <?php 
Hooks::run('meta');
Hooks::run('css');
//use Assets::css or combine_css to inject stylesheets
?>
  </head>
  <body>
예제 #4
0
파일: View.php 프로젝트: hmc-soft/mvc
 private static function init()
 {
     if (!headers_sent()) {
         \HMC\Hooks::run('headers');
     }
 }
예제 #5
0
파일: footer.php 프로젝트: hmc-soft/mvc
<?php

use HMC\Hooks;
Hooks::run('footer');
Hooks::run('afterBody');
Hooks::run('js');
//do js here
?>
</body>
</html>
예제 #6
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');
}