serlo-org/athene2-class-resolver

This package is abandoned and no longer maintained. No replacement package was suggested.

Zend Framework 2 Module that provides class resolving components for Athene2

1.0 2014-07-27 16:03 UTC

This package is not auto-updated.

Last update: 2020-03-02 04:35:29 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

The Athene2 Class Resolver is a Zend Framework 2 Module which lets you resolve classes like a bauss!. Using Interfaces for Doctrine Entities? No problem, the class resolver helps you find the right implementation!

Usage

In your module.config.php add:

    'class_resolver'  => [
        'My\ClassInterface' => 'My\CrazyClass'
    ]

Now you can easily resolve the interface either to a class name (which is useful for e.g. Doctrine Entities) or to a real class:

$classResolver = $serviceManager->get('ClassResolver\ClassResolver');
$className     = $classResolver->resolveClassName('My\ClassInterface');
$class         = $classResolver->resolve('My\ClassInterface');

echo $className; // prints "My\CrazyClass"
echo get_class($class); // prints "My\CrazyClass"

If you wish to instantiate the class through Zend's ServiceManager, do the following:

$classResolver = $serviceManager->get('ClassResolver\ClassResolver');
$class         = $classResolver->resolve('My\ClassInterface', true);

echo get_class($class); // prints "My\CrazyClass"