Horde_Auth_Sql::__construct PHP Method

__construct() public method

Constructor
public __construct ( array $params = [] )
$params array Parameters: 'db' - (Horde_Db_Adapter) [REQUIRED] Database object.
'encryption' - (string) The encryption to use to store the password in
               the table (e.g. plain, crypt, md5-hex, md5-base64, smd5,
               sha, ssha, aprmd5).
               DEFAULT: 'md5-hex'
'hard_expiration_field' - (string) The name of the field containing a
                          date after which the account is no longer
                          valid and the user will not be able to log in
                          at all.
                          DEFAULT: none
'password_field' - (string) The name of the password field in the auth
                   table.
                   DEFAULT: 'user_pass'
'show_encryption' - (boolean) Whether or not to prepend the encryption
                    in the password field.
                    DEFAULT: false
'soft_expiration_field' - (string) The name of the field containing a
                          date after which the system will request the
                          user change his or her password.
                          DEFAULT: none
'table' - (string) The name of the SQL table to use in 'database'.
          DEFAULT: 'horde_users'
'username_field' - (string) The name of the username field in the auth
                   table.
                   DEFAULT: 'user_uid'
    public function __construct(array $params = array())
    {
        if (!isset($params['db'])) {
            throw new InvalidArgumentException('Missing db parameter.');
        }
        $this->_db = $params['db'];
        unset($params['db']);
        $params = array_merge(array('encryption' => 'md5-hex', 'password_field' => 'user_pass', 'show_encryption' => false, 'table' => 'horde_users', 'username_field' => 'user_uid', 'soft_expiration_field' => null, 'soft_expiration_window' => null, 'hard_expiration_field' => null, 'hard_expiration_window' => null), $params);
        parent::__construct($params);
        /* Only allow limits when there is a storage configured */
        if (empty($params['soft_expiration_field']) && $params['soft_expiration_window'] > 0) {
            throw new InvalidArgumentException('You cannot set [soft_expiration_window] without [soft_expiration_field].');
        }
        if ($params['hard_expiration_field'] == '' && $params['hard_expiration_window'] > 0) {
            throw new InvalidArgumentException('You cannot set [hard_expiration_window] without [hard_expiration_field].');
        }
    }

Usage Example

Example #1
0
 /**
  * Constructor.
  *
  * Some special tokens can be used in the SQL query. They are replaced
  * at the query stage:
  *   '\L' will be replaced by the user's login
  *   '\P' will be replaced by the user's password.
  *   '\O' will be replaced by the old user's login (required for update)
  *
  * Eg: "SELECT * FROM users WHERE uid = \L
  *                          AND passwd = \P
  *                          AND billing = 'paid'"
  *
  * @param array $params  Configuration parameters:
  *   - query_auth:          (string) Authenticate the user. ('\L' & '\P')
  *   - query_add:           (string) Add user. ('\L' & '\P')
  *   - query_getpw:         (string) Get one user's password. ('\L')
  *   - query_update:        (string) Update user. ('\O', '\L' & '\P')
  *   - query_resetpassword: (string) Reset password. ('\L', & '\P')
  *   - query_remove:        (string) Remove user. ('\L')
  *   - query_list:          (string) List user.
  *   - query_exists:        (string) Check for existance of user. ('\L')
  */
 public function __construct(array $params = array())
 {
     foreach (array('query_auth', 'query_add', 'query_update', 'query_resetpassword', 'query_remove', 'query_list') as $val) {
         if (empty($params[$val])) {
             switch ($val) {
                 case 'query_auth':
                     $this->_capabilities['authenticate'] = false;
                     break;
                 case 'query_add':
                     $this->_capabilities['add'] = false;
                     break;
                 case 'query_update':
                     $this->_capabilities['update'] = false;
                     break;
                 case 'query_resetpassword':
                     $this->_capabilities['resetpassword'] = false;
                     break;
                 case 'query_remove':
                     $this->_capabilities['remove'] = false;
                     break;
                 case 'query_list':
                     $this->_capabilities['list'] = false;
                     break;
             }
         }
     }
     parent::__construct($params);
 }
All Usage Examples Of Horde_Auth_Sql::__construct