diff --git a/Module.php b/Module.php index e482640..a9728a8 100644 --- a/Module.php +++ b/Module.php @@ -3,13 +3,25 @@ namespace ZfcUserDoctrineORM; use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Zend\EventManager\EventInterface; +use Zend\ModuleManager\Feature; +use Zend\ServiceManager\ServiceManager; +use ZfcUserDoctrineORM\Factory; +use ZfcUserDoctrineORM\Mapper; +use ZfcUserDoctrineORM\Options; +use Doctrine\ORM\EntityManager; + class Module + implements Feature\AutoloaderProviderInterface, Feature\BootstrapListenerInterface, Feature\ServiceProviderInterface { - public function onBootstrap($e) + public function onBootstrap(EventInterface $e) { - $app = $e->getParam('application'); - $sm = $app->getServiceManager(); + $app = $e->getParam('application'); + /** @var ServiceManager $sm */ + $sm = $app->getServiceManager(); + + /** @var Options\ModuleOptions $options */ $options = $sm->get('zfcuser_module_options'); // Add the default entity driver only if specified in configuration @@ -19,6 +31,9 @@ public function onBootstrap($e) } } + /** + * @return array + */ public function getAutoloaderConfig() { return array( @@ -33,27 +48,27 @@ public function getAutoloaderConfig() ); } + /** + * @return array + */ public function getServiceConfig() { return array( - 'aliases' => array( - 'zfcuser_doctrine_em' => 'Doctrine\ORM\EntityManager', + 'aliases' => array( + 'zfcuser_user_mapper' => Mapper\User::class, + 'zfcuser_module_options' => Options\ModuleOptions::class, + 'zfcuser_doctrine_em' => EntityManager::class, ), 'factories' => array( - 'zfcuser_module_options' => function ($sm) { - $config = $sm->get('Configuration'); - return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array()); - }, - 'zfcuser_user_mapper' => function ($sm) { - return new \ZfcUserDoctrineORM\Mapper\User( - $sm->get('zfcuser_doctrine_em'), - $sm->get('zfcuser_module_options') - ); - }, + Mapper\User::class => Factory\UserMapperFactory::class, + Options\ModuleOptions::class => Factory\ModuleOptionsFactory::class, ), ); } + /** + * @return array + */ public function getConfig() { return include __DIR__ . '/config/module.config.php'; diff --git a/config/module.config.php b/config/module.config.php index d401bba..0520476 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,17 +1,18 @@ array( 'driver' => array( 'zfcuser_entity' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\XmlDriver', - 'paths' => __DIR__ . '/xml/zfcuser' + 'paths' => __DIR__ . '/xml/zfcuser', ), 'orm_default' => array( 'drivers' => array( - 'ZfcUser\Entity' => 'zfcuser_entity' - ) - ) - ) + 'ZfcUser\Entity' => 'zfcuser_entity', + ), + ), + ), ), ); diff --git a/src/ZfcUserDoctrineORM/Factory/ModuleOptionsFactory.php b/src/ZfcUserDoctrineORM/Factory/ModuleOptionsFactory.php new file mode 100644 index 0000000..34c2b56 --- /dev/null +++ b/src/ZfcUserDoctrineORM/Factory/ModuleOptionsFactory.php @@ -0,0 +1,19 @@ +get('Config'); + + return new ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array()); + } +} diff --git a/src/ZfcUserDoctrineORM/Factory/UserMapperFactory.php b/src/ZfcUserDoctrineORM/Factory/UserMapperFactory.php new file mode 100644 index 0000000..523ae3c --- /dev/null +++ b/src/ZfcUserDoctrineORM/Factory/UserMapperFactory.php @@ -0,0 +1,23 @@ +get('zfcuser_doctrine_em'), + $serviceLocator->get('zfcuser_module_options') + ); + } +}