feat(laravel): Enable to skip autoconfiguration with new `SkipAutoconfigure` attribute
| Q | A |
|---|---|
| Branch? | main |
| Tickets | N/A |
| License | MIT |
| Doc PR | N/A |
We discovered an issue where a circular dependency could occur when decorating a system processor such as WriteProcessor.
For example, create a decorator for WriteProcessor called AppWriteProcessor as follows:
$this->app->extend(WriteProcessor::class, function (WriteProcessor $inner) {
return new AppWriteProcessor($inner);
});
final class AppWriteProcessor implements ProcessorInterface
{
public function __construct(
private readonly WriteProcessor $decorated,
) {
}
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
{
return $this->decorated->process($data, $operation, $uriVariables, $context);
}
}
In this case, because AppWriteProcessor implements ProcessorInterface, it is tagged with ProcessorInterface and is therefore included as a dependency of CallableProcessor.
Furthermore, because CallableProcessor is included in the dependencies of WriteProcessor, a circular dependency occurs: CallableProcessor -> AppWriteProcessor -> WriteProcessor -> CallableProcessor.
The only two ways to prevent this is to change the constructor argument type of AppWriteProcessor to mixed instead of WriteProcessor, or to remove the tagging of AppWriteProcessor with ProcessorInterface.
This PR introduces a new SkipAutoconfigure attribute, which allows you to exclude some application code from autoconfigure.
I've created a minimal environment to reproduce this issue in the following GitHub repository, and the commit logs explain the process to resolve it.
https://github.com/ttskch/api-platform-laravel-system-provider-decoration-example/commits/main/