From 56b6e317bbccd05c663e082af0c1a39d1b71819c Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Thu, 1 May 2025 13:41:26 +0200 Subject: [PATCH] Update Create Framework tutorial --- create_framework/dependency_injection.rst | 2 +- create_framework/event_dispatcher.rst | 4 ++-- create_framework/http_foundation.rst | 2 +- create_framework/http_kernel_controller_resolver.rst | 9 --------- create_framework/http_kernel_httpkernel_class.rst | 1 - 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/create_framework/dependency_injection.rst b/create_framework/dependency_injection.rst index de3c4e11e4e..59b1275fcd4 100644 --- a/create_framework/dependency_injection.rst +++ b/create_framework/dependency_injection.rst @@ -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') diff --git a/create_framework/event_dispatcher.rst b/create_framework/event_dispatcher.rst index 650e4c7554e..9a3a48942ac 100644 --- a/create_framework/event_dispatcher.rst +++ b/create_framework/event_dispatcher.rst @@ -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; diff --git a/create_framework/http_foundation.rst b/create_framework/http_foundation.rst index 219119164b4..71146b1785c 100644 --- a/create_framework/http_foundation.rst +++ b/create_framework/http_foundation.rst @@ -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'); diff --git a/create_framework/http_kernel_controller_resolver.rst b/create_framework/http_kernel_controller_resolver.rst index 1c2857c9ed9..6c7e469da27 100644 --- a/create_framework/http_kernel_controller_resolver.rst +++ b/create_framework/http_kernel_controller_resolver.rst @@ -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'; diff --git a/create_framework/http_kernel_httpkernel_class.rst b/create_framework/http_kernel_httpkernel_class.rst index fa673f9ba57..05d9ad6d93e 100644 --- a/create_framework/http_kernel_httpkernel_class.rst +++ b/create_framework/http_kernel_httpkernel_class.rst @@ -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;