Más contenido relacionado La actualidad más candente (20) Similar a HTTP Middlewares in PHP by Eugene Dounar (20) HTTP Middlewares in PHP by Eugene Dounar7. find src -name '*.php' |
grep -iv tests |
cut -f2- -d/ |
cut -f1 -d. |
awk '{ print length, $0 }' |
sort -n |
tr / ;
15. RFC 3875
The Common Gateway Interface (CGI) [22] allows an HTTP [1], [4] server
and a CGI script to share responsibility for responding to client requests.
17. GET / HTTP/1.1
Host: igor.io
Accept: */*
REQUEST_METHOD = GET
PATH_INFO = /
HTTP_HOST = igor.io
HTTP_ACCEPT = */*
SERVER_NAME = igor.io
24. app = lambda do |env|
body = "Hello, World!"
[200, {
"Content-Type" => "text/plain",
"Content-Length" => body.length.to_s
}, [body]]end
run app
28. php_sapi_name()
➔ aolserver
➔ apache
➔ apache2filter
➔ apache2handler
➔ caudium
➔ cgi (until PHP 5.3)
➔ cgi-fcgi
➔ cli
➔ continuity
➔ embed
➔ isapi
➔ litespeed
➔ milter
➔ nsapi
➔ phttpd
➔ pi3web
➔ roxen
➔ thttpd
➔ tux
➔ webjames
41. <?php$app = new CallableHttpKernel(function ($request) {
return new Response('Hello World!');});
42. class Logger implements HttpKernelInterface{
private $app;
private $logger;
public function __construct(HttpKernelInterface $app, LoggerInterface $logger)
{
$this->app = $app;
$this->logger = $logger;
}
public function handle(Request $request, ...)
{
$response = $this->app->handle($request, $type, $catch);
$this->log($request, $response);
return $response;
}
private function log(Request $request, Response $response)
{
...
}}
43. $app = new Logger(
$app,
new MonologLogger());
47. class Foo implements HttpKernelInterface{
private $app;
public function __construct(HttpKernelInterface $app)
{
$this->app = $app;
}
public function handle(Request $request, ...)
{
$response = $this->app->handle($request, $type, $catch);
return $response;
}}
49. $blog = new SilexApplication();$blog->get('/',
function () {
return 'This is the blog!';});$app = new
StackUrlMap($app, [
'/blog' => $blog,]);
UrlMap
50. $app = new CallableHttpKernel(function ($request) {
$session = $request->getSession();
...});$app = new StackSession($app);
Session
51. $app = new IgorwStackOAuth($app, [
'key'=> 'foo',
'secret'=> 'bar',
'callback_url' => 'http://localhost:8080/auth/verify',
'success_url'=> '/',
'failure_url'=> '/auth',]);$app = new StackSession($app);
OAuth
54. $stack = (new StackBuilder())
->push('StackSession')
->push('IgorwStackOAuth', [...])
->push('Foo');$app = $stack->resolve($app);