Skip to content

Conversation

@soyuka
Copy link

@soyuka soyuka commented Mar 13, 2025

The idea of auto-configurable services is that you setup some interfaces for auto configuration and they get automatically tagged by the Laravel container. For example, let's take this interface:

interface ProviderInterface {}

We want this interface to be automatically tagged in the container, a Laravel component would have something like this:

$app->make(LibraryProvider::class, function(Application $app) { 
    return new Provider($app->tagged(ProviderInterface::class)); 
});

$app->autoconfigure(ProviderInterface::class);

With this feature, in userland developers don't need to do anything as these services are automatically discovered and tagged.
We implemented this into API Platform and @TomasVotruba suggested I propose this to the Laravel framework.

Do you think that this is something we'd like to see inside the Laravel framework?

@taylorotwell taylorotwell marked this pull request as draft March 13, 2025 14:55
}

try {
require_once $sourceFile;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely going to be an issue if the discovered file is a blade template or a pest unit file. Still looking to improve that...

@soyuka
Copy link
Author

soyuka commented May 22, 2025

Hi, a quick update this is working for now on API Platform but is harder then it looked:

  • services that depends on autoconfigured services need to be deferred
  • pest unit tests can be triggered by the autoloader (and we rely on require_once to get the class names)

That said, I still think the idea may work but it'll be hard to make this bug-free at least in an initial work. I'll be closing this as I don't want to introduce this to the framework unless we find another way of getting the class names. Feel free to continue this work and ping me if you want more insights.

@soyuka soyuka closed this May 22, 2025
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.

1 participant