コード例 #1
0
ファイル: Routing.php プロジェクト: bulton-fr/bfw-fastroute
 public function detectUri()
 {
     $returnObj = new \stdClass();
     $returnObj->fileArbo = '';
     $returnObj->nameCtr = '';
     $returnObj->nameMethode = '';
     $httpMethod = $_SERVER['REQUEST_METHOD'];
     $uriParse = parse_url($_SERVER['REQUEST_URI']);
     $request = rawurldecode($uriParse['path']);
     $routes = (require path . 'configs/bfw-fastroute/routes.php');
     $dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $router) use($routes) {
         foreach ($routes as $slug => $infos) {
             $slug = trim($slug);
             $method = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'];
             if (isset($infos['httpMethod'])) {
                 $method = $infos['httpMethod'];
             }
             $handler = $infos;
             unset($handler['httpMethod']);
             $router->addRoute($method, $slug, $handler);
         }
     });
     if ($request === '') {
         $request = '/';
     }
     $routeInfo = $dispatcher->dispatch($httpMethod, $request);
     $routeStatus = $routeInfo[0];
     $routeError = 0;
     if ($routeStatus === FastRoute\Dispatcher::METHOD_NOT_ALLOWED) {
         $routeError = 405;
     }
     if ($routeStatus !== FastRoute\Dispatcher::FOUND) {
         $routeError = 404;
     }
     if ($routeError !== 0) {
         ErrorView($routeError, true);
         //exit doing in ErrorView
     }
     $fastRouteCallback = $this->config->routeCallback;
     if (isset($fastRouteCallback) && is_callable($fastRouteCallback)) {
         $fastRouteCallback($returnObj, $routeInfo[1]);
     }
     $this->getArgs = $routeInfo[2];
     return $returnObj;
 }
コード例 #2
0
<?php

/**
 * Actions à effectuer lors de l'initialisation du module par le framework.
 * @author Vermeulen Maxime <*****@*****.**>
 * @package bfw-controller
 * @version 1.0
 */
require_once $rootPath . 'configs/bfw-controller/config.php';
$page_title = '';
$Ctr = new \BFWCtr\Controller();
$Ctr->setDefaultPage($ctr_defaultMethode);
//La page
if (file_exists($rootPath . 'controllers/' . $Ctr->getFileArbo() . '.php') && !$ctr_class) {
    require_once $rootPath . 'controllers/' . $Ctr->getFileArbo() . '.php';
} elseif ($ctr_class) {
    if (method_exists('\\controller\\' . $Ctr->getNameCtr(), $Ctr->getMethode()) && $ctr_class) {
        $ctrName = '\\controller\\' . $Ctr->getNameCtr();
        $methodeName = $Ctr->getMethode();
        call_user_func(array($ctrName, $methodeName));
    } elseif (method_exists('\\controller\\index', $Ctr->getMethode()) && $ctr_class) {
        call_user_func(array('\\controller\\index', $Ctr->getMethode()));
    } else {
        ErrorView(404);
    }
} else {
    ErrorView(404, false);
}