Repository: symfony/symfony
File: src/Symfony/Component/HttpKernel/Event/ViewEvent.php (PHP)

Code before:
 * Call setResponse() to set the response that will be returned for the
 * current request. The propagation of this event is stopped as soon as a
 * response is set.
 *
 * @author Bernhard Schussek <bschussek@gmail.com>
 */
final class ViewEvent extends RequestEvent
{
    /**
     * @deprecated since Symfony 8.1, use $controllerMetadata instead
     */
    public readonly ?ControllerArgumentsEvent $controllerArgumentsEvent;

    public function __construct(
        HttpKernelInterface $kernel,
        Request $request,
        int $requestType,
        private mixed $controllerResult,
        ControllerMetadata|ControllerArgumentsEvent|null $controllerMetadata = null,
    ) {
        if ($controllerMetadata instanceof ControllerArgumentsEvent) {
            trigger_deprecation('symfony/http-kernel', '8.1', 'Passing a ControllerArgumentsEvent to the ViewEvent constructor is deprecated. Pass a ControllerMetadata instance instead.');
            $this->controllerArgumentsEvent = $e = $controllerMetadata;
            $controllerMetadata = new ControllerMetadata(\Closure::bind(static fn () => $this->controllerEvent, $e, $e::class)(), $e);
        } else {
            $this->controllerArgumentsEvent = null;
        }

        parent::__construct($kernel, $request, $requestType, $controllerMetadata);
    }

    public function getControllerResult(): mixed
    {
        return $this->controllerResult;
    }

    public function setControllerResult(mixed $controllerResult): void
    {
        $this->controllerResult = $controllerResult;
    }
}


Review comment (suggestion):
this is **not** backward compatible. As the HttpKernel instantiate the class with a ControllerMetadata, the `controllerArgumentsEvent` will now always be `null`, which will break event listeners that have not been migrated yet.

Instead, we should create a ControllerArgumentsEvent from the ControllerMetadata and assign it to the property.

Code after:
 * Call setResponse() to set the response that will be returned for the
 * current request. The propagation of this event is stopped as soon as a
 * response is set.
 *
 * @author Bernhard Schussek <bschussek@gmail.com>
 */
final class ViewEvent extends RequestEvent
{
    public readonly ?ControllerArgumentsMetadata $controllerMetadata;

    /**
     * @deprecated since Symfony 8.1, use $controllerMetadata instead
     */
    public private(set) ?ControllerArgumentsEvent $controllerArgumentsEvent {
        get {
            trigger_deprecation('symfony/http-kernel', '8.1', 'Accessing the "controllerArgumentsEvent" property of the "%s" class is deprecated. Use "controllerMetadata" instead.', __CLASS__);

            if (!$m = $this->controllerMetadata) {
                return null;
            }

            return $this->controllerArgumentsEvent ??= new ControllerArgumentsEvent($this->getKernel(), \Closure::bind(fn () => $this->controllerEvent, $m, ControllerMetadata::class)(), $m->getArguments(), $this->getRequest(), $this->getRequestType());
        }
    }

    public function __construct(
        HttpKernelInterface $kernel,
        Request $request,
        int $requestType,
        private mixed $controllerResult,
        ControllerArgumentsMetadata|ControllerArgumentsEvent|null $controllerMetadata = null,
    ) {
        if ($controllerMetadata instanceof ControllerArgumentsEvent) {
            trigger_deprecation('symfony/http-kernel', '8.1', 'Passing a ControllerArgumentsEvent to the ViewEvent constructor is deprecated. Pass a ControllerArgumentsMetadata instance instead.');
            $this->controllerArgumentsEvent = $controllerMetadata;
            $controllerEvent = \Closure::bind(fn () => $this->controllerEvent, $controllerMetadata, ControllerArgumentsEvent::class)();
            $controllerMetadata = new ControllerArgumentsMetadata($controllerEvent, $controllerMetadata);
        }
        $this->controllerMetadata = $controllerMetadata;

        parent::__construct($kernel, $request, $requestType);
    }

    public function getControllerResult(): mixed
    {
        return $this->controllerResult;
    }

    public function setControllerResult(mixed $controllerResult): void
    {
        $this->controllerResult = $controllerResult;