Skip to content

Conversation

@ttskch
Copy link
Contributor

@ttskch ttskch commented Oct 18, 2025

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 are 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 us 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/

@stale
Copy link

stale bot commented Dec 17, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 17, 2025
@soyuka
Copy link
Member

soyuka commented Dec 17, 2025

I actually like this patch, I think we should document this however.

@soyuka soyuka merged commit 45831a9 into api-platform:main Dec 17, 2025
109 of 114 checks passed
@stale stale bot removed the stale label Dec 17, 2025
@ttskch ttskch deleted the feat/larabel-skip-autoconfigure branch December 17, 2025 17:47
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.

2 participants