示例#1
0
文件: Swf.php 项目: slaxweb/bootstrap
 public function routeRequest()
 {
     Hooks::call("bootstrap.before.route");
     require_once APPPATH . "config/routes.php";
     try {
         $route = $this->_router->process();
     } catch (RouteNotFoundException $e) {
         if (Hooks::call("bootstrap.before.noroute") === true) {
             return;
         }
         if (function_exists("show404")) {
             call_user_func_array("show404", [$e->getRequest()]);
         } else {
             echo "No route found for following request: {$e->getRequest()}";
         }
         return;
     }
     if (Hooks::call("bootstrap.before.controller", $route["action"]) === true) {
         return;
     }
     if (is_object($route["action"]) && $route["action"] instanceof \Closure) {
         call_user_func_array($route["action"], $route["params"]);
     } else {
         $controller = Registry::setAlias("controller", "{$route["action"][0]}");
         $controller->{$route["action"][1]}(...$route["params"]);
     }
     Hooks::call("bootstrap.after.route");
 }
示例#2
0
// Define APPPATH constant pointing to Application directory
define("APPPATH", FCPATH . "../{$appDir}/");
// define PUBPATH constant pointing to Public directory
define("PUBPATH", FCPATH . "../{$pubDir}/");
// define VENPATH constant pointing to the Vendor directory
define("VENPATH", FCPATH . "../{$venDir}/");
// define TEMPLATEPATH constant pointing to the Templates directory
define("TEMPLATEPATH", APPPATH . "/Template/View");
// define TWIGCACHE constant pointing to the Twig Cache directory
define("TWIGCACHE", APPPATH . "/Template/Cache");
/**
 * Load the config
 */
require_once APPPATH . "config/config.php";
/**
 * Load the system Composer Autoloader
 */
$loader = (require_once FCPATH . "../vendor/autoload.php");
// add autoloader and router to Registry
\SlaxWeb\Registry\Container::addAlias("loader", $loader);
\SlaxWeb\Registry\Container::addAlias("router", \SlaxWeb\Router\Factory::init());
// load the hooks
require_once APPPATH . "config/hooks.php";
/**
 * Lets begin. Load and start the bootstraper
 */
$swf = new \SlaxWeb\Bootstrap\Swf($loader, \SlaxWeb\Registry\Container::get("router"));
// Add some stuff to the Autoloader
$swf->configureAutoload();
// Route the request
$swf->routeRequest();