Questions tagged [php-di]

PHP-DI is a simple to use dependency injection container for PHP. It is practical, powerful, and framework-agnostic.

PHP-DI is a simple to use dependency injection container for PHP. It is practical, powerful, and framework-agnostic.

See more:

101 questions
0
votes
3 answers

Inject container in controller class

I'm migrating my app from Slim/3 to Slim/4. Perhaps I'm confused because there're endless syntaxes for the same stuff but I composed this: use DI\Container; use Slim\Factory\AppFactory; use Slim\Psr7\Request; use Slim\Psr7\Response; require…
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
0
votes
1 answer

how to register calss in php-di to automatically call some method when instantiated

i run controller this way $controller = $this->getContainer()->get($class); $controller->{$method}(...array_values($vars)); now inside controller i need to use models if i try to autowire model like class MyClass extends Controller { public…
Eugene
  • 1,680
  • 3
  • 14
  • 23
0
votes
1 answer

How do I fetch the PHP DI container?

How do I load a database container using PHP DI? This is one of the variations I have tried up until now. Settings.php new Database(), 'SystemUser'…
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
0
votes
0 answers

Separate Entity from Model or keep them as one class (SpotORM)

I am progressively incorporating in my project an ORM (with SpotORM) and dependency injection (with PHP-DI) and I want to do it right. Right now I can't figure out if the Entity and the Model are supposed to be two different classes, or just…
sylbru
  • 1,461
  • 1
  • 11
  • 19
0
votes
1 answer

PHP-DI: Interface being injected into constructor won't resolve correctly

I can't seem to get PHP-DI to properly resolve an interface to it's configured class when injected in the constructor. In the following code, using the container to get \Foo\IDog returns a Poodle class, but when using the container to get…
Brent
  • 501
  • 3
  • 13
0
votes
1 answer

PHP-DI using annotation injection with factory

i have a factory for creating an object. Abbruchprotokoll::class => factory(function(ContainerInterface $c){ return new Abbruchprotokoll($c->get(Request::class)->getRouterParam('stts-id'), $c->get(MySQL::class)); }) the factory is creating that…
JuKe
  • 663
  • 2
  • 7
  • 20
0
votes
1 answer

Why scalar parameter value injection doesn't work in constructor?

I have the settings class:
Audiophile
  • 970
  • 2
  • 8
  • 20
0
votes
1 answer

Registering Slim's PHP-View in PHP-DI6

I'm trying to learn the Slim framework and PHP-DI at the same time. I don't want folks to write my code for me, but I'm at a complete stand-still here. All I want to do is figure out how to pass Slim's PHP-View object into a controller class using…
ConleeC
  • 337
  • 6
  • 13
0
votes
1 answer

PHPUnit working with Slim and PHP-DI

I think I have a design flaw in my application. I'll explain why. I have a wrapper around a httpclient which gets injected (via php-di) in all kinds of other classes. I use Slim to create an api. When call enters my application, Slim will guide it…
sridesmet
  • 875
  • 9
  • 19
0
votes
1 answer

PHP DI Annotations don't work

I have just started using PHP-DI and it is awesome, however I cannot manage to solve one issue. Here is my services definitions DI\autowire( '\CRM\Report\Service\ReportService' ), …
user4671628
0
votes
2 answers

How to pass user data to service from controller using PHP-DI

My controllers have an account object and a user object, and almost all interactions with the backend depends on these objects to set access rights, limit data loads, ++++ (I am not using any specific framework) My controllers have different ways of…
user3159921
  • 65
  • 1
  • 5
0
votes
1 answer

How does PHP-DI Symfony Bridge work and how to set up it correctly?

I have some problems by getting the PHP-DI 6 & Symfony 4 combination working. So I'd like to get a deeper understanding, how this works / should work and check, whether I actually configured it correctly. Symfony uses by default its own DI…
automatix
  • 14,018
  • 26
  • 105
  • 230
0
votes
1 answer

Referencing PHP-DI definitions defined as multi-dimensional arrays

If I have an array of definitions like below, the injection of a RouteCollector instance in other objects is executed perfectly: use MyApp\Routing\RouteCollector; return [ 'router.options.routeParser' => 'FastRoute\\RouteParser\\Std', …
user7941334
0
votes
1 answer

Php-Di annotations performance

Can anyone explain me what is better regarding performace in Php-Di? Using annotations or plain constructor params? Annotations = less chars to write but is it a good practice? class A { /** * @Inject * @var B **/ private $b; …
piernik
  • 3,507
  • 3
  • 42
  • 84
0
votes
1 answer

PHP-DI Can't inject created class with constructor parameters

I try to make a project with PHP-DI but i have a problem. This is the trace: Here is the code: Container class: $this->containerBuilder->addDefinitions([ 'Configuration' =>…
Jean Walrave
  • 191
  • 1
  • 2
  • 13