__construct() protected method

This constructor should always be called first in any class which implements this class.
protected __construct ( &$config )
 /**
  * Parse configuration.
  *
  * This constructor parses the configuration.
  *
  * @param array $config Configuration for database consent store.
  */
 public function __construct($config)
 {
     parent::__construct($config);
     foreach (array('dsn', 'username', 'password') as $id) {
         if (!array_key_exists($id, $config)) {
             throw new Exception('consent:Database - Missing required option \'' . $id . '\'.');
         }
         if (!is_string($config[$id])) {
             throw new Exception('consent:Database - \'' . $id . '\' is supposed to be a string.');
         }
     }
     $this->_dsn = $config['dsn'];
     $this->_username = $config['username'];
     $this->_password = $config['password'];
     if (array_key_exists('table', $config)) {
         if (!is_string($config['table'])) {
             throw new Exception('consent:Database - \'table\' is supposed to be a string.');
         }
         $this->_table = $config['table'];
     } else {
         $this->_table = 'consent';
     }
     if (isset($config['timeout'])) {
         if (!is_int($config['timeout'])) {
             throw new Exception('consent:Database - \'timeout\' is supposed to be an integer.');
         }
         $this->_timeout = $config['timeout'];
     }
 }
Example #2
0
 /**
  * Parse configuration.
  *
  * This constructor parses the configuration.
  *
  * @param array $config Configuration for database consent store.
  *
  * @throws Exception in case of a configuration error.
  */
 public function __construct($config)
 {
     parent::__construct($config);
     if (!array_key_exists('dsn', $config)) {
         throw new Exception('consent:Database - Missing required option \'dsn\'.');
     }
     if (!is_string($config['dsn'])) {
         throw new Exception('consent:Database - \'dsn\' is supposed to be a string.');
     }
     $this->_dsn = $config['dsn'];
     $this->_dateTime = 0 === strpos($this->_dsn, 'sqlite:') ? 'DATETIME("NOW")' : 'NOW()';
     if (array_key_exists('username', $config)) {
         if (!is_string($config['username'])) {
             throw new Exception('consent:Database - \'username\' is supposed to be a string.');
         }
         $this->_username = $config['username'];
     } else {
         $this->_username = null;
     }
     if (array_key_exists('password', $config)) {
         if (!is_string($config['password'])) {
             throw new Exception('consent:Database - \'password\' is supposed to be a string.');
         }
         $this->_password = $config['password'];
     } else {
         $this->_password = null;
     }
     if (array_key_exists('table', $config)) {
         if (!is_string($config['table'])) {
             throw new Exception('consent:Database - \'table\' is supposed to be a string.');
         }
         $this->_table = $config['table'];
     } else {
         $this->_table = 'consent';
     }
     if (isset($config['timeout'])) {
         if (!is_int($config['timeout'])) {
             throw new Exception('consent:Database - \'timeout\' is supposed to be an integer.');
         }
         $this->_timeout = $config['timeout'];
     }
 }