PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 11, 2022

[FIXED] Why I can't get Symfony Finder like a service?

 January 11, 2022     php, symfony, symfony-components, symfony-filesystem, symfony-finder     No comments   

Issue

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 Symfony\Component\Finder\Finder();

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.


Solution

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

  • http://symfony.com/doc/current/components/finder.html
  • http://symfony.com/doc/current/components/filesystem.html

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).



Answered By - Yann Eugoné
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing