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
1
vote
1 answer

How to use the PHP-DI Symfony Bridge for Controllers?

I want to use my recently set up Symfony 4 project with PHP-DI 6 and PHP-DI Symfony Bridge 3. My project structure looks like…
automatix
  • 14,018
  • 26
  • 105
  • 230
1
vote
1 answer

PHP-DI 5: Caching of values and definitions

I am using the PHP-DI 5 dependency injection container and I have already read the documentation about the definitions caching. Though I am still not sure in this regard... So I would like to ask you: 1) If I directly set an object as an entry value…
user7941334
1
vote
2 answers

PHP-DI inject parameter by name

I am using php-di and Doctrine together. To use Doctrine there is a bootstrap.php file which constructs the $entityManager object. The $entityManager object is defined globally in that file so to use it in my classes I have to inject it. For example…
ConductedClever
  • 4,175
  • 2
  • 35
  • 69
1
vote
2 answers

Adding one regular variable to auto-wired function

I'm using Slim Framework with PHP-DI to autowire dependencies for me. But one dependency is just a regular array. If I put a regular array into my container configuration, then all arrays will be set to that one array. So my primary question would…
ADJenks
  • 2,973
  • 27
  • 38
1
vote
2 answers

In PHP-DI the has() function not working for definition in file

Using a php definition file I have created this definition return [ 'auth' => \DI\object('MyProject\Users\Handlers\Permissions')->lazy() ]; But when I use the has() function to check if the definition exists i.e. $container->has('auth'); //this…
Stanley Ngumo
  • 4,089
  • 8
  • 44
  • 64
1
vote
1 answer

PHP-DI Register Instance for ctor Injection

I'm using php-di and am using twig in my project. I'd like to register the instance of $twig with php-di so that its instance is injected into the ctor argument on objects where it's needed. I'd like to use php definitions and avoid phpdoc…
Chris Klepeis
  • 9,783
  • 16
  • 83
  • 149
1
vote
1 answer

Getting started PHP-DI without any 3rd party framework

I am just now discovering dependency injection and I want to apply it to a medium sized project which I've been working on. I already have a classes folder which holds all the classes used in the system /application/core/classes I would like to…
Stanley Ngumo
  • 4,089
  • 8
  • 44
  • 64
0
votes
0 answers

Is it possible to get all dependencies implementing a certain interface using PHP-DI?

Using PHP-DI, it is possible to get a dependency using: $container->get(MyDependency::class). Can I use a similar method to automatically get all dependencies implementing a certain interface?
Mat
  • 833
  • 1
  • 5
  • 20
0
votes
0 answers

Slim4 and PHP-DI doesn't inject using annotation

I'm migrating a project from an older version of Slim and PHP-DI to the last one and PHP 8.1.17. These are the composer dependency for slim and php-di: "slim/slim" : "~4.11", "php-di/php-di" : "^7.0.2", PHP-DI annotation doesn't work like the…
Tobia
  • 9,165
  • 28
  • 114
  • 219
0
votes
0 answers

Slim with PHP-DI: Using a DTO as controller method parameter?

I'm using the PHP Slim Framework V4 to build an API with php-di/slim-bridge to have dependency injection within the controller methods. What's the best practice when working with DTOs for incoming requests in Slim Framework v4? I'd like to use DTOs…
CRaSH3k
  • 11
  • 1
0
votes
1 answer

Dependency Injection inside a service utility class using php-di

In my Slim v4, application, I am setting up the container definitions as below. $containerBuilder = new ContainerBuilder(); $containerBuilder->useAttributes(true); $containerBuilder->addDefinitions([ MailerInterface::class => function…
Purus
  • 5,701
  • 9
  • 50
  • 89
0
votes
1 answer

PHP-DI Suddenly throws 'No entry or class found' error in production server

I have a PayPal integration and for it, I have a Controller and Service class. For the controller:
deymbwoi
  • 125
  • 3
  • 10
0
votes
0 answers

PHP-DI / Definition for resolving every time a new object

i am trying to update phpdi from 5.4.6 to 6.4 and i don't know how to write a definition for objects which should be created everytime it is injected. In 5.4.6 i simly wrote return [ 'setasign\\Fpdi\\Fpdi' =>…
0
votes
0 answers

How to access PDO instance created with DI in dependencies.php

How do I get the PDO connection in my model class that was created in dependicies.php? I have Controller and Model classes. My route: $app->group('/users', function (Group $group) { $group->get('', [UsersController::class, 'getAll'], function…
Scott Logsdon
  • 71
  • 1
  • 4
0
votes
0 answers

Slim 4 php-di Factory function not running as expected / not "fully" called

i'm having problems registering a factory causing a strange behaviour. When my dependency is resolved by the factory function i can see (by testing..), that actually only the constructor is called, nothing more. Here's the factory function + DI…
mademyday
  • 83
  • 2
  • 9