Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move of factories from module.php to module.config.php #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 30 additions & 15 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +31,9 @@ public function onBootstrap($e)
}
}

/**
* @return array
*/
public function getAutoloaderConfig()
{
return array(
Expand All @@ -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';
Expand Down
11 changes: 6 additions & 5 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

return array(
'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',
),
),
),
),
);
19 changes: 19 additions & 0 deletions src/ZfcUserDoctrineORM/Factory/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace ZfcUserDoctrineORM\Factory;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcUserDoctrineORM\Options\ModuleOptions;

class ModuleOptionsFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');

return new ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array());
}
}
23 changes: 23 additions & 0 deletions src/ZfcUserDoctrineORM/Factory/UserMapperFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace ZfcUserDoctrineORM\Factory;

use Zend\Db;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\Hydrator;
use ZfcUser\Mapper;
use ZfcUser\Options;

class UserMapperFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return new \ZfcUserDoctrineORM\Mapper\User(
$serviceLocator->get('zfcuser_doctrine_em'),
$serviceLocator->get('zfcuser_module_options')
);
}
}