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:

91 questions
4
votes
3 answers

Dependency injection in PHP (slim, php-di)

I have a Slim Php (slim4) application to which I added Monolog for logging purposes. I'm adding the logger to the application like this: $containerBuilder->addDefinitions([ LoggerInterface::class => function (ContainerInterface $c) { $logger…
S. Roose
  • 831
  • 6
  • 21
4
votes
2 answers

How to set up and inject multiple PDO database connections in slim 4?

I could make an instance of PDO and inject it successfully. I defined the PDO::class directly and injected it in the constructor with __construct(PDO $pdo). I would need something like PDO1::class and PDO2::class to inject it like follows:…
Samuel Gfeller
  • 328
  • 3
  • 12
4
votes
1 answer

PHP DI - cannot be resolved Parameter $logger of __construct() has no value defined or guessable

I am trying to get a basic example of PHP-DI work, but I simple to be stuck at a fairly basic example. I assume I am missing something simple here, but have not been able to single it out. It is not recognising the LoggerInterface type hinting, but…
4
votes
1 answer

PHP-DI - Differences between Factories and Objects

PHP-DI allows some methods to define injections, including factories and objects: http://php-di.org/doc/php-definitions.html. Factories: TestClass::class => function () { return new TestClass('param'); } The TestClass instance is created…
Bob
  • 159
  • 6
4
votes
1 answer

PHP-DI injectOn not injecting on setter methods

I have setup dependencies and definitions while configuring the container using the ContainerBuilder and then compiling it to get the actual Container, but whenever I try injecting dependencies they always tend to be ignored. Have I missed the…
4
votes
1 answer

PHP-DI No entry or class found for 'interface name'

So, I'm trying to set up php-di for the first time, but I'm having some trouble with the builder. I keep getting the error: Uncaught exception 'DI\NotFoundException' with message 'No entry or class found for 'IConnection'' in…
iHowell
  • 1,819
  • 18
  • 40
3
votes
1 answer

How to call for a monolog from the index.php?

There is example of using Monolog with PHP-DI (from manual, there are 2 files - index.php and config.php:
szerz
  • 237
  • 1
  • 9
3
votes
1 answer

PHP-DI annotation not working

I have installed php-di 4.4 in a new custom project using composer.Im runing a xampp localhost with php 5.6.3 but I set netbeans for php 5.4 on this project. Im new to php-di, I did use annotations in my android projects but cant seem to make it…
MrDrishu
  • 100
  • 8
3
votes
1 answer

How can I override a DI container dependency with a specific instance?

Imagine we have a Request object and a Controller object. The Controller object is constructed with a Request object, like so: abstract class Controller { public $request; public function __construct(Request $request) { …
Mark Locker
  • 781
  • 1
  • 8
  • 18
2
votes
2 answers

PHP-DI Potentially polymorphic call when using the set method

The issue I have an unexpected warning from PHPStorm when I try to set a new value in a PHP-DI container. Given the following code: function inject(Psr\Container\ContainerInterface $container){ $container->set(RandomClass::class, new…
Noah Boegli
  • 558
  • 6
  • 21
2
votes
2 answers

How to access slim4's routeParser with the PHP-DI setup demonstrated in Slim-Skeleton?

I've set up a new app based on the SlimPHP team's Slim Skeleton application. Inside of my route definitions, I want to be able to access the route parser as described in the Slim4 documentation. So, for example, I'd like to be able to edit the…
davidreedernst
  • 445
  • 6
  • 8
2
votes
1 answer

Dependency injection cannot be handled using php-di

This is a problem that drove me crazy for over one week. I installed php-di via composer and added my own project to the composer.json file: { "name": "mypackage/platform", "description": "MyPackage Platform", "type": "project", …
Belkin
  • 187
  • 10
2
votes
0 answers

Definitions in dependency injection via php-di

Getting my head wrapped around dependency injection with php-di, but I'm obviously not doing something right. Wondering if someone could tell me what I'm doing wrong. Ok, have a bootstrap.php file, no namespace in it, and looks something…
Envrin
  • 19
  • 1
2
votes
1 answer

Inject mock objects using PHP-DI for testing controllers with PHPUnit

I have refactored some of my controllers to use dependency injection via property injection as recommended in the "best practices": final class ZebraController extends Controller { /** * @Inject * @var AnimalClientInterface */ …
rink.attendant.6
  • 36,468
  • 57
  • 89
  • 143
2
votes
1 answer

PHP-DI: create vs. autowire vs. get. Or how to correctly map an interface to an implementation provided by a definition

For my PHP-DI container in a web MVC I prepared the following definition for a router: return [ 'router' => function (ContainerInterface $c) { //... return new Router(...); } ]; Now I want to map an interface…
dakis
  • 225
  • 1
  • 6
  • 32
1
2 3 4 5 6 7