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

Get an abstract defined service from an alias #5752

Closed
wants to merge 2 commits into from
Closed

Get an abstract defined service from an alias #5752

wants to merge 2 commits into from

Conversation

jmleroux
Copy link
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.

When you want to get a service leading to to an abstract factory from an alias.
@blanchonvincent
Copy link
Contributor

Hey @jmleroux, can you provide unit tests ?

@jmleroux
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@Ocramius
Copy link
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
Copy link
Contributor Author

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
Copy link
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
Copy link
Contributor Author

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
Copy link
Contributor Author

jmleroux commented Feb 2, 2014

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

@Ocramius
Copy link
Member

Ocramius commented Feb 2, 2014

Indeed, this solution is way simpler

@jmleroux
Copy link
Contributor Author

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

@Ocramius
Copy link
Member

@jmleroux the PR looks good to me

@jmleroux
Copy link
Contributor Author

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 added a commit that referenced this pull request Mar 3, 2014
Get an abstract defined service from an alias
weierophinney added a commit that referenced this pull request Mar 3, 2014
- multiline comment formatting, trailing whitespace
weierophinney added a commit that referenced this pull request Mar 3, 2014
@jmleroux jmleroux deleted the patch-2 branch March 3, 2014 22:14
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
…ch-2

Get an abstract defined service from an alias
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
- multiline comment formatting, trailing whitespace
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants