Example #1
0
 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");
 }
Example #2
0
<?php

use SlaxWeb\Hooks\Hooks;
/**
 * Example hook
 */
Hooks::set(["name" => "Hook name", "class" => "\\Hooks\\Sample"]);