Skip to content
Advertisement

Why I can’t get Symfony Finder like a service?

I use Symfony Standard Edition and try to get Symfony Finder component like a service, but not found it. To use the Finder, I need to create it manually like:

$finder = new SymfonyComponentFinderFinder();

Why I can’t get it from service container? Is it was wrong?

P.S. The Symfony Filesystem component exists in service container and available by name filesystem.

Advertisement

Answer

The Symfony’s Finder component is a standalone component, it is not a part of the FileSystem component:

There is no “finder” service because a Finder instance is an object that needs to be manipulated to work. And as objects are always passed by reference, if someone modifies the service once, everyone will see those changes. This is not what you want for this component.

But you can create your own service as a Finder instance and use this service only in another service (as a dependency).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement