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

Allow setting of custom user hydrator and user mapper from config file. #189

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,23 @@ public function getServiceConfig()
return $form;
},

'zfcuser_user_entity' => function ($sm) {
$entityClass = $sm->get('zfcuser_module_options')->getUserEntityClass();
return new $entityClass;
},

'zfcuser_user_hydrator' => function ($sm) {
$hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
return $hydrator;
$hydratorClass = $sm->get('zfcuser_module_options')->getUserHydratorClass();
return new $hydratorClass;
},

'zfcuser_user_mapper' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$mapper = new Mapper\User();
$mapperClass = $options->getUserMapperClass();
$mapper = new $mapperClass;
$mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter'));
$entityClass = $options->getUserEntityClass();
$mapper->setEntityPrototype(new $entityClass);
$mapper->setHydrator(new Mapper\UserHydrator());
$mapper->setEntityPrototype($sm->get('zfcuser_user_entity'));
$mapper->setHydrator($sm->get('zfcuser_user_hydrator'));
$mapper->setTableName($options->getTableName());
return $mapper;
},
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ The following options are available:
- **user_entity_class** - Name of Entity class to use. Useful for using your own
entity class instead of the default one provided. Default is
`ZfcUser\Entity\User`.
- **user_mapper_class** - Name of Mapper class to use. Useful for using your own
mapper class instead of the default one provided. Default is
`ZfcUser\Mapper\User`.
- **user_hydrator_class** - Name of Hydrator class to use. Useful for using your
own hydrator class instead of the default one provided. Default is
`ZfcUser\Mapper\UserHydrator`.
- **enable_username** - Boolean value, enables username field on the
registration form. Default is `false`.
- **auth_identity_fields** - Array value, specifies which fields a user can
Expand Down
16 changes: 16 additions & 0 deletions config/zfcuser.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ $settings = array(
*/
//'user_entity_class' => 'ZfcUser\Entity\User',

/**
* User Model Mapper Class
*
* Name of Mapper class to use. Useful for using your own mapper class
* instead of the default one provided. Default is ZfcUser\Mapper\User.
*/
//'user_mapper_class' => 'ZfcUser\Mapper\User',

/**
* User Model Hydrator Class
*
* Name of Hydrator class to use. Useful for using your own hydrator class
* instead of the default one provided. Default is ZfcUser\Mapper\UserHydrator.
*/
//'user_hydrator_class' => 'ZfcUser\Mapper\UserHydrator',

/**
* Enable registration
*
Expand Down
54 changes: 54 additions & 0 deletions src/ZfcUser/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ class ModuleOptions extends AbstractOptions implements
*/
protected $userEntityClass = 'ZfcUser\Entity\User';

/**
* @var string
*/
protected $userMapperClass = 'ZfcUser\Mapper\User';

/**
* @var string
*/
protected $userHydratorClass = 'ZfcUser\Mapper\UserHydrator';

/**
* @var string
*/
Expand Down Expand Up @@ -495,6 +505,50 @@ public function getUserEntityClass()
return $this->userEntityClass;
}

/**
* set user mapper class name
*
* @param string $userMapperClass
* @return ModuleOptions
*/
public function setUserMapperClass($userMapperClass)
{
$this->userMapperClass = $userMapperClass;
return $this;
}

/**
* get user mapper class name
*
* @return string
*/
public function getUserMapperClass()
{
return $this->userMapperClass;
}

/**
* set user hydrator class name
*
* @param string $userHydratorClass
* @return ModuleOptions
*/
public function setUserHydratorClass($userHydratorClass)
{
$this->userHydratorClass = $userHydratorClass;
return $this;
}

/**
* get user hydrator class name
*
* @return string
*/
public function getUserHydratorClass()
{
return $this->userHydratorClass;
}

/**
* set password cost
*
Expand Down