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
5
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…
user3159921
  • 65
  • 1
  • 5
4
votes
5 answers

How to log every query from multiple connections in Eloquent (outside laravel)

I use multiple database connections in my app, one SQLServ, and another MySQL. I want to debug every query from both servers sequentially. therefore rather using Manager::getQueryLog() i need to use Event::listen. I use SlimFramework, with…
Egy Mohammad Erdin
  • 3,402
  • 6
  • 33
  • 57
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
  • 1,398
  • 1
  • 12
  • 27
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
  • 840
  • 9
  • 19
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
  • 7
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
  • 2,263
  • 1
  • 25
  • 49
4
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
  • 831
  • 1
  • 10
  • 19
3
votes
1 answer

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
  • 485
  • 6
  • 11
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
  • 247
  • 2
  • 10
3
votes
2 answers

Injecting parameters into constructor with PHP-DI

I am struggling to get dependency injection to work the way I expect - I am trying to inject a class, Api, which needs to know which server to connect to for a particular user. This means that overriding constructor properties in a config file is…
PointToPoint
  • 117
  • 1
  • 3
  • 12
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
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
  • 750
  • 1
  • 7
  • 24
2
votes
1 answer

PHPUnit test specific method of class with dependencies

After reading quite some docs I came up with this function to test the service method findAllUsers. I first create a stub of the repository, then tell what the relevant method findAllusers returns (yes they have the same name in repo and service)…
Samuel Gfeller
  • 840
  • 9
  • 19
2
votes
1 answer

Sharing the same instance of an object: auryn vs. PHP-DI

I am trying to build my first no-framework PHP application and I am following this tutorial. I am relatively new to some concepts described in the tutorial. Despite this, I decided to use, as Dependency Injector, PHP-DI instead of the suggested one…
Filippo Lauria
  • 1,965
  • 14
  • 20
1
2 3 4 5 6 7