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

PHP-DI DI\env() method doesn't work when using with symfony/dotenv or vlucas/phpdotenv

Since it's not recommended to use getenv() and symfony/dotenv, vlucas/phpdotenv have disabled it by default, how is it possible to configure DI\Definition\Resolve\EnvironmentVariableResolver to use custom $variableReader constructor parameter?
yanot
  • 345
  • 4
  • 17
1
vote
1 answer

Slim Framework : How to break circular dependency injection?

I'm using Slim 4.5.0 with PHP-DI 6 and I've a circular dependency issue. I know how to solve this kind of issue using a setter, but in the context of SlimFramework, I can't get anything to work. I want to send message to a Slack Channel when an…
Thomas
  • 1,231
  • 14
  • 25
1
vote
0 answers

Inject data in constructor dynamically using Ray Di

I'm trying to use ray di to inject data in the constructor. But I am having some problem. Here is my code
John
  • 21
  • 3
1
vote
1 answer

PHP-DI container configuration

This is a follow-on to my previous question (which was poorly scoped) which made me realize I had more I needed to learn about DI: Dependency injection, composition root, and entry points Can someone explain what aspect of dependency injection and…
Brian
  • 642
  • 7
  • 18
1
vote
0 answers

PHP-DI: How to create interface implementation with custom constructor parameter value?

I'm using php-di 6.0.10 I have the interface implementation in my DI config: \App\Writer\WriterInterface::class => DI\get(\App\Writer\Text::class) It has constructor like this: class TextWriter implements WriterInterface ... public function…
Audiophile
  • 970
  • 2
  • 8
  • 20
1
vote
1 answer

How is possible to execute a piece of code when an object is created in PHP-DI?

I set up my dependencies with \DI\Container like this: $this->container = new \DI\Container(); $this->container->set('AdyenClient', \DI\create('\Adyen\Client')); $this->container->set('AdyenCheckout',…
1
vote
2 answers

PHP-DI says missing parameter while in definition file has set

I am new to PHP-DI and I really do not understand what do I miss. I have a container: $definitonFile = __DIR__ . '/app/etc/di_config.php'; $containerBuilder = new…
vaso123
  • 12,347
  • 4
  • 34
  • 64
1
vote
1 answer

PHP-DI: Does in any way matter, in which order the definition files are loaded into the container?

I plan to have many definitions files (e.g. configuration files), in separate directories and multiple-level subdirectories. Let's suppose, that these files will contain many complex definition situations - so to say. So I would like to ask: Does IN…
PajuranCodes
  • 303
  • 3
  • 12
  • 43
1
vote
1 answer

Using PHPUnit with PHP-DI

I'm using the PHP-DI library and it works great for my code by using a bootstrap and config file, as recommended by the PHP-DI documentation. Then, in my app, I'm getting the container and kicking things off by calling the bootstrap: $container =…
1
vote
2 answers

PHP-DI Call a method which have default parameter to null

I'm trying to use a PHP-DI Call on a method which have a default parameter but i get this error Fatal error: Uncaught Invoker\Exception\NotEnoughParametersException: Unable to invoke the callable because no value was given for parameter 1... PS :…
Ray Carnegie
  • 103
  • 1
  • 7
1
vote
1 answer

How to get instance of PHP-DI container from any class I want?

I am using PHP-DI 6 Container in my PHP Project. At the very begging of my program I just initialize the container and get Application class with all dependencies injected. $container = new Container(); $application =…
NanoBreaker
  • 67
  • 12
1
vote
0 answers

How to use services defined in PHP-DI in the Symfony's services.yaml?

I'm writing an application, that has a structure of a Symfony application and some Symfony functionality, but should be decoupled from the framework as possible. So instead of the framework's DI, I'm using PHP-DI. Now I need Symfony's…
automatix
  • 14,018
  • 26
  • 105
  • 230
1
vote
1 answer

How to register event listeners in Symfony 4?

I'm writing a Symfony application. Means: The application has a structure of a Symfony application and uses Symfony's MVC (symfony/http-kernel, symfony/routing etc.), but it should be as framework-independent as possible. So instead of the…
automatix
  • 14,018
  • 26
  • 105
  • 230
1
vote
1 answer

Autowire all classes in config or

I use php-di for autoloading classes in my API-Application. For speed, however, php-di states that you have to autowire the classes manually for compilation. So they give us this example: return [ // ... (your definitions) UserController::class…
sridesmet
  • 875
  • 9
  • 19
1
vote
1 answer

How to use autowire(...), create(...), and get(...) in definitions for PHP-DI?

PHP-DI 6 provides multiple functions, that working in the definitions. Three of them seem to do the same in the definitions context: autowire(...), create(...), and get(...). E.g. I have following…
automatix
  • 14,018
  • 26
  • 105
  • 230