For an API project I want to fail very early, before the controller is dispatched, if the input data is incorrect. I’ve managed to get the validation done by using the route defaults and an event subscriber subscribing to the KernelEvents::REQUEST event. As you can see in the code, I’m trying to get the validator from the container. My assumption
Tag: dependency-injection
Laravel – Middleware custom typed Request parameter
I want to use VacancyListRequest to pass through middleware parameters and use its rules to validate them before controller action. I know that middleware acts Pipeline pattern, but does anybody know how to use any custom type except default IlluminateHttpRequest? Middleware Controller Error AppHttpMiddlewareVacancyBeforeVacancyIndexRequestMiddleware::handle(): Argument #1 ($request) must be of type AppHttpRequestsVacancyVacancyListRequest, IlluminateHttpRequest given, Answer You are getting that error
Symfony autowire/autoconfigure not working
I created a symfony 5.3 api. My plan is to inject the “EntityManager” via “EntityManagerInterface”. Error that comes: My services.yaml My CreateUserAccountController.php in src/Controller/: My composer.json: I know that I dont use the Manager, but it doesn´t work for me. The webserver I use: symfony cli webserver Has anyone a idea, where the problem is? Answer This is actually a
Symfony inject array through services.yaml
I am trying to inject an array to Event Subscriber, but I also inject an other repository so I don’t know how this will work: Here’s what I am trying: services.yaml TerminateSubscriber.php: It says that the first parameter should be an instance of the Repo, array given. But if I switch the parameters it says “optional parameter given before required”
Symfony: Service in other Service not loaded (Too few arguments)
Background I have a OptionHelper-Class that is looking in the database-table, where I store some flexible parameters. This class is working fine in Controllers. Now I want to use this class in a …
Resolving dependencies without a dependency injection container
I have a project in plain PHP and there is a class which is dependent on external library. I don’t feel like passing it to constructor everywhere is a good idea (it’s called mainly in tests, but the …
Store but not EXECUTE a Global Function (PHP)
This is an odd situation and I think the answer is ‘you can’t do that, what are you thinking?’ but hope someone can prove me wrong. My goal is to store a globally scoped function in a variable then …
How do I get a service from the container directly, if I didn’t/couldn’t inject the service using DI?
I have a part of code where I’m injecting two services $checker and $paginator by dependency injection. It works perfectly: public function index(Request $request, Paginator $paginator, Checker $…
How to use the logger in a console command on Symfony 4?
I’ve recently gone from using Symfony 2.7 to 4.2. Previously in my commands in order to log to a file I used something like: This functionality appears to have changed. I can log from a controller following https://symfony.com/doc/current/logging.html I can output to the console using: But as much as I stare at the information on the symfony website I just
Overriding Mailer service in Laravel 5.4
I am trying to override the default implementation of Mailer in IlluminateMailMailServiceProvider. At first, I thought that I will just extend the service and switch the implementation in the container followingly: AppMailMailer AppProvidersAppServiceProvider The problem is that even though I’ve overridden the container definition when resolving the service it ignores my definition completely because IlluminateMailMailServiceProvider has $defer = true property,