From 78217633223b467bf41196d0c964ded77bc2225d Mon Sep 17 00:00:00 2001 From: Johan van der Heide Date: Mon, 1 Aug 2016 10:21:13 +0200 Subject: [PATCH 1/3] Reworked the factories from Module.php to real factories to avoid missed overloading --- Module.php | 12 ---------- config/module.config.php | 22 +++++++++++++----- .../Factory/ModuleOptionsFactory.php | 19 +++++++++++++++ .../Factory/UserMapperFactory.php | 23 +++++++++++++++++++ 4 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 src/ZfcUserDoctrineORM/Factory/ModuleOptionsFactory.php create mode 100644 src/ZfcUserDoctrineORM/Factory/UserMapperFactory.php diff --git a/Module.php b/Module.php index e482640..e5d82b9 100644 --- a/Module.php +++ b/Module.php @@ -39,18 +39,6 @@ public function getServiceConfig() 'aliases' => array( 'zfcuser_doctrine_em' => 'Doctrine\ORM\EntityManager', ), - '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') - ); - }, - ), ); } diff --git a/config/module.config.php b/config/module.config.php index d401bba..9a89e1f 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,17 +1,27 @@ array( + 'service_manager' => array( + 'factories' => array( + 'zfcuser_user_mapper' => 'ZfcUserDoctrineORM\Factory\UserMapperFactory', + 'zfcuser_module_options' => 'ZfcUserDoctrineORM\Factory\ModuleOptionsFactory', + ), + 'aliases' => array( + 'zfcuser_register_form_hydrator' => 'zfcuser_user_hydrator', + 'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', + ), + ), + 'doctrine' => 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') + ); + } +} From cac508f0a52669046d5afedadd0457e9bf89be0c Mon Sep 17 00:00:00 2001 From: Johan van der Heide Date: Mon, 1 Aug 2016 10:31:09 +0200 Subject: [PATCH 2/3] Further cleanup of the module.php --- Module.php | 28 +++++++++++++++------------- config/module.config.php | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Module.php b/Module.php index e5d82b9..a7c38a9 100644 --- a/Module.php +++ b/Module.php @@ -3,13 +3,21 @@ namespace ZfcUserDoctrineORM; use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Zend\EventManager\EventInterface; +use Zend\ModuleManager\Feature; +use Zend\ServiceManager\ServiceManager; +use ZfcUserDoctrineORM\Options\ModuleOptions; -class Module + +class Module implements Feature\AutoloaderProviderInterface, Feature\BootstrapListenerInterface { - 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 ModuleOptions $options */ $options = $sm->get('zfcuser_module_options'); // Add the default entity driver only if specified in configuration @@ -19,6 +27,9 @@ public function onBootstrap($e) } } + /** + * @return array + */ public function getAutoloaderConfig() { return array( @@ -33,15 +44,6 @@ public function getAutoloaderConfig() ); } - public function getServiceConfig() - { - return array( - 'aliases' => array( - 'zfcuser_doctrine_em' => 'Doctrine\ORM\EntityManager', - ), - ); - } - public function getConfig() { return include __DIR__ . '/config/module.config.php'; diff --git a/config/module.config.php b/config/module.config.php index 9a89e1f..cf04de9 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -8,6 +8,7 @@ 'aliases' => array( 'zfcuser_register_form_hydrator' => 'zfcuser_user_hydrator', 'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', + 'zfcuser_doctrine_em' => 'Doctrine\ORM\EntityManager', ), ), 'doctrine' => array( From bb963a6c4e0f57ff4fa0898315e641bd0219f30a Mon Sep 17 00:00:00 2001 From: Johan van der Heide Date: Mon, 1 Aug 2016 12:02:09 +0200 Subject: [PATCH 3/3] Used the FQCN and moved the code to the Module.php to be in line with ZfcUser --- Module.php | 31 ++++++++++++++++++++++++++++--- config/module.config.php | 14 ++------------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Module.php b/Module.php index a7c38a9..a9728a8 100644 --- a/Module.php +++ b/Module.php @@ -6,10 +6,14 @@ use Zend\EventManager\EventInterface; use Zend\ModuleManager\Feature; use Zend\ServiceManager\ServiceManager; -use ZfcUserDoctrineORM\Options\ModuleOptions; +use ZfcUserDoctrineORM\Factory; +use ZfcUserDoctrineORM\Mapper; +use ZfcUserDoctrineORM\Options; +use Doctrine\ORM\EntityManager; -class Module implements Feature\AutoloaderProviderInterface, Feature\BootstrapListenerInterface +class Module + implements Feature\AutoloaderProviderInterface, Feature\BootstrapListenerInterface, Feature\ServiceProviderInterface { public function onBootstrap(EventInterface $e) { @@ -17,7 +21,7 @@ public function onBootstrap(EventInterface $e) /** @var ServiceManager $sm */ $sm = $app->getServiceManager(); - /** @var ModuleOptions $options */ + /** @var Options\ModuleOptions $options */ $options = $sm->get('zfcuser_module_options'); // Add the default entity driver only if specified in configuration @@ -44,6 +48,27 @@ public function getAutoloaderConfig() ); } + /** + * @return array + */ + public function getServiceConfig() + { + return array( + 'aliases' => array( + 'zfcuser_user_mapper' => Mapper\User::class, + 'zfcuser_module_options' => Options\ModuleOptions::class, + 'zfcuser_doctrine_em' => EntityManager::class, + ), + 'factories' => array( + 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 cf04de9..0520476 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,17 +1,7 @@ array( - 'factories' => array( - 'zfcuser_user_mapper' => 'ZfcUserDoctrineORM\Factory\UserMapperFactory', - 'zfcuser_module_options' => 'ZfcUserDoctrineORM\Factory\ModuleOptionsFactory', - ), - 'aliases' => array( - 'zfcuser_register_form_hydrator' => 'zfcuser_user_hydrator', - 'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', - 'zfcuser_doctrine_em' => 'Doctrine\ORM\EntityManager', - ), - ), - 'doctrine' => array( + 'doctrine' => array( 'driver' => array( 'zfcuser_entity' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\XmlDriver',