mirror of
https://github.com/symfony/symfony-docs.git
synced 2026-03-24 00:32:14 +01:00
Update Create Framework tutorial
This commit is contained in:
committed by
Javier Eguiluz
parent
8b20cc8946
commit
56b6e317bb
@@ -10,7 +10,6 @@ to it::
|
||||
namespace Simplex;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel;
|
||||
use Symfony\Component\Routing;
|
||||
@@ -199,6 +198,7 @@ Now, here is how you can register a custom listener in the front controller::
|
||||
|
||||
// ...
|
||||
use Simplex\StringResponseListener;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
$container->register('listener.string_response', StringResponseListener::class);
|
||||
$container->getDefinition('dispatcher')
|
||||
|
||||
@@ -121,7 +121,7 @@ the registration of a listener for the ``response`` event::
|
||||
$response = $event->getResponse();
|
||||
|
||||
if ($response->isRedirection()
|
||||
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|
||||
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
|
||||
|| 'html' !== $event->getRequest()->getRequestFormat()
|
||||
) {
|
||||
return;
|
||||
@@ -200,7 +200,7 @@ Let's refactor the code a bit by moving the Google listener to its own class::
|
||||
$response = $event->getResponse();
|
||||
|
||||
if ($response->isRedirection()
|
||||
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|
||||
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
|
||||
|| 'html' !== $event->getRequest()->getRequestFormat()
|
||||
) {
|
||||
return;
|
||||
|
||||
@@ -189,7 +189,7 @@ fingertips thanks to a nice and simple API::
|
||||
// retrieves a COOKIE value
|
||||
$request->cookies->get('PHPSESSID');
|
||||
|
||||
// retrieves a HTTP request header, with normalized, lowercase keys
|
||||
// retrieves an HTTP request header, with normalized, lowercase keys
|
||||
$request->headers->get('host');
|
||||
$request->headers->get('content-type');
|
||||
|
||||
|
||||
@@ -165,15 +165,6 @@ Let's conclude with the new version of our framework::
|
||||
use Symfony\Component\HttpKernel;
|
||||
use Symfony\Component\Routing;
|
||||
|
||||
function render_template(Request $request): Response
|
||||
{
|
||||
extract($request->attributes->all(), EXTR_SKIP);
|
||||
ob_start();
|
||||
include sprintf(__DIR__.'/../src/pages/%s.php', $_route);
|
||||
|
||||
return new Response(ob_get_clean());
|
||||
}
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
$routes = include __DIR__.'/../src/app.php';
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ And the new front controller::
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel;
|
||||
use Symfony\Component\Routing;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user