8000 Merge branch '4.4' · symfony/symfony@4a9926a · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a9926a

Browse files
Merge branch '4.4'
* 4.4: [Form][Validator][Intl] Fix tests [Messenger] return empty envelopes when RetryableException occurs [Intl] Excludes locale from language codes (split localized language names) [FrameworkBundle] WebTestCase KernelBrowser::getContainer null return type [Intl] Fix compile type errors [Validator] Accept underscores in the URL validator as the URL will resolve correctly [Translation] Collect original locale in case of fallback translation Add types to constructors and private/final/internal methods (Batch I) [HttpFoundation] optimize normalization of headers Replace REMOTE_ADDR in trusted proxies with the current REMOTE_ADDR [ErrorHandler] Forward \Throwable Fix toolbar load when GET params are present in "_wdt" route
2 parents 8f1c4f1 + 4acef47 commit 4a9926a

File tree

264 files changed

+2713
-2191
lines changed
  • ErrorHandler
  • ErrorRenderer
  • Form/Tests/Extension/Core/Type
  • HttpFoundation
  • HttpKernel
  • Intl
    Original file line numberDiff line numberDiff line change
    @@ -60,7 +60,7 @@ DependencyInjection
    6060
    ```php
    6161
    new Definition('%my_class%');
    6262
    ```
    63-
    63+
    6464
    DoctrineBridge
    6565
    --------------
    6666
    * Deprecated injecting `ClassMetadataFactory` in `DoctrineExtractor`, an instance of `EntityManagerInterface` should be
    @@ -96,7 +96,7 @@ FrameworkBundle
    9696
    * Deprecated `routing.loader.service`, use `routing.loader.container` instead.
    9797
    * Not tagging service route loaders with `routing.route_loader` has been deprecated.
    9898
    * Overriding the methods `KernelTestCase::tearDown()` and `WebTestCase::tearDown()` without the `void` return-type is deprecated.
    99-
    99+
    100100
    HttpClient
    101101
    ----------
    102102

    @@ -139,7 +139,7 @@ HttpKernel
    139139
    }
    140140
    ```
    141141

    142-
    As many bundles must be compatible with a range of Symfony versions, the current
    142+
    As many bundles must be compatible with a range of Symfony versions, the current
    143143
    directory convention is not deprecated yet, but it will be in the future.
    144144

    145145
    * Deprecated the second and third argument of `KernelInterface::locateResource`
    @@ -148,6 +148,7 @@ HttpKernel
    148148
    fallback directories. Resources like service definitions are usually loaded relative to the
    149149
    current directory or with a glob pattern. The fallback directories have never been advocated
    150150
    so you likely do not use those in any app based on the SF Standard or Flex edition.
    151+
    * Getting the container from a non-booted kernel is deprecated
    151152

    152153
    Lock
    153154
    ----
    @@ -171,7 +172,7 @@ MonologBridge
    171172
    --------------
    172173

    173174
    * The `RouteProcessor` has been marked final.
    174-
    175+
    175176
    Process
    176177
    -------
    177178

    @@ -195,14 +196,14 @@ Security
    195196
    * Implementations of `PasswordEncoderInterface` and `UserPasswordEncoderInterface` should add a new `needsRehash()` method
    196197
    * Deprecated returning a non-boolean value when implementing `Guard\AuthenticatorInterface::checkCredentials()`. Please explicitly return `false` to indicate invalid credentials.
    197198
    * Deprecated passing more than one attribute to `AccessDecisionManager::decide()` and `AuthorizationChecker::isGranted()` (and indirectly the `is_granted()` Twig and ExpressionLanguage function)
    198-
    199+
    199200
    **Before**
    200201
    ```php
    201202
    if ($this->authorizationChecker->isGranted(['ROLE_USER', 'ROLE_ADMIN'])) {
    202203
    // ...
    203204
    }
    204205
    ```
    205-
    206+
    206207
    **After**
    207208
    ```php
    208209
    if ($this->authorizationChecker->isGranted(new Expression("has_role('ROLE_USER') or has_role('ROLE_ADMIN')"))) {}
    @@ -230,18 +231,18 @@ TwigBridge
    230231
    * Deprecated to pass `$rootDir` and `$fileLinkFormatter` as 5th and 6th argument respectively to the
    231232
    `DebugCommand::__construct()` method, swap the variables position.
    232233
    * Deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
    233-
    234+
    234235
    TwigBundle
    235236
    ----------
    236237

    237238
    * Deprecated `twig.exception_controller` configuration option, set it to "null" and use `framework.error_controller` instead:
    238-
    239+
    239240
    Before:
    240241
    ```yaml
    241242
    twig:
    242243
    exception_controller: 'App\Controller\MyExceptionController'
    243244
    ```
    244-
    245+
    245246
    After:
    246247
    ```yaml
    247248
    twig:
    @@ -250,36 +251,36 @@ TwigBundle
    250251
    framework:
    251252
    error_controller: 'App\Controller\MyExceptionController'
    252253
    ```
    253-
    254-
    The new default exception controller will also change the error response content according to
    254+
    255+
    The new default exception controller will also change the error response content according to
    255256
    https://tools.ietf.org/html/rfc7807 for `json`, `xml`, `atom` and `txt` formats:
    256-
    257+
    257258
    Before:
    258259
    ```json
    259-
    {
    260-
    "error": {
    261-
    "code": 404,
    262-
    "message": "Sorry, the page you are looking for could not be found"
    263-
    }
    260+
    {
    261+
    "error": {
    262+
    "code": 404,
    263+
    "message": "Sorry, the page you are looking for could not be found"
    264+
    }
    264265
    }
    265266
    ```
    266-
    267+
    267268
    After:
    268269
    ```json
    269-
    {
    270+
    {
    270271
    "title": "Not Found",
    271-
    "status": 404,
    272+
    "status": 404,
    272273
    "detail": "Sorry, the page you are looking for could not be found"
    273274
    }
    274275
    ```
    275-
    276+
    276277
    * Deprecated the `ExceptionController` and `PreviewErrorController` controllers, use `ErrorController` from the HttpKernel component instead
    277278
    * Deprecated all built-in error templates, use the error renderer mechanism of the `ErrorRenderer` component
    278-
    * Deprecated loading custom error templates in non-html formats. Custom HTML error pages based on Twig keep working as before:
    279+
    * Deprecated loading custom error templates in non-html formats. Custom HTML error pages based on Twig keep working as before:
    279280

    280281
    Before (`templates/bundles/TwigBundle/Exception/error.jsonld.twig`):
    281282
    ```twig
    282-
    {
    283+
    {
    283284
    "@id": "https://example.com",
    284285
    "@type": "error",
    285286
    "@context": {
    @@ -289,7 +290,7 @@ TwigBundle
    289290
    }
    290291
    }
    291292
    ```
    292-
    293+
    293294
    After (`App\ErrorRenderer\JsonLdErrorRenderer`):
    294295
    ```php
    295296
    class JsonLdErrorRenderer implements ErrorRendererInterface
    @@ -298,7 +299,7 @@ TwigBundle
    298299
    {
    299300
    return 'jsonld';
    300301
    }
    301-
    302+
    302303
    public function render(FlattenException $exception): string
    303304
    {
    304305
    return json_encode([
    @@ -323,7 +324,7 @@ Validator
    323324
    * Deprecated using anything else than a `string` as the code of a `ConstraintViolation`, a `string` type-hint will
    324325
    be added to the constructor of the `ConstraintViolation` class and to the `ConstraintViolationBuilder::setCode()`
    325326
    method in 5.0.
    326-
    * Deprecated passing an `ExpressionLanguage` instance as the second argument of `ExpressionValidator::__construct()`.
    327+
    * Deprecated passing an `ExpressionLanguage` instance as the second argument of `ExpressionValidator::__construct()`.
    327328
    Pass it as the first argument instead.
    328329
    * The `Length` constraint expects the `allowEmptyString` option to be defined
    329330
    when the `min` option is used.
    @@ -343,7 +344,7 @@ WebServerBundle
    343344
    ---------------
    344345

    345346
    * The bundle is deprecated and will be removed in 5.0.
    346-
    347+
    347348
    Yaml
    348349
    ----
    349350

    Original file line numberDiff line numberDiff line change
    @@ -288,6 +288,7 @@ HttpFoundation
    288288
    use `Symfony\Component\Mime\FileinfoMimeTypeGuesser` instead.
    289289
    * `ApacheRequest` has been removed, use the `Request` class instead.
    290290
    * The third argument of the `HeaderBag::get()` method has been removed, use method `all()` instead.
    291+
    * Getting the container from a non-booted kernel is not possible anymore.
    291292

    292293
    HttpKernel
    293294
    ----------

    Original file line numberDiff line numberDiff line change
    @@ -174,10 +174,8 @@ protected function registerCommands()
    174174
    if ($bundle instanceof Bundle) {
    175175
    try {
    176176
    $bundle->registerCommands($this);
    177-
    } catch (\Exception $e) {
    178-
    $this->registrationErrors[] = $e;
    179177
    } catch (\Throwable $e) {
    180-
    $this->registrationErrors[] = new FatalThrowableError($e);
    178+
    $this->registrationErrors[] = $e;
    181179
    }
    182180
    }
    183181
    }
    @@ -192,10 +190,8 @@ protected function registerCommands()
    192190
    if (!isset($lazyCommandIds[$id])) {
    193191
    try {
    194192
    $this->add($container->get($id));
    195-
    } catch (\Exception $e) {
    196-
    $this->registrationErrors[] = $e;
    197193
    } catch (\Throwable $e) {
    198-
    $this->registrationErrors[] = new FatalThrowableError($e);
    194+
    $this->registrationErrors[] = $e;
    199195
    }
    200196
    }
    201197
    }
    @@ -211,6 +207,10 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
    211207
    (new SymfonyStyle($input, $output))->warning('Some commands could not be registered:');
    212208

    213209
    foreach ($this->registrationErrors as $error) {
    210+
    if (!$error instanceof \Exception) {
    211+
    $error = new FatalThrowableError($error);
    212+
    }
    213+
    214214
    $this->doRenderException($error, $output);
    215215
    }
    216216
    }

    Original file line numberDiff line numberDiff line change
    @@ -125,11 +125,15 @@ protected static function createKernel(array $options = [])
    125125
    protected static function ensureKernelShutdown()
    126126
    {
    127127
    if (null !== static::$kernel) {
    128-
    $container = static::$kernel->getContainer();
    129-
    static::$kernel->shutdown();
    130-
    static::$booted = false;
    131-
    if ($container instanceof ResetInterface) {
    132-
    $container->reset();
    128+
    $isBooted = (new \ReflectionClass(static::$kernel))->getProperty('booted');
    129+
    $isBooted->setAccessible(true);
    130+
    if ($isBooted->getValue(static::$kernel)) {
    131+
    $container = static::$kernel->getContainer();
    132+
    static::$kernel->shutdown();
    133+
    static::$booted = false;
    134+
    if ($container instanceof ResetInterface) {
    135+
    $container->reset();
    136+
    }
    133137
    }
    134138
    }
    135139
    static::$container = null;

    Original file line numberDiff line numberDiff line change
    @@ -14,6 +14,7 @@
    1414
    use Psr\Log\NullLogger;
    1515
    use Symfony\Component\Config\Loader\LoaderInterface;
    1616
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    17+
    use Symfony\Component\DependencyInjection\ContainerInterface;
    1718
    use Symfony\Component\Filesystem\Filesystem;
    1819
    use Symfony\Component\HttpKernel\Kernel;
    1920

    @@ -96,4 +97,13 @@ protected function getKernelParameters(): array
    9697

    9798
    return $parameters;
    9899
    }
    100+
    101+
    public function getContainer(): ContainerInterface
    102+
    {
    103+
    if (!$this->booted) {
    104+
    throw new \LogicException('Cannot access the container on a non-booted kernel. Did you f 1077E orget to boot it?');
    105+
    }
    106+
    107+
    return parent::getContainer();
    108+
    }
    99109
    }

    Original file line numberDiff line numberDiff line change
    @@ -12,6 +12,7 @@
    1212
    namespace Symfony\Bundle\SecurityBundle\Tests\Functional\app;
    1313

    1414
    use Symfony\Component\Config\Loader\LoaderInterface;
    15+
    use Symfony\Component\DependencyInjection\ContainerInterface;
    1516
    use Symfony\Component\Filesystem\Filesystem;
    1617
    use Symfony\Component\HttpKernel\Kernel;
    1718

    @@ -98,4 +99,13 @@ protected function getKernelParameters(): array
    9899

    99100
    return $parameters;
    100101
    }
    102+
    103+
    public function getContainer(): ContainerInterface
    104+
    {
    105+
    if (!$this->booted) {
    106+
    throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
    107+
    }
    108+
    109+
    return parent::getContainer();
    110+
    }
    101111
    }

    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,7 @@
    1313

    1414
    {% set text %}
    1515
    <div class="sf-toolbar-info-piece">
    16-
    <b>Locale</b>
    16+
    <b>Default locale</b>
    1717
    <span class="sf-toolbar-status">
    1818
    {{ collector.locale|default('-') }}
    1919
    </span>
    @@ -61,7 +61,7 @@
    6161
    <div class="metrics">
    6262
    <div class="metric">
    6363
    <span class="value">{{ collector.locale|default('-') }}</span>
    64-
    <span class="label">Locale</span>
    64+
    <span class="label">Default locale</span>
    6565
    </div>
    6666
    <div class="metric">
    6767
    <span class="value">{{ collector.fallbackLocales|join(', ')|default('-') }}</span>
    @@ -126,7 +126,7 @@
    126126
    </div>
    127127
    {% else %}
    128128
    {% block fallback_messages %}
    129-
    {{ helper.render_table(messages_fallback) }}
    129+
    {{ helper.render_table(messages_fallback, true) }}
    130130
    {% endblock %}
    131131
    {% endif %}
    132132
    </div>
    @@ -162,11 +162,14 @@
    162162

    163163
    {% endblock %}
    164164

    165-
    {% macro render_table(messages) %}
    165+
    {% macro render_table(messages, is_fallback) %}
    166166
    <table data-filters>
    167167
    <thead>
    168168
    <tr>
    169169
    <th data-filter="locale">Locale</th>
    170+
    {% if is_fallback %}
    171+
    <th>Fallback locale</th>
    172+
    {% endif %}
    170173
    <th data-filter="domain">Domain</th>
    171174
    <th>Times used</th>
    172175
    <th>Message ID</th>
    @@ -177,6 +180,9 @@
    177180
    {% for message in messages %}
    178181
    <tr data-filter-locale="{{ message.locale }}" data-filter-domain="{{ message.domain }}">
    179182
    <td class="font-normal text-small nowrap">{{ message.locale }}</td>
    183+
    {% if is_fallback %}
    184+
    <td class="font-normal text-small nowrap">{{ message.fallbackLocale|default('-') }}</td>
    185+
    {% endif %}
    180186
    <td class="font-normal text-small text-bold nowrap">{{ message.domain }}</td>
    181187
    <td class="font-normal text-small nowrap">{{ message.count }}</td>
    182188
    <td>
    Original file line numberDiff line numberDiff line change
    @@ -429,7 +429,7 @@
    429429
    newToken = (newToken || token);
    430430
    this.load(
    431431
    'sfwdt' + token,
    432-
    '{{ path("_wdt", { "token": "xxxxxx" }) }}'.replace(/xxxxxx/, newToken),
    432+
    '{{ path("_wdt", { "token": "xxxxxx" })|escape('js') }}'.replace(/xxxxxx/, newToken),
    433433
    function(xhr, el) {
    434434
    435435
    /* Evaluate in global scope scripts embedded inside the toolbar */
    @@ -532,7 +532,7 @@
    532532
    sfwdt.innerHTML = '\
    533533
    <div class="sf-toolbarreset">\
    534534
    <div class="sf-toolbar-icon"><svg width="26" height="28" xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" viewBox="0 0 26 28" enable-background="new 0 0 26 28" xml:space="preserve"><path fill="#FFFFFF" d="M13 0C5.8 0 0 5.8 0 13c0 7.2 5.8 13 13 13c7.2 0 13-5.8 13-13C26 5.8 20.2 0 13 0z M20 7.5 c-0.6 0-1-0.3-1-0.9c0-0.2 0-0.4 0.2-0.6c0.1-0.3 0.2-0.3 0.2-0.4c0-0.3-0.5-0.4-0.7-0.4c-2 0.1-2.5 2.7-2.9 4.8l-0.2 1.1 c1.1 0.2 1.9 0 2.4-0.3c0.6-0.4-0.2-0.8-0.1-1.3C18 9.2 18.4 9 18.7 8.9c0.5 0 0.8 0.5 0.8 1c0 0.8-1.1 2-3.3 1.9 c-0.3 0-0.5 0-0.7-0.1L15 14.1c-0.4 1.7-0.9 4.1-2.6 6.2c-1.5 1.8-3.1 2.1-3.8 2.1c-1.3 0-2.1-0.6-2.2-1.6c0-0.9 0.8-1.4 1.3-1.4 c0.7 0 1.2 0.5 1.2 1.1c0 0.5-0.2 0.6-0.4 0.7c-0.1 0.1-0.3 0.2-0.3 0.4c0 0.1 0.1 0.3 0.4 0.3c0.5 0 0.9-0.3 1.2-0.5 c1.3-1 1.7-2.9 2.4-6.2l0.1-0.8c0.2-1.1 0.5-2.3 0.8-3.5c-0.9-0.7-1.4-1.5-2.6-1.8c-0.8-0.2-1.3 0-1.7 0.4C8.4 10 8.6 10.7 9 11.1 l0.7 0.7c0.8 0.9 1.3 1.7 1.1 2.7c-0.3 1.6-2.1 2.8-4.3 2.1c-1.9-0.6-2.2-1.9-2-2.7c0.2-0.6 0.7-0.8 1.2-0.6 c0.5 0.2 0.7 0.8 0.6 1.3c0 0.1 0 0.1-0.1 0.3C6 15 5.9 15.2 5.9 15.3c-0.1 0.4 0.4 0.7 0.8 0.8c0.8 0.3 1.7-0.2 1.9-0.9 c0.2-0.6-0.2-1.1-0.4-1.2l-0.8-0.9c-0.4-0.4-1.2-1.5-0.8-2.8c0.2-0.5 0.5-1 0.9-1.4c1-0.7 2-0.8 3-0.6c1.3 0.4 1.9 1.2 2.8 1.9 c0.5-1.3 1.1-2.6 2-3.8c0.9-1 2-1.7 3.3-1.8C20 4.8 21 5.4 21 6.3C21 6.7 20.8 7.5 20 7.5z"/></svg></div>\
    535-
    An error occurred while loading the web debug toolbar. <a href="{{ path("_profiler_home") }}' + newToken + '>Open the web profiler.</a>\
    535+
    An error occurred while loading the web debug toolbar. <a href="{{ path("_profiler_home")|escape('js') }}' + newToken + '>Open the web profiler.</a>\
    536536
    </div>\
    537537
    ';
    538538
    sfwdt.setAttribute('class', 'sf-toolbar sf-error-toolbar');

    Original file line numberDiff line numberDiff line change
    @@ -68,6 +68,9 @@ protected function getVersionStrategy()
    6868
    return $this->versionStrategy;
    6969
    }
    7070

    71+
    /**
    72+
    * @return bool
    73+
    */
    7174
    protected function isAbsoluteUrl(string $url)
    7275
    {
    7376
    return false !== strpos($url, '://') || '//' === substr($url, 0, 2);

    Original file line numberDiff line numberDiff line change
    @@ -50,7 +50,7 @@ public function applyVersion(string $path)
    5050
    return $this->getManifestPath($path) ?: $path;
    5151
    }
    5252

    53-
    private function getManifestPath(string $path)
    53+
    private function getManifestPath(string $path): ?string
    5454
    {
    5555
    if (null === $this->manifestData) {
    5656
    if (!file_exists($this->manifestPath)) {