Skip to content

Commit b4846b8

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: Update http_client.rst [Routing] Add example of Requirement enum
2 parents 01203e9 + 7fe1d72 commit b4846b8

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

http_client.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,11 +2355,11 @@ First, use a browser or HTTP client to perform the HTTP request(s) you want to
23552355
test. Then, save that information as a ``.har`` file somewhere in your application::
23562356

23572357
// ExternalArticleServiceTest.php
2358-
use PHPUnit\Framework\TestCase;
2358+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
23592359
use Symfony\Component\HttpClient\MockHttpClient;
23602360
use Symfony\Component\HttpClient\Response\MockResponse;
23612361

2362-
final class ExternalArticleServiceTest extends TestCase
2362+
final class ExternalArticleServiceTest extends KernelTestCase
23632363
{
23642364
public function testSubmitData(): void
23652365
{

routing.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,51 @@ URL Route Parameters
649649
contains a collection of commonly used regular-expression constants such as
650650
digits, dates and UUIDs which can be used as route parameter requirements.
651651

652+
.. configuration-block::
653+
654+
.. code-block:: php-attributes
655+
656+
// src/Controller/BlogController.php
657+
namespace App\Controller;
658+
659+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
660+
use Symfony\Component\HttpFoundation\Response;
661+
use Symfony\Component\Routing\Attribute\Route;
662+
use Symfony\Component\Routing\Requirement\Requirement;
663+
664+
class BlogController extends AbstractController
665+
{
666+
#[Route('/blog/{page}', name: 'blog_list', requirements: ['page' => Requirement::DIGITS])]
667+
public function list(int $page): Response
668+
{
669+
// ...
670+
}
671+
}
672+
673+
.. code-block:: yaml
674+
675+
# config/routes.yaml
676+
blog_list:
677+
path: /blog/{page}
678+
controller: App\Controller\BlogController::list
679+
requirements:
680+
page: !php/const Symfony\Component\Routing\Requirement\Requirement::DIGITS
681+
682+
.. code-block:: php
683+
684+
// config/routes.php
685+
use App\Controller\BlogController;
686+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
687+
use Symfony\Component\Routing\Requirement\Requirement;
688+
689+
return static function (RoutingConfigurator $routes): void {
690+
$routes->add('blog_list', '/blog/{page}')
691+
->controller([BlogController::class, 'list'])
692+
->requirements(['page' => Requirement::DIGITS])
693+
;
694+
// ...
695+
};
696+
652697
.. tip::
653698

654699
Route requirements (and route paths too) can include

0 commit comments

Comments
 (0)