Skip to content

[make:decorator] Add new maker to create decorator - #1807

Merged
GromNaN merged 1 commit into
symfony:1.xfrom
GromNaN:feature/make-decorator
Aug 30, 2026
Merged

[make:decorator] Add new maker to create decorator#1807
GromNaN merged 1 commit into
symfony:1.xfrom
GromNaN:feature/make-decorator

Conversation

@GromNaN

@GromNaN GromNaN commented Aug 21, 2026

Copy link
Copy Markdown
Member

Rebase and continuation of #1613 by @WedgeSama, updated for the current 1.x codebase (config moved from XML to PHP, help files restructured) and with the remaining review feedback from @Neirda24 applied:

  • Fixed the getRealId() strict comparison (in_array with strict mode).
  • Initialized the short name map entries explicitly instead of relying on implicit array creation, and replaced the array_map/array_unique callable-first-class syntax with a plain foreach.
  • Fixed the choice prompt wording ("choose which one you want to decorate:").
  • Replaced the ReflectionClass lookup of ContainerInterface constants with a static map for the onInvalid option.
  • Added support for variadic parameters when parsing methods to decorate (previously produced an incorrect signature and a broken forwarding call).
  • Fixed a typo in an internal exception message.

Add a make:decorator command that generates a decorator class for an existing service. The maker asks for the service to decorate and the class name of the decorator, then generates a class that either implements the decorated service interfaces or extends its class.

bin/console make:decorator Symfony\Component\Routing\Generator\UrlGeneratorInterface MyUrlGenerator
<?php

namespace App;

use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;

#[AsDecorator(UrlGeneratorInterface::class)]
final class MyUrlGenerator implements UrlGeneratorInterface
{
    public function __construct(
        #[AutowireDecorated]
        private readonly UrlGeneratorInterface $inner,
    ) {
    }

    public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
    {
        return $this->inner->generate($name, $parameters, $referenceType);
    }

    public function setContext(RequestContext $context): void
    {
        $this->inner->setContext($context);
    }

    public function getContext(): RequestContext
    {
        return $this->inner->getContext();
    }
}

Closes #1401

@GromNaN
GromNaN force-pushed the feature/make-decorator branch 3 times, most recently from 7d87396 to 1359fc1 Compare August 28, 2026 18:34
@GromNaN
GromNaN force-pushed the feature/make-decorator branch 2 times, most recently from d9b3ca0 to 3fe7b78 Compare August 29, 2026 20:28
Add a make:decorator command that generates a decorator class for an
existing service. The maker asks for the service to decorate and the
class name of the decorator, then generates a class that either
implements the decorated service interfaces or extends its class.

Supporting pieces:
- DecoratorHelper resolves a service id from a full id or a short class
  name, and exposes suggestions on error.
- MakeDecoratorPass fills the helper with the service ids, the service
  id to class map and the short class name map at compile time.
- DecoratorInfo and the ClassMethod / MethodArgument models describe the
  methods to forward to the decorated service, including variadic
  parameters.
- UseStatementGenerator handles the extra type imports needed by the
  generated methods.
- Validator gains a check for existing class names.

Closes symfony#1401
@GromNaN
GromNaN force-pushed the feature/make-decorator branch from 3fe7b78 to ca9ce46 Compare August 30, 2026 10:08
@GromNaN
GromNaN merged commit 5e6824d into symfony:1.x Aug 30, 2026
8 of 9 checks passed
@GromNaN
GromNaN deleted the feature/make-decorator branch August 30, 2026 10:09
@GromNaN

GromNaN commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

Thank you @WedgeSama for the initial work and @Neirda24 for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add maker for decorate services

2 participants