Review main Merged

89890[FEATURE] Make validation attributes usable for method parameters

Elias Häußler CR +2 V +2 Hard +479 −89 updated 11/22/25, 21:17

Commit message

Both `#[IgnoreValidation]` and `#[Validate]` attributes can be used
at controller actions to configure the validation behavior for either

    (1) the complete method or
    (2) a single parameter.

This works fine for (1). However, using these attributes in context
of (2) raises some concerns concerning

    (a) duplication of parameter names,
    (b) validation of the existence of a configured parameter, and
    (c) unnecessary complexity regarding reflection-based handling of
        these parameters.

When the attributes were originally implemented as Doctrine
annotations, the only possible way to implement behavior (2) was to
add the appropriate annotation to the method-related annotation.
Since #107229, annotations are no longer used in Extbase, and PHP
attributes are the only left successor in this area. Since PHP
attributes support placement at specific method parameters, the
existing attributes can be safely rewritten to be placed

    (A) at a specific method and
    (B) at a specific method parameter.

This patch implements this behavior: The capabilities of the existing
attributes are expanded to allow placement at method parameters as
well. The previous behavior (defining validation-related behavior at
method level using the existing attribute properties) is now
deprecated and will be removed with TYPO3 v15.

Developers can easily migrate their implementations by moving
parameter-related attributes next to the method parameters instead of
the related method.

**Before:**

    final class FooController extends ActionController
    {
        #[IgnoreValidation(argumentName: 'something')]
        public function barAction(string $something): ResponseInterface
        {
            // Do something...
        }

        #[Validate(validator: 'NotEmpty', param: 'anythingNotEmpty')]
        public function bazAction(string $anythingNotEmpty): ResponseInterface
        {
            // Do something...
        }
    }

**After:**

    final class FooController extends ActionController
    {
        public function barAction(
            #[IgnoreValidation]
            string $something,
        ): ResponseInterface {
            // Do something...
        }

        public function bazAction(
            #[Validate(validator: 'NotEmpty')]
            string $anythingNotEmpty,
        ): ResponseInterface {
            // Do something...
        }
    }

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 1

Files 21

Show 1 more file

Review log 2736

Show 711 earlier messages
  1. Elias Häußler uploaded patch set 1 06/25/25, 16:54

  2. core-ci voted on patch set 1 V -1 06/25/25, 17:03 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/80885

  3. Elias Häußler wrote 08/21/25, 06:56

    Topic set to extbase
  4. Elias Häußler uploaded patch set 2 V -1 10/14/25, 15:40

  5. core-ci voted on patch set 2 V +1 10/14/25, 15:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86650

  6. Elias Häußler uploaded patch set 3 V +1 11/20/25, 15:33

  7. core-ci voted on patch set 3 V -1 11/20/25, 15:43 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90304

  8. Elias Häußler uploaded patch set 4 V -1 11/20/25, 18:34

  9. core-ci voted on patch set 4 V +1 11/20/25, 18:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90349

  10. Elias Häußler uploaded patch set 5 V +1 11/20/25, 20:48

  11. Elias Häußler marked it ready for review 11/20/25, 20:48

  1. core-ci voted on patch set 5 V +1 11/20/25, 20:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90372

  2. Elias Häußler uploaded patch set 6 V +1 11/20/25, 21:04

  3. Elias Häußler uploaded patch set 7 11/20/25, 21:06

  4. core-ci voted on patch set 7 V +1 11/20/25, 21:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90384

  5. Simon Schaufelberger uploaded patch set 8 V +1 11/20/25, 23:02

  6. core-ci voted on patch set 8 V +1 11/20/25, 23:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90413

  7. Simon Schaufelberger commented on patch set 8 11/20/25, 23:20

    I'm not really happy with the deprecation message: Passing an argument name to an #[IgnoreValidation] attribute is deprecated and will be removed in TYPO3 v15.0. Place the attribute on the method parameter instead. in /home/simon/Code/typo3-core/typo3/sysext/extbase/Classes/Attribute/IgnoreValidation.php line 52 This does not help at all where the deprecated attribute is used. Can we add more info about controller or method or at least extension?
  8. Simon Schaufelberger commented on patch set 8 V +1 11/20/25, 23:33

    Tested with a custom extension and couldn't find any problems.
  9. Elias Häußler commented on patch set 8 11/21/25, 06:20

    Reply

    I assume this is not possible, because the attribute does not know its context when being created. If you have a suggestion for a better naming, feel free to adapt it as you wish.
  10. Elias Häußler rebased onto patch set 9 V +1 11/21/25, 11:59

  11. Oliver Klee commented on patch set 9 11/21/25, 12:06

    IgnoreValidation.php:30

    Would it work to add the `@deprecated` annotation to this line instead of the `@todo` in line 33?
  12. core-ci voted on patch set 9 V +1 11/21/25, 12:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90494

  13. Simon Schaufelberger commented on patch set 9 11/21/25, 20:06

    IgnoreValidation.php:57

    ```suggestion if ($this->argumentName !== null) { $detectedLocation = 'unknown location'; $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 4); if ( isset($trace[2]['object']) && $trace[2]['object'] instanceof ClassSchema && isset($trace[2]['args'][0]) && $trace[2]['args'][0] instanceof \ReflectionClass ) { /** @var \ReflectionClass $targetClass */ $targetClass = $trace[2]['args'][0]; $className = $targetClass->getName(); $methodName = 'unknownMethod'; foreach ($targetClass->getMethods() as $method) { $attributes = $method->getAttributes(self::class); foreach ($attributes as $attribute) { $args = $attribute->getArguments(); $argCheck = $args['argumentName'] ?? $args[0] ?? null; if ($argCheck === $this->argumentName) { $methodName = $method->getName(); break 2; } } } $detectedLocation = sprintf('%s::%s', $className, $methodName); } trigger_error( 'Passing an argument name to an #[IgnoreValidation] attribute is deprecated. ' . 'Found in: ' . $detectedLocation . '. ' . 'Place the attribute on the parameter named "$' . $this->argumentName . '" instead.', E_USER_DEPRECATED, ); } ```
  14. Simon Schaufelberger commented on patch set 9 11/21/25, 20:07

    IgnoreValidation.php:57 Reply

    by that it would be possible to output some meaningful deprecation message. What do you think?
  15. Simon Schaufelberger commented on patch set 9 11/21/25, 20:09

    IgnoreValidation.php:57 Reply

    "and will be removed in TYPO3 v15.0" got lost on the way...
  16. Elias Häußler commented on patch set 9 11/22/25, 16:17

    IgnoreValidation.php:57 Reply

    I think we should not do this. Here are the reasons: 1) It massively bloats up the attribute class with IMO less impact. Developers reading their deprecation log should be able to search for usages of the attribute in their project. 2) When upgrading an application which raises these deprecation warnings, developers must update their validation attributes anyway, because of the recent changes in this area. 3) We never do this in TYPO3 core. I could at least not find any places where we use `debug_backtrace` to fetch this kind of information. We haven't done this in #97559 as well. I hope this is fine for you.
  17. Simon Schaufelberger commented on patch set 9 CR +1 V +1 11/22/25, 17:44

    IgnoreValidation.php:57 Reply

    It's only for the people not using rector and support 2 versions. I'll give my best to create a Rector rule for that.
  18. Simon Schaufelberger commented on patch set 9 11/22/25, 17:45

    Reply

    Done
  19. Christian Kuhn commented on patch set 9 11/22/25, 21:00

    IgnoreValidation.php:30 Reply

    i think its fine turning the two @todo into @deprecated - afaik ide's are quite fine with these positions. i'm not used to '@param @deprecated', but it feels odd to me and we can't leave out @param i suppose. i looked at the change for a while and played around now. i hope it is ok to resolve for now in order to reach a merge: this is the last part of the extbase attribute works and i'd love to see this being done with 14.0 let's sort out such a detail with a dedicated change if really needed.
  20. Christian Kuhn uploaded patch set 10 CR +1 V +1 11/22/25, 21:02

  21. Christian Kuhn voted on patch set 10 CR +2 V +2 11/22/25, 21:04

  22. Simon Schaufelberger voted on patch set 10 CR +1 V +1 11/22/25, 21:05

  23. Stefan Bürk voted on patch set 10 CR +1 V +1 11/22/25, 21:08

  24. core-ci voted on patch set 10 V +1 11/22/25, 21:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90691

  25. Christian Kuhn merged patch set 11 11/22/25, 21:17