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

Add PSR-11 ContainerInterface support / Zend\ServiceManager #17

Merged
merged 1 commit into from
May 4, 2017

Conversation

bcremer
Copy link

@bcremer bcremer commented May 4, 2017

This adds return type detection for Psr\Container\ContainerInterface-style service locators.

$thing = $container->get(\MyApp\MyThing::class);
// $thing is type of \MyApp\MyThing

As discussed a while ago on twitter: https://gist.github.com/Haehnchen/aea3ac2d10cc709227815436de1e2ba2

This is especially useful for ZF3/Zend Expressive style Factories:

use Zend\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class MyObjectFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $dependency = $container->get(stdClass::class);
        return new MyObject($dependency);
    }
}

@Haehnchen Haehnchen merged commit 5864f5b into Haehnchen:master May 4, 2017
@Haehnchen
Copy link
Owner

thx

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

Successfully merging this pull request may close these issues.

2 participants