Skip to content

Commit 5640ecb

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: Change the order of code blocks in the configuration block We need to use AsEntityListener instead of AsDoctrineListener Update getContainerExtension() [FrameworkBundle] Add support for route attributes in kernel controller methods
2 parents 6c8a458 + 8d8c936 commit 5640ecb

File tree

3 files changed

+97
-41
lines changed

3 files changed

+97
-41
lines changed

bundles/extension.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ method to return the instance of the extension::
5454

5555
// ...
5656
use Acme\HelloBundle\DependencyInjection\UnconventionalExtensionClass;
57+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
5758

5859
class AcmeHelloBundle extends Bundle
5960
{
60-
public function getContainerExtension()
61+
public function getContainerExtension(): ?ExtensionInterface
6162
{
6263
return new UnconventionalExtensionClass();
6364
}

configuration/micro_kernel_trait.rst

Lines changed: 91 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,55 +20,109 @@ via Composer:
2020
symfony/http-foundation symfony/routing \
2121
symfony/dependency-injection symfony/framework-bundle
2222
23-
Next, create an ``index.php`` file that defines the kernel class and runs it::
23+
Next, create an ``index.php`` file that defines the kernel class and runs it:
2424

25-
// index.php
26-
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
27-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
28-
use Symfony\Component\HttpFoundation\JsonResponse;
29-
use Symfony\Component\HttpFoundation\Request;
30-
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
31-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
25+
.. configuration-block::
3226

33-
require __DIR__.'/vendor/autoload.php';
27+
.. code-block:: php-attributes
3428
35-
class Kernel extends BaseKernel
36-
{
37-
use MicroKernelTrait;
29+
// index.php
30+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
31+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
32+
use Symfony\Component\HttpFoundation\JsonResponse;
33+
use Symfony\Component\HttpFoundation\Request;
34+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
35+
use Symfony\Component\Routing\Annotation\Route;
3836
39-
public function registerBundles(): array
40-
{
41-
return [
42-
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
43-
];
44-
}
37+
require __DIR__.'/vendor/autoload.php';
4538
46-
protected function configureContainer(ContainerConfigurator $c): void
39+
class Kernel extends BaseKernel
4740
{
48-
// PHP equivalent of config/packages/framework.yaml
49-
$c->extension('framework', [
50-
'secret' => 'S0ME_SECRET'
51-
]);
52-
}
41+
use MicroKernelTrait;
5342
54-
protected function configureRoutes(RoutingConfigurator $routes): void
55-
{
56-
$routes->add('random_number', '/random/{limit}')->controller([$this, 'randomNumber']);
43+
public function registerBundles(): array
44+
{
45+
return [
46+
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
47+
];
48+
}
49+
50+
protected function configureContainer(ContainerConfigurator $c): void
51+
{
52+
// PHP equivalent of config/packages/framework.yaml
53+
$c->extension('framework', [
54+
'secret' => 'S0ME_SECRET'
55+
]);
56+
}
57+
58+
#[Route('/random/{limit}', name='random_number')]
59+
public function randomNumber(int $limit): JsonResponse
60+
{
61+
return new JsonResponse([
62+
'number' => random_int(0, $limit),
63+
]);
64+
}
5765
}
5866
59-
public function randomNumber(int $limit): JsonResponse
67+
$kernel = new Kernel('dev', true);
68+
$request = Request::createFromGlobals();
69+
$response = $kernel->handle($request);
70+
$response->send();
71+
$kernel->terminate($request, $response);
72+
73+
.. code-block:: php
74+
75+
// index.php
76+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
77+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
78+
use Symfony\Component\HttpFoundation\JsonResponse;
79+
use Symfony\Component\HttpFoundation\Request;
80+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
81+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
82+
83+
require __DIR__.'/vendor/autoload.php';
84+
85+
class Kernel extends BaseKernel
6086
{
61-
return new JsonResponse([
62-
'number' => random_int(0, $limit),
63-
]);
87+
use MicroKernelTrait;
88+
89+
public function registerBundles(): array
90+
{
91+
return [
92+
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
93+
];
94+
}
95+
96+
protected function configureContainer(ContainerConfigurator $c): void
97+
{
98+
// PHP equivalent of config/packages/framework.yaml
99+
$c->extension('framework', [
100+
'secret' => 'S0ME_SECRET'
101+
]);
102+
}
103+
104+
protected function configureRoutes(RoutingConfigurator $routes): void
105+
{
106+
$routes->add('random_number', '/random/{limit}')->controller([$this, 'randomNumber']);
107+
}
108+
109+
public function randomNumber(int $limit): JsonResponse
110+
{
111+
return new JsonResponse([
112+
'number' => random_int(0, $limit),
113+
]);
114+
}
64115
}
65-
}
66116
67-
$kernel = new Kernel('dev', true);
68-
$request = Request::createFromGlobals();
69-
$response = $kernel->handle($request);
70-
$response->send();
71-
$kernel->terminate($request, $response);
117+
$kernel = new Kernel('dev', true);
118+
$request = Request::createFromGlobals();
119+
$response = $kernel->handle($request);
120+
$response->send();
121+
$kernel->terminate($request, $response);
122+
123+
.. versionadded:: 6.1
124+
125+
The PHP attributes notation has been introduced in Symfony 6.1.
72126

73127
That's it! To test it, start the :doc:`Symfony Local Web Server
74128
</setup/symfony_server>`:

doctrine/events.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ First, define a PHP class that handles the ``postUpdate`` Doctrine event::
255255
}
256256
}
257257

258-
Then, add the ``#[AsDoctrineListener]`` attribute to the class to enable it as
258+
Then, add the ``#[AsEntityListener]`` attribute to the class to enable it as
259259
a Doctrine entity listener in your application:
260260

261261
.. code-block:: php
@@ -265,9 +265,10 @@ a Doctrine entity listener in your application:
265265
266266
// ...
267267
use App\Entity\User;
268-
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
268+
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
269+
use Doctrine\ORM\Events;
269270
270-
#[AsDoctrineListener(event: 'postUpdate', method: 'postUpdate', entity: User::class)]
271+
#[AsEntityListener(event: Events::postUpdate, method: 'postUpdate', entity: User::class)]
271272
class UserChangedNotifier
272273
{
273274
// ...

0 commit comments

Comments
 (0)