Skip to content

Conversation

@MacFJA
Copy link

@MacFJA MacFJA commented Sep 20, 2015

Extract from the class docblock

Class AliasFactory.

Alias factory allow you to define class alias to reduce class name.
For example, instead of:

$object = $factory->getInstance('\\My\\Super\\Application\\Entity\\User');

You can just define an alias and class it:

$factory->registerAlias('\\My\\Super\\Application\\Entity\\User', 'User');

//... later in your code

$object = $factory->getInstance('User');

(Of course, in most of case we use use \My\Super\Application\Entity\User and
$object = $factory->getInstance(User.class) which is already a short syntax).

But you can also define factory override.
Let's imagine that your project have a \SomeOne\Framework\Application class, but have have extend it in your class \My\Framework\Application.
To shameless use your class instead of their, just do:

use \SomeOne\Framework\Application as BaseApplication;
use \My\Framework\Application;

$factory->registerAlias(BaseApplication.class, Application.class);

Now $factory will return \My\Framework\Application when you ask the factory for \SomeOne\Framework\Application

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.

1 participant