Exemple #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getApplication();
     $table = $app->getHelperSet()->get('table');
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $rules = new RuleBook();
     $rules->load($this->conf->get('routes'), true);
     // foreach ($this->conf->get('routes') as $url => $params) {
     foreach ($rules->all() as $rule) {
         $template = $rule->getTemplate();
         $params = $rule->getInformation();
         $method = '*';
         $generator = '';
         if (isset($params['method'])) {
             $method = $params['method'];
             unset($params['method']);
         }
         if (isset($params['_generator'])) {
             $generator = $params['_generator'];
             unset($params['_generator']);
         }
         // json string clean up
         $info = str_replace(['":"', '","', '{"', '"}'], [': ', ', ', '', ''], json_encode($params, JSON_UNESCAPED_SLASHES));
         $table->addRow([$generator, strtolower($method), $template, $info]);
     }
     $table->render($output);
 }
Exemple #2
0
 public function testRuleIsSavedToRequest()
 {
     $req = new Request();
     $req->setMethod(Verb::GET);
     $req->setUri('/mypage');
     $rand = mt_rand();
     $rule = Rule::create('/mypage', ['random' => $rand], true);
     $this->rulebook->add($rule);
     $this->rulebook->matching($req, true);
     $this->assertEquals($rule, $req->getRule());
 }
Exemple #3
0
 /**
  * handle a request
  * @param Request $req
  * @param Response $res
  * @return boolean success
  */
 public function route(Request $req, Response $res)
 {
     $ok = false;
     $route = $this->rules->matching($req, true);
     if ($route) {
         // defaults
         $route = array_merge(['format' => 'html', 'base' => 'app/views', 'file' => '', 'action' => '', 'controller' => '', 'namespace' => $this->conf->get('app:namespace')], $route);
         if ($route['file']) {
             // file request
             $ok = $this->runFileRequest($route, $res);
         } else {
             // action request
             $ok = $this->runActionRequest($route, $req, $res);
         }
     }
     $this->setResponseContentType($res, $route['format']);
     return $ok;
 }
Exemple #4
0
namespace Fabrico\Runtime\Setup\Http;

use Efficio\Http\Request;
use Efficio\Http\Response;
use Efficio\Http\RuleBook;
use Efficio\Http\Status;
use Exception;
use Fabrico\Renderer;
use Fabrico\Runtime\Instance;
require 'vendor/autoload.php';
$app = Instance::create();
$conf = $app->getConfiguration();
$res = new Response();
$req = new Request();
$req->importFromGlobals();
$rules = new RuleBook();
$rules->load($conf->get('routes'), true);
$app->setRuleBook($rules);
$renderer = new Renderer();
$renderer->handlers($conf->get('app:views:renderers'));
$app->setRenderer($renderer);
try {
    if (!$app->route($req, $res)) {
        $res->setStatusCode(Status::NOT_FOUND);
        $res->setContentType(Response::HTML);
        $res->setContent(file_get_contents('public/404.html'));
    }
} catch (Exception $ex) {
    // reset headers in case something like a redirect header was set before
    // the exception was thrown. we don't want to send any of those, or
    // anything else other than a status code and the error page content