Questions tagged [symfony-dependency-injection]
35 questions
                    
                    8
                    
            votes
                
                2 answers
            
        Get service via class name from iterable - injected tagged services
I am struggling to get a specific service via class name from group of injected tagged services.
Here is an example:
I tag all the services that implement DriverInterface as app.driver and bind it to the $drivers variable.
In some other service I…
         
    
    
        povs
        
- 93
- 2
- 6
                    5
                    
            votes
                
                1 answer
            
        How to use AutoWiring when looping through Subclasses?
I have a Sumfony 4.3 command that processes some data and loops through a number of "processors" to do the processing. The code uses a factory (autowired) which then instantiates the command.
use App\Entity\ImportedFile;
use…
         
    
    
        jdog
        
- 2,465
- 6
- 40
- 74
                    3
                    
            votes
                
                0 answers
            
        Are anonymous inline invokable factories possible with Symfony?
I can define anonymous inline factory (Symfony 6+) like this:
GuzzleClient1:
    class: GuzzleHttp\ClientInterface
    factory: [ !service { class: 'App\GuzzleClientFactory', calls: [ { 'withBaseUri': [ 'http://example.com' ] } ] }, 'build' ]
or…
         
    
    
        Vladislav Rastrusny
        
- 29,378
- 23
- 95
- 156
                    3
                    
            votes
                
                1 answer
            
        How can I use a class constant as the tag for bound parameter service?
I have tagged a group of  services  that implement the same interface like this in my  configuration:
// services.yml
services:
  _instanceof:
     App\SomeInterface:
       tags: [ !php/const App\SomeInterface::TAG ]
(Where the value for …
         
    
    
        yivi
        
- 42,438
- 18
- 116
- 138
                    3
                    
            votes
                
                0 answers
            
        Unused binding error when trying to bind logger to autowired controller constructor in Symfony 3.4
After upgrading to Symfony 3.4 from 2.8, I am attempting to get rid of warnings about using services from the container. One hang up is my controller all extend from an abstract controller which needs access to the monolog logger. I've decided to…
         
    
    
        fivejeez
        
- 63
- 1
- 6
                    3
                    
            votes
                
                1 answer
            
        Symfony DI: Uncaught ArgumentCountError: Too few arguments to function App::__construct(), 0 passed in index.php on line 28 and exactly 1 expected
I'm trying to implement Symfonys dependency injection container. 
I have 2 containers set, one for the database, and one for the system user.
and I'm using addArgument() to both the App class and SystemUser class, pushing to App class a SystemUser…
         
    
    
        Imnotapotato
        
- 5,308
- 13
- 80
- 147
                    2
                    
            votes
                
                1 answer
            
        Make private and removed service available in tests
I'm trying to make vatin-bundle compatible with Symfony 6.
But the tests fail
The "validator" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and…
         
    
    
        Brucie Alpha
        
- 1,135
- 2
- 12
- 31
                    2
                    
            votes
                
                1 answer
            
        Circular reference problem with decorated service
As the documentation suggests I wrote this service to add the uuid to the normalized object:
        
            
            
                
                    
    
    
         
    
    
                
            
        
    
 
    
    
        Jack Skeletron
        
- 1,351
- 13
- 37
                    2
                    
            votes
                
                0 answers
            
        Is there a way to override a Symfony container value with a Console argument?
tl;dr: I have a Symfony service configuration that binds a default string value to a named parameter, and I want to override it in a Console process with a command line option value.
I'm working on a Composer library (php-tuf/composer-stager) that…
         
    
    
        TravisCarden
        
- 344
- 2
- 14
                    2
                    
            votes
                
                1 answer
            
        Can't get the IriConverter from the container because it's not public
I trying to load the api_platform.iri_converter but get an error:
The \"api_platform.iri_converter\" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container…
         
    
    
        Ricardo Albear
        
- 496
- 8
- 26
                    2
                    
            votes
                
                1 answer
            
        Symfony Autowiring for Legacy-Controllers without PSR-4
I have a Legacy App and I'm using Symfony with it.
Everything works fine so far.
Now I want to use Autowiring for my Legacy-Controllers.
they're loaded using composers classmap functionality
are in the Root-Namespace (e.g. \Controller_Page)
class…
         
    
    
        Patrick
        
- 1,562
- 1
- 16
- 33
                    1
                    
            vote
                
                1 answer
            
        How to represent argument that uses factory with YAML configuration, equivalent to this XML configuration?
I am trying to figure out if I can use a similar construct in the YAML syntax for a service definition as in the XML syntax. Specifically the "construct" where, in XML, an argument can be resolved by factory "in-line".
I have the following XML…
         
    
    
        leflings
        
- 646
- 3
- 17
                    1
                    
            vote
                
                1 answer
            
        What Did I Do Wrong Here With Shopware 6 Product.Loaded Event
I created a bare minimum Shopware 6 plugin to display product ID when the product is loaded. It worked fine. Below is my code.
   PATH: src/Resources/config/services.xml
        
            
            
                
                    
    
    
         
    
    
                
            
        
     
 
    
    
        DevOPlug
        
- 59
- 8
                    1
                    
            vote
                
                1 answer
            
        Passing dynamic arguments to service factory in Symfony
I'm integrating Symfony into an older application having its own dependency container based on PSR-11. Been searching for a solution to merge that DI container to the one Symfony uses, but found nothing. To just make it work, I came with one "hacky"…
         
    
    
        Jazi
        
- 6,569
- 13
- 60
- 92
                    1
                    
            vote
                
                0 answers
            
        Symfony 5 symfony/dependency-injection container does not handle service by name
In the config file services.yaml I create several services with names
cart.storage.session:
    class: App\Cart\Storage\SessionStorage
    arguments:
        - '%cart.storage.session_key%'
cart.calculator:
    class:…
         
    
    
        webgrig
        
- 49
- 1
- 8