Get an abstract defined service from an alias #5752

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@jmleroux
Contributor

When you want to get a service leading to to an abstract factory from an alias.

I ended up with this issue when trying to get a cache instance wich i defined in my configuration :

return array(
    'service_manager' => array(
        'abstract_factories' => array(
            'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
        ),
        'aliases' => array (
            'app_cache' => 'memcached',
        ),
    ),
    'caches' => array(
        'memcached' => array(
            'adapter' => array(
                'name' => 'memcached',
                // other config values...
            ),
        ),
    ),
)

The purpose is to be able to change the cache by changing the alias.

Without this PR, ZF try to create this service :

$this->canCreateFromAbstractFactory('memcached', 'cache_core');

but 'cache_core' is not a cache configuration key.

@jmleroux jmleroux Get an abstract defined service from an alias
When you want to get a service leading to to an abstract factory from an alias.
ac1f8c1
@blanchonvincent
Contributor

Hey @jmleroux, can you provide unit tests ?

@jmleroux
Contributor

I can't run ServiceManager test group.
I can run all groups, but it's a bit long to run to validate my tests.

How can i run ServiceManager group ?

My try :

php run-tests.php -g ZendTest/ServiceManager
@jmleroux
Contributor

Note : we would not have this problem without the $name in the method canCreateServiceWithName
see #5755

@Ocramius
Member
Ocramius commented Feb 2, 2014

This is not supported. I simply disallow service aliases for DoctrineModule's services, for example.

This is fixed with #5500 and won't land in 2.x

@jmleroux
Contributor
jmleroux commented Feb 2, 2014

OK, i'll do without.
I there a link available to an article or discussion explaining why removing aliases ?

I used them a few times and found them useful

@Ocramius
Member
Ocramius commented Feb 2, 2014

@jmleroux not removing them, just pushing them out as "non-core" feature - they work exactly like before

Aliases and normalization make work for abstract factories a real pain. The combination of the two is even worse :-)

@jmleroux
Contributor
jmleroux commented Feb 2, 2014

OK for ZF3.

But my fix is a simple one and makes aliases work with abstract factory.
Why not considering it until the release of ZF3 ?

@jmleroux
Contributor
jmleroux commented Feb 2, 2014

I see that the problem has already been raised : #5535
But my fix is way more simple.

@Ocramius
Member
Ocramius commented Feb 2, 2014

Indeed, this solution is way simpler

@jmleroux
Contributor

ping @Ocramius
Some news about this PR ?
Just to know if I can rely on "aliased abstract factories" before ZF3 ?

@Ocramius
Member

@jmleroux the PR looks good to me

@jmleroux
Contributor

Any change to see it merged ?

chat-potte

@weierophinney weierophinney added this to the 2.2.6 milestone Mar 3, 2014
@weierophinney weierophinney self-assigned this Mar 3, 2014
@weierophinney weierophinney added a commit that referenced this pull request Mar 3, 2014
@weierophinney weierophinney [#5752] CS fixes
- multiline comment formatting, trailing whitespace
5877f43
@weierophinney weierophinney added a commit that closed this pull request Mar 3, 2014
@weierophinney weierophinney Merge branch 'hotfix/5752'
Close #5752
Fixes #5535
1ef51f6
@weierophinney weierophinney added a commit that referenced this pull request Mar 3, 2014
@weierophinney weierophinney Merge branch 'hotfix/5752' into develop
Forward port #5752
ea8fdd1
@jmleroux jmleroux deleted the jmleroux:patch-2 branch Mar 3, 2014
@weierophinney weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5752 from jmleroux/pat…
…ch-2

Get an abstract defined service from an alias
13d474d
@weierophinney weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#5752] CS fixes
- multiline comment formatting, trailing whitespace
b352d58
@weierophinney weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5752' f848448
@weierophinney weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5752' into develop fa1a9da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment