Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

pimple protect factory #91

Merged
merged 1 commit into from
Sep 1, 2016
Merged

Conversation

pine3ree
Copy link

@pine3ree pine3ree commented May 19, 2016

storing object having a callable __invoke() method requires using Pimple::protect().... I (foolishly) forgot this in my previous commit.

storing object having a callable `__invoke()` method requires using Pimple::protect()....forgot this in my previous commit.
@stubbetje
Copy link

Oh yes! I have been trying to debug this issue for to long. This solved it for me.

I was trying to create a factory class that is the factory for a number of objects

namespace App;

use Interop\Container\ContainerInterface;

class FooBarFactory
{
    public function __invoke( ContainerInterface $container, string $name )
    {
        switch( $name ) {
            case Foo::class:
                return new Foo;

            case Bar::class:
                return new Bar;

            default:
                throw new \InvalidArgumentException( '...' ):
        }
    }
}

And in config/dependencies.global.php:

return [
    'dependencies' => [
        'factories' => [
            Foo::class => FooBarFactory::class,
            Bar::class => FooBarFactory::class,
        ],
    ],
];

The first time, FooBarFactory was called like expected, with a fully qualified class name in $name.
But after that initial time, FooBarFactory kept being called without a $name argument.

First I thought it was not supposed to work this way, but when using zendframework/zend-servicemanager, then it works flawlessly.

The suggested change fixes this. So as far as I am concerned, this change should be merged...

Thx @pine3ree for making my day 😄

@pine3ree
Copy link
Author

@stubbetje
sorry i forgot this "not unsignificant" detail in my previous PR. It was long time ago, but this pr has not been merged yet: i guess devs have been very busy with zf3 packages upgrade.
kind regards

@weierophinney weierophinney added this to the 1.0.3 milestone Sep 1, 2016
@weierophinney weierophinney self-assigned this Sep 1, 2016
@weierophinney weierophinney merged commit 5db8b82 into zendframework:master Sep 1, 2016
weierophinney added a commit that referenced this pull request Sep 1, 2016
weierophinney added a commit that referenced this pull request Sep 1, 2016
weierophinney added a commit that referenced this pull request Sep 1, 2016
weierophinney added a commit that referenced this pull request Sep 1, 2016
@weierophinney
Copy link
Member

Thanks, @pine3ree

@pine3ree pine3ree deleted the patch-2 branch September 1, 2016 14:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants