public function testCreateFromGlobals() { $_REQUEST['a'] = 1; $old = $_SERVER; $_SERVER['REQUEST_URI'] = '/index.php'; $_SERVER['HTTP_HOST'] = 'awesome-host.com'; $_SERVER['REQUEST_METHOD'] = 'POST'; $requests = Request::createFromGlobals(); $this->assertEquals($_SERVER['HTTP_HOST'], $requests->getHost()); $this->assertEquals('/index.php', $requests->getPath()); $this->assertEquals('1', $requests->getParam('a')); $this->assertEquals($_SERVER['REQUEST_METHOD'], $requests->getMethod()); $_SERVER = $old; }
<?php require_once '../vendor/autoload.php'; session_start(); function h($value) { return htmlspecialchars($value); } $builder = new \DI\ContainerBuilder(); $builder->useAnnotations(true); $builder->addDefinitions('../config/config.php'); $router = new \Vtk13\Mvc\Handlers\ControllerRouter($builder->build(), 'Vtk13\\Cc\\Controller\\', '/', 'index'); $response = $router->handle(\Vtk13\Mvc\Http\Request::createFromGlobals()); if (!headers_sent()) { header($response->getStatusLine()); foreach ($response->getHeaders() as $name => $value) { header("{$name}: {$value}"); } echo $response->getBody(); }
<?php use Vtk13\Mvc\Handlers\ControllerRouter; use Vtk13\Mvc\Http\Request; use Vtk13\TraceView\Registry; require_once '../vendor/autoload.php'; ini_set('include_path', '..:' . ini_get('include_path')); if ($config = stream_resolve_include_path('config.php')) { include $config; } else { define('TRACEVIEW_MYSQL', false); } $router = new ControllerRouter('Vtk13\\TraceView\\Controllers\\'); $response = $router->handle(Request::createFromGlobals()); header($response->getStatusLine()); foreach ($response->getHeaders() as $name => $content) { header($name . ': ' . $content); } echo $response->getBody();