__construct() public method

Constructor. Sets the initial configuration for the Form adapter, as detailed below.
See also: lithium\security\auth\adapter\Form::$_model
See also: lithium\security\auth\adapter\Form::$_fields
See also: lithium\security\auth\adapter\Form::$_filters
See also: lithium\security\auth\adapter\Form::$_validators
See also: lithium\security\auth\adapter\Form::$_query
public __construct ( array $config = [] ) : void
$config array Available configuration options: `'model'` _string_: The name of the model class to use. See the `$_model` property for details. `'fields'` _array_: The model fields to query against when taking input from the request data. See the `$_fields` property for details. `'scope'` _array_: Any additional conditions used to constrain the authentication query. For example, if active accounts in an application have an `active` field which must be set to `true`, you can specify `'scope' => array('active' => true)`. See the `$_scope` property for more details. `'filters'` _array_: Named callbacks to apply to request data before the user lookup query is generated. See the `$_filters` property for more details. `'validators'` _array_: Named callbacks to apply to fields in request data and corresponding fields in database data in order to do programmatic authentication checks after the query has occurred. See the `$_validators` property for more details. `'query'` _string_: Determines the model method to invoke for authentication checks. See the `$_query` property for more details.
return void
Exemplo n.º 1
0
 /**
  * Sets the initial configuration for the `Form` adapter.
  *
  * @see lithium\security\auth\adapter\Form::$__construct
  * @param array $config Sets the configuration for the adapter, which has the following options:
  *				- `'model'` _string_: The name of the model class to use. See the `$_model`
  *				  property for details.
  *				- `'fields'` _array_: The model fields to query against when taking input from
  *				  the request data. See the `$_fields` property for details.
  *				- `'scope'` _array_: Any additional conditions used to constrain the
  *				  authentication query. For example, if active accounts in an application have
  *				  an `active` field which must be set to `true`, you can specify
  *				  `'scope' => array('active' => true)`. See the `$_scope` property for more
  *				  details.
  *				- `'filters'` _array_: Named callbacks to apply to request data before the user
  *				  lookup query is generated. See the `$_filters` property for more details.
  *				- `'validators'` _array_: Named callbacks to apply to fields in request data and
  *				  corresponding fields in database data in order to do programmatic
  *				  authentication checks after the query has occurred. See the `$_validators`
  *				  property for more details.
  *				- `'query'` _string_: Determines the model method to invoke for authentication
  *				  checks. See the `$_query` property for more details.
  */
 public function __construct(array $config = array())
 {
     $config += array('model' => null, 'entityManager' => null, 'repositoryMethod' => 'findOneBy');
     if (empty($config['model']) || !class_exists($config['model'])) {
         throw new ConfigException("No valid model \"{$config['model']}\" available to use for Form auth adapter");
     } elseif (empty($config['entityManager']) && (!method_exists($config['model'], 'getEntityManager') || !is_callable($config['model'] . '::getEntityManager'))) {
         throw new ConfigException("The model {$config['model']} must define a getEntityManager() static method, or you must set the entityManager auth config variable");
     }
     $reflection = new \ReflectionClass($config['model']);
     if (!$reflection->implementsInterface('li3_doctrine2\\models\\IModel') && !$reflection->implementsInterface('li3_doctrine2\\models\\IUser')) {
         throw new ConfigException("The model {$config['model']} must implement IUser");
     }
     $entityManager = $config['entityManager'] ?: call_user_func($config['model'] . '::getEntityManager');
     if (!isset($entityManager) || !$entityManager instanceof EntityManager) {
         throw new ConfigException('Not a valid entity manager');
     }
     $this->repository = $entityManager->getRepository($config['model']);
     parent::__construct($config);
 }