Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 28 19:30
  • Jan 27 15:53
    mforest-gsu starred PHP-DI/PHP-DI
  • Jan 27 12:33
    rustamr1991 opened #846
  • Jan 27 12:28
  • Jan 27 12:09
    rustamr1991 opened #845
  • Jan 26 21:19
    sahil1572 starred PHP-DI/PHP-DI
  • Jan 26 13:36
    btalanski starred PHP-DI/PHP-DI
  • Jan 25 13:03
  • Jan 25 03:26
    renakdup starred PHP-DI/PHP-DI
  • Jan 22 18:48
    Gounlaf commented #844
  • Jan 22 18:43
    hemberger commented #844
  • Jan 22 18:35
    Gounlaf commented #844
  • Jan 22 18:35
    Gounlaf commented #844
  • Jan 22 17:57
    Gounlaf commented #844
  • Jan 22 17:55
    mnapoli commented #844
  • Jan 21 16:50
    hemberger commented #844
  • Jan 21 15:19
    mnapoli commented #844
  • Jan 20 12:50
    Gounlaf edited #844
  • Jan 20 12:48
    Gounlaf opened #844
  • Jan 19 13:21
    reypm starred PHP-DI/PHP-DI
Andrew Vehlies
@avehlies
I suppose something might be able to be done with "autoload": { "files": "some/dir/of/handlers" } in composer.json and then loop through get_declared_classes() and check if they implement?
Andrew Vehlies
@avehlies
turns out that's not the case since composer's classmap autoload won't list a class in get_declared_classes() until it's actually requested
Mario P
@mario-p_gitlab
Does PHP-DI support similar functionality to Symfony service tagging?
Currently, what I am doing to replicate tagging is via arrays defined in the DI container
Mario P
@mario-p_gitlab
'my-tag-1' => [get(Service1), get(Service2)]
Anaël Ollier
@nanawel
@mario-p_gitlab Not to my knowledge. That would be handy though.
Mario P
@mario-p_gitlab
I was thinking of adding 2 new features,
Service::class => autowire()->tag('tag-1')
and
SomeOtherService::class => autowire()->constructorParameter('some-collection', getByTag('tag-1'))
Andrei Dascalu
@andrei-dascalu
Hi everyone, wondering if there's anyone around
Is it possible to use @Inject annotation to extra a value from an array? (eg, I have 'config' => ['item' => 1, 'test' => 2 ] and I would like to inject config['item'] on a private class member)
devrieswebsolutions
@devrieswebsolutions
Can anybody help me with this error: Too few arguments to function App\Model\DbObject::__construct(), 0 passed in C:\laragon\www\newswebsite\src\Model\DbObject.php
Aguirre, Lautaro Wenceslao
@thisbar
Hi. Does PHP-DI support PHP Attributes for doctrine?
yannlo
@yannlo
Hi i have a question please,
it's maybe stupide but PHP-DI create all instances injected when build container or when I use get Method ?
Marko Antolović
@bronhy
I am not sure since I don't know php-DI that well but maybe this helps.
Some DIs have lazy loading. But usually the default behavior is that the instances are created before they are injected.
I guess its written in docs how it is with php-DI
AUTOHAUSEN® AG
@autohausen
Hey guys, is it possible to override the definition of an interface for a specific class?
More context: I want "LoggerInterface" to be created as a FileLogger, but for a specific class I want LoggerInterface to be created as AnotherFileLogger without hardcoding the param name (constructorParam) in my DI config. I'd like to do something like: MyClass::class => [ LoggerInterface::class => AnotherFileLogger::class ]
Is such a thing implemented?
Daniel Opitz
@odan
@autohausen You could use a LoggerFactory for this specific class.
AUTOHAUSEN® AG
@autohausen

@autohausen You could use a LoggerFactory for this specific class.

This would require me to use the param-name instead of the interface-name.

Example:

MyClass::class => \DI\autowire()
->constructorParameter('log', MyLogger::class)

I don't like that solution because I have to use class internals within my di-config. Something like that would be much better:

MyClass::class => \DI\autowire()
->override(LoggerInterface::class, MyLogger::class)

I checked the docs but it seems php-di does not support that approach. Anyways. I will stick with the factory approach :-/

AUTOHAUSEN® AG
@autohausen

Since I try to solve my issue with the factory approach, there is another question: is there a way to get the "target class" within the factory? There is a \DI\Factory\RequestedEntry but this just provides the name of the requested interface (i.e. LoggerInterface). I'd like to somehow get the name of the class requesting that dependency (in my case this would be MyClass::class).

Is that possible somehow?

Daniel Opitz
@odan
This was not what I meant. If you just let the DI container inject a LoggerFactory into your class (object) via the constructor (autowiring) you can create a custom logger per class. So you don't need a DI container definiton for each class of your application.
AUTOHAUSEN® AG
@autohausen

@odan Thanks for your reply. Injecting a LoggerFactory into my "business" classes moves the configuration and the complexity to the wrong place. My classes just depend on \Psr\Log\LoggerInterface. Anything else is bad design imho.

I decided to stick with this solution:

  1. Convention: always call the ctor-param $log (yikes)

  2. Set the custom logger by explicitly defining the ctor-param:

    SomeService::class => \DI\autowire()
    ->constructorParameter('log', \DI\factory(function(LoggerFactory $loggerFactory){
    return $loggerFactory->create('/var/log/my.log');
    })),

I don't like it that much, but ey - it works.

Vladimir
@palansher

Hello guys!

I did not get the idea with @Inject annotations for methods.
https://php-di.org/doc/annotations.html

For example, from doc:

/**

 * Annotation combined with the type-hint:
 *
 * @Inject
 */
public function method1(Foo $param)
{
}

I hope I can call $this->method1() and the object of Foo class will be created and injected as parameter authomatically.
But, obviously, I get "too few arguments Error" while calling.
Please help me understand the idea: how to inject objects as method's argument.

Mandeep Sharma
@mandeephub
Hi
im getting this error when i write inster query
https://prnt.sc/k-UaNIq81eUZ
Mandeep Sharma
@mandeephub
this is the code

<?php

include 'config.php';

if(isset($_POST["Submit"])){

$tasknamevar = $_POST['taskname'];

//echo($tasknamevar);

INSERT INTO tasks (taskname)
VALUES ('Cardinal');

echo($tasknamevar);

}

?>

<form method="post">

<input type="text" name="taskname" required>
<input type="submit" value="Submit" name="submit">

</form>