Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 13 04:24
    BinZhiZhu starred PHP-DI/PHP-DI
  • Apr 13 02:51
    ngocnd0242 starred PHP-DI/PHP-DI
  • Apr 12 15:17
    alessandromarotta starred PHP-DI/demo
  • Apr 12 10:33
    hultberg opened #771
  • Apr 12 07:30
    attitudefx7 starred PHP-DI/PHP-DI
  • Apr 10 14:33
    mnapoli closed #770
  • Apr 10 14:33
    mnapoli commented #770
  • Apr 10 14:31
    marcortola starred PHP-DI/PHP-DI
  • Apr 10 02:19
    curruwilla starred PHP-DI/PHP-DI
  • Apr 09 13:50
    sorinsarca commented #770
  • Apr 09 11:27
    n00dl3 commented #770
  • Apr 09 11:27
    n00dl3 commented #770
  • Apr 09 09:20
    n00dl3 commented #770
  • Apr 09 08:53
    mnapoli commented #770
  • Apr 09 08:52
    mnapoli labeled #770
  • Apr 08 10:23
    antonydevanchi starred PHP-DI/PHP-DI
  • Apr 08 07:41
    moussaclarke starred PHP-DI/PHP-DI
  • Apr 08 06:50
    321zeno starred PHP-DI/PHP-DI
  • Apr 07 08:09
    n00dl3 opened #770
  • Apr 07 02:50
    angelxmoreno starred PHP-DI/PHP-DI
Jack Price-Burns
@JackPriceBurns
Hello :wave: when using the autowiring to load classes, if the class can not be instantiated because of an exception the container just returns null, is this behaviour intended (I don't know if I've changed something) and is there any way I can make these exceptions get thrown out of the container so I can handle them myself?
dennis-0312
@dennis-0312

Hi. I have this problem, when I upload my project to a host this error activates me: Fatal error: Not captured DI \ NotFoundException: No entry or class was found for 'App \ Controllers \ AuthController' in /home/vrfctuqw/myhonsting.com/ vendor /php-di/php-di/src/Container.php:135 Stack tracking: # 0 /home/vrfctuqw/myhosting.com/vendor/php-di/php-di/src/CompiledContainer.php(64) : DI \ Container-> get ('App \ Controllers ...') # 1 /home/vrfctuqw/myhosting.com/public/index.php(474): DI \ CompiledContainer-> get ('App \ \ Controllers ... ') # 2 {main} included in /home/vrfctuqw/myhosting.com/vendor/php-di/php-di/src/Container.php on line 135

Locally it works correctly, but in hosting I present this. I would like you to help me please

Định Nguyễn Thế
@vatgia
I has a problem when i call a magic menthod in a class.
Sandunika Fernando
@sandunika_fdo_twitter
Hi I have used "mnapoli/php-di": "~4.0", "container-interop/container-interop": "^1.1", for my application and now im moving to php 7 with "php-di/php-di": "6.0.11", "psr/container": "^1.0.0", I'm getting "Entry "Idfix\Contracts\RegistryInterface" cannot be resolved: the class is not instantiable Full definition: Object ( class = #NOT INSTANTIABLE# Idfix\Contracts\RegistryInterface lazy = false )" this issue please advice
Stay The Fuck Home
@KipchirchirIan_twitter
Hello! So, after doing composer update I get a notice that the package jeremeamia/superclosure is abandoned and php-di seems to require/depend on this package. Any solutions to this problem especially that the recommendation is using opis/closure and it's not advisable to edit composer.lock directly??
Maciej Holyszko
@falkenhawk
Vitalijus Trainys
@tvitas
hi, why dependencies still exists to jeremeamia/superclosure? Its abandoned?
Sorry, not read RTFM :)
Closed.
Thanks.
Bram Van der Sype
@Brammm
When trying to compile my container, I'm getting a "The closure was not found within the abstract syntax tree" exception from jeremeamia/superclosure
Can anyone point me in the right direction of how to debug that? @mnapoli ?
The stack trace isn't exactly helpful
I previously had an error because I was using use ($var) in a closure, but took those out
Bram Van der Sype
@Brammm
Oh, apparently you can't use arrow functions
Jens Prangenberg
@jprangenbergde
Hi everyone, does anybody have knowledge about php-di and zend expressive? "I got Cannot compile closures which import variables using the use keyword'", but i cant find an use statement for the given Delegator. Some ideas?
Bram Van der Sype
@Brammm
@mnapoli still using Slim v3 with the php-di bridge, I upgraded composer and now suddenly getting the error "Class 'AssociativeArrayResolver' not found in /var/www/html/cache/CompiledContainer.php on line 1210"
What could be causing that?
Bram Van der Sype
@Brammm
It happened in the upgrade from php-di 6.1 to 6.2, I'm guessing it has something to do with the change of the closure thingy
Adam Bosco
@KuroTsuto

Hey all! I'm wondering if I can look up a key within a get()'d array in a autowire()->constructorParameter() somehow. This was my first stab, and I understand it doesn't work because get() is a definition helper, not an immediate lookup:

return [
  'config' => [
    'foo' => 'bar'
  ],

  'my.object' => autowire( MyClass::class )
    ->constructorParameter( 'foo', get( 'config' )[ 'foo' ] )
]

I understand that I could do this with a factory function, but I'm really curious as to if there is a way to do so without one?

rajabuitguy
@rajabuitguy_twitter
How do I use PHP-DI in codeigniter 4
aortizdeurbina
@aortizdeurbina
Hi, a query, how can I make a library I have generated, auto-inject into the application that uses it. Is this possible?

I tried something like this:

class CacheServiceProvider implements ServiceProviderInterface
{
/**

 * @param Container $pimple
 */
public function register(Container $pimple): void
{
    $pimple[CacheAdapter::class] = [self::class, 'getCache'];
}
But doesn't work!
Maciej Fikus
@maciejfikus

Hey guys, I've quick question as I do not understand it from docs.

How does @Inject work? It is said, that I can use it while I do not have control over object creation (i.e. some package).
The Object is created "by hand" somewhere (new Object(itsparams)) - then, I would like to inject some properties from container

I mean, it can't be used in this way, right? It can be used only if object itself is controllered by container?
suvarivaza
@suvarivaza
hi
are you here?
houguang
@houguang
hello
Mohamed Cherif Bouchelaghem
@cherifGsoul
Seems that factory function doens’t accept callable like:
class MyServiceFactory {
   public function __invoke(ContainerInterface $container)
  {
        //creation logic here!
  }
The issue is when compilation is enabled, without compilation everything work fine
Anyone faces this issue before?
to workaround this:
factory(function($container){
     return (new MyServiceFactory)->__invoke($container);
}),
Hans-Helge Buerger
@obstschale
Hey there, is there a way in PHP-DI to return always a new instance of a class. factory() returns always the same instance, but I need a new instance for every injection.
Anaël Ollier
@nanawel
Hi @obstschale In my understanding of the documentation and the current state of the library, you need to create a factory class yourself for this kind of need, and use something like Container->make(...) in order to force creating a new instance of your class.
Hans-Helge Buerger
@obstschale
Ok. Thx for your help
Ziyodjon
@iziyodjon
Hello everybody. I have questions about other files (css/js).
How I connect personal css file ? Thank you.
Mohamed Cherif Bouchelaghem
@cherifGsoul
Hi, how you guys organize dependencies without being a mess?
Split to bunch of arrays and merge them?
Maybe the question was asked before, I just would like to know if there is any pattern to follow?
Anaël Ollier
@nanawel

Hi @cherifGsoul There's no pattern, at least none that I know of. I personnally split the directives in 4 files, based on the "type" of them.

return array_merge(
    include 'sections/10-values.php',
    include 'sections/20-preferences.php',
    include 'sections/30-definitions.php',
    include 'sections/40-virtual.php'
);

Where "preferences", "definitions" and "virtual" are derived from what you can find in Magento 2 (just because I'm used to it).

  • values: keys are simple strings, often reused later, ex: 'app.base_url' => "some_value"
  • preferences: keys are interface names and define a preference for a given interface, ex: \App\BootstrapInterface::class => \DI\get(\App\Bootstrap::class)
  • definitions: keys are class names and define dependencies, ex: \App\Bootstrap::class => \DI\autowire()->constructorParameter(...)
  • virtual: keys are virtual class names and also define dependencies, ex: 'App\ApiBootstrap::class => \DI\autowire(\App\Bootstrap::class)->constructorParameter(...)
    So far, it covers all my cases :)
Mohamed Cherif Bouchelaghem
@cherifGsoul
@nanawel thanks you for sharing your approach, I really like it and give me ideas
Anaël Ollier
@nanawel
There's a mistake in the last line, the example should be 'App\ApiBootstrap' => \DI\autowire(\App\Bootstrap::class)->constructorParameter(...) (the key should be string, not a ::class)
Mohamed Cherif Bouchelaghem
@cherifGsoul
@nanawel Yeah I got it since is virtual
Anaël Ollier
@nanawel
:thumbsup:
Mohamed Cherif Bouchelaghem
@cherifGsoul
Plus this page in the docs https://php-di.org/doc/definition-overriding.html gives some insights about organizing big applications definitions.
Callum Hopkins
@caleuanhopkins
hi all, anyone know where i can find some documentation about using mocked service in PHPUnit with PHP-DI? we are using the annotations to inject services into our classes and need to be able to inject a mocked version of the service when running out PHPUnit tests
Miika Koskela
@mkoske
Hello, is there a way to get the class name that required specific dependency?
What I try to do, is that when I use Doctrine ORM, I want to use generic repository classes that are retrieved using EntityManager::getRepository("EntityName"). But I don't want to pass EntityManager itself only to get generic repository out of it so I was thinking if I just could typehint to generic EntityRepository class and somehow pass in the required "EntityName"
So I could in my service just typehint to generic EntityManager and get the requiring service class name and the name of the entity from that, e.g. UserService => UserEntity => UserRepository
Miika Koskela
@mkoske
Or should I just manually configure all my services?