예제 #1
0
 protected function applyMessageConstraints(RouteHandler $handler) : RouteHandler
 {
     $ref = $handler->getReflection();
     foreach ($ref->getParameters() as $param) {
         $type = $param->getClass();
         if (!$type) {
             continue;
         }
         foreach ($this->readers as $reader) {
             if ($reader->isSupported($type)) {
                 $handler->consumes(...$reader->getAcceptedTypes());
             }
         }
     }
     if ($ref->hasReturnType()) {
         $type = (string) $ref->getReturnType();
         foreach ($this->writers as $writer) {
             if ($writer->isSupported($type)) {
                 $handler->produces(...$writer->getProducedTypes());
             }
         }
     }
     return $handler;
 }
예제 #2
0
 /**
  * Tell the routeHandler to exit the execution after the controller is executed
  */
 public function end()
 {
     $this->routeHandler->fastExit();
 }
예제 #3
0
<?php

require_once __DIR__ . '/../lib/RouteHandler.php';
$route = $_GET['__route__'];
if (trim($route) !== '/') {
    $command = RouteHandler::unpack($route);
    //@todo validate commands against what's available in database
    //@todo instantiate command through factory
    switch ($command['section']) {
        case 'cmd':
            require_once __DIR__ . "/../modules/{$command['module']}/controller.php";
            //@todo to be replaced with autoloader and factory
            break;
        default:
            print 'No such option available';
    }
} else {
    print 'Welcome to CodMarsh';
}
예제 #4
0
 /**
  * Handle request
  *
  * @param string $httpMethod
  * @param string $uri
  * @return mixed
  */
 public function handle($httpMethod, $uri)
 {
     $matcher = new RouteMatcher($this->generator->getData(), $this->handler);
     $this->currentRoute = $route = $matcher->match($httpMethod, $uri);
     return $this->handler->handleRoute($route);
 }