Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : PSR-11 and get / has #21220

Closed
harikt opened this issue Sep 17, 2017 · 7 comments
Closed

Question : PSR-11 and get / has #21220

harikt opened this issue Sep 17, 2017 · 7 comments

Comments

@harikt
Copy link
Contributor

harikt commented Sep 17, 2017

  • Laravel Version: 5.5
  • PHP Version:
  • Database Driver & Version:

Description:

According to PSR-11 https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md#31-psrcontainercontainerinterface

Finds an entry of the container by its identifier and returns it.

Now if you have not registered anything the container always throws Illuminate\Container\EntryNotFoundException .

But Illuminate Container can create instances via make method. This is my take, if there is a concrete class, container should be able to create the object. Else throw the exception. The has method need to be modified for the same.

I am looking at an implementation
https://github.com/dms-org/web.laravel/blob/582d970393656a011ffcee4f6716ae79c5e57813/src/Ioc/LaravelIocContainer.php#L157 of psr-11 before 5.5 .

Steps To Reproduce:

<?php
require __DIR__ . '/vendor/autoload.php';

class Foo
{
    public function __construct()
    {
        echo "Constructed \n";
    }
}

$container = new \Illuminate\Container\Container();
$container->make(Foo::class);
$container->get(Foo::class);
@Dylan-DPC-zz
Copy link

This repo is for bug tracking. This isn't a bug so you can open a proposal in the laravel/internals repo

@devcircus
Copy link
Contributor

Seems like according to

Finds an entry of the container by its identifier and returns it.

it is pretty explicit that it "finds an entry" of the container by its "identifier". So just allowing Laravel's container to return a concrete, doesn't really fit. However I can see why this may be convenient.

@harikt
Copy link
Contributor Author

harikt commented Sep 18, 2017

@devcircus did you checked how the dms container is working ?

@themsaid
Copy link
Member

Please ask on the forums, this repo is for bug reporting only. You can use https://laracasts.com/discuss or https://laravel.io/forum which are forums with a very large community of developers helping each other.

@hakuno
Copy link

hakuno commented Aug 30, 2018

$container->get(Foo::class);

The Laravel's PSR-11 implementation is buggy. Because get doesn't work like make.

@golaod
Copy link

golaod commented Sep 21, 2020

$container->get(Foo::class);

The Laravel's PSR-11 implementation is buggy. Because get doesn't work like make.

I agree with you. If PSR-11 was added to let laravel devs replace that container with PSR-11 interface, then the entire logic which works in laravel's container should work the same under PSR-11 interface.

@driesvints
Copy link
Member

@golaod Laravel's container already makes use of PSR-11. get wasn't suppose to behave the same as make.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants