Category : dependency-injection

I’m using Symfony DependencyInjection, but not building my app with Symfony and have a problem with the following scenario. I configured by Composer and everything already. Say I have a class called TestController with the following constructor: class TestController { private $environment; public function __construct(string $environment) { $this->environment = $environment; } } Later on, I ..

Read more

I have a generic service who uses a configuration to do its processing. <?php namespace AppService; class MyCustomService { /** * @var array */ private $config; /** * MyCustomService constructor. * * @param array $config */ public function __construct(array $config) { $this->config = $config; } public function getConfig() { return $this->config; } } I want ..

Read more

I want to test my privare service. I saw people recommending to get it with Locator. I’m trying to do as docs say: https://symfony.com/doc/current/service_container/service_subscribers_locators.html#defining-a-service-locator My services.yaml: AppTestsServiceLocatorsAuthServiceLocator: arguments: !service_locator AppServiceAuthManager: ‘@AppServiceAuthManager’ I’m getting: SymfonyComponentConfigExceptionLoaderLoadException : "!service_locator" tag only accepts maps of "@service" references in "/var/www/api/src/../config/services.yaml" in /var/www/api/src/../config/services.yaml (which is being imported from "/var/www/api/src/Kernel.php"). /var/www/api/vendor/symfony/config/Loader/FileLoader.php:173 Do ..

Read more

So I use a Service Class (extends from TYPO3CMSCoreAuthenticationAuthenticationService) to authenticate our Frontend Users using OAuth2. These Services are automatically instantiated and called via Typos own In this class I used to save data from the authentication result to $GLOBALS[‘TSFE’]->fe_user using setKey(‘ses’, ‘key’, ‘data’), which seems is not possible anymore since v10. How would I ..

Read more

I want to Use Dependency Injection laravel-excel in laravel 8 but I got error this my code in ShipmentsExport: namespace AppExports; use AppShipments; use MaatwebsiteExcelConcernsFromCollection; use IlluminateSupportCollection; use DB; class ShipmentsExport implements FromCollection { private $year; public function __construct(int $year) { $this->year = $year; } public function collection() { $data = DB::table(‘admins’)->whereYear($this->$year)->get(); // get error ..

Read more

This is a two part question. First, I can’t seem to find out how to make PhpStorm correctly hint Doctrine repositories: Entity looks like this: /** * @ORMEntity(repositoryClass="UserRepository") * @Entity @Table(name="users") */ class User { Repository looks like this: use DoctrineORMEntityRepository; class UserRepository extends EntityRepository { public function getUser() {} } But when access the ..

Read more

In Symfony you can direct inject a service into a controller function: use AppServiceFooService; class FooController { public function one(FooService $fooService){ $fooService->doSomething(); } } I’m looking for reasons/guides when to inject and when not to inject. What is the performance price for either one, or pro/cons, e.g.: Must you always aim to not have a ..

Read more