Ejemplo n.º 1
0
 public function call(Server\Request $req = null, Server\Error $err = null)
 {
     $this->d('CALL - DUMP: ', $this->dump());
     $res = parent::call($req, $err);
     $res->write($this->config->get('uri', $req->uri));
     return $res;
 }
Ejemplo n.º 2
0
 public function call(Server\Request $req = null, Server\Error $err = null)
 {
     d('CALLING NEWS/SEARCH (#3)');
     $res = parent::call($req, $err);
     // $res->write('<p>URI: '.$req->uri.'</p>');
     return $res;
 }
 public function call(Server\Request $req = null, Server\Error $err = null)
 {
     $res = parent::call($req, $err);
     // $res->write('gzip:');
     $res->body = '<pre style="border: 3px solid #f00; padding: 1em;">compressed: ' . $res->body . '</pre>';
     return $res;
 }
Ejemplo n.º 4
0
 public function __construct(Server\LayerInterface $next, array $config = [], array $env = [])
 {
     parent::__construct($next, $config, $env);
     $this->map(array('pattern' => '*', 'fn' => function ($req, $res) {
         // d('info');
         return '<h1>Info</h1>';
     }));
 }
Ejemplo n.º 5
0
<?php

putenv('DEBUG=1');
require __DIR__ . '/../vendor/autoload.php';
class BodyWriterMiddleware extends Server\Layer
{
    public function call(Server\Request $req = null, Server\Error $err = null)
    {
        $res = parent::call($req, $err);
        $res->write($this->config['body'] ? $this->config['body'] : 'test-layer');
        return $res;
    }
}
$stack = new Server\Module();
$stack->employ(array('pattern' => '/foo*', 'class' => 'BodyWriterMiddleware', 'config' => array('body' => 'foo')));
$stack->employ(array('pattern' => '/bar*', 'class' => 'BodyWriterMiddleware', 'config' => array('body' => 'bar')));
$req = new Server\Request('GET', '/foo');
$res = $stack->call($req);
$res->send();
Ejemplo n.º 6
0
<?php

putenv('DEBUG=1');
require __DIR__ . '/../vendor/autoload.php';
class TestController extends Server\Controller
{
    public function index()
    {
        $this->res->write('test');
    }
    public function writeByReturn()
    {
        return 'test';
    }
    public function returnData()
    {
        return array('test' => 'test');
    }
}
$module = new Server\Module();
$module->map(['pattern' => '*', 'controller' => 'TestController']);
$res = $module->call();
$res->send();
<?php

putenv('DEBUG=1');
require __DIR__ . '/../vendor/autoload.php';
class HeaderFilter extends Server\Layer
{
    public function call(Server\Request $req = null, Server\Error $err = null)
    {
        $res = parent::call($req, $err);
        $res->body = '<h1>' . $res->body . '</h1>';
        return $res;
    }
}
class FrontController extends Server\Controller
{
    public function index()
    {
        return 'Hello, world!';
    }
}
$app = new Server\Module();
$app->employ(['class' => 'HeaderFilter']);
$app->map(['controller' => 'FrontController']);
$app->call()->send();
// outputs: <h1>Hello, world!</h1>