/**
  * Инициализирует компонент
  * @return void
  */
 public function init()
 {
     $this->instance = new $this->service();
     $this->instance->configure($this->options);
 }
Beispiel #2
0
 /**
  * Дополняет массив аргументов аргументами по умолчанию для каждого запроса
  *
  * @param array $args Массив аргументов
  *
  * @return array
  */
 protected function createArgs(array $args = [])
 {
     $args = parent::createArgs($args);
     if (null !== $this->defaultArgs) {
         if (array_key_exists(0, $args)) {
             $args = $args[0];
         }
         $args = array_merge($this->defaultArgs, $args);
     }
     return $args;
 }
Beispiel #3
0
 /**
  * Производит конфигурирование сервиса
  *
  * @param array $config Опции конфигурации
  *
  * @throws ConfigurationErrorException
  * @throws ErrorException
  */
 public function configure(array $config = [])
 {
     if (!array_key_exists('host', $config)) {
         throw new ConfigurationErrorException(self::ERR__HOST_REQUIRED);
     }
     if (array_key_exists('port', $config) && is_numeric($config['port'])) {
         $this->port = $config['port'];
     }
     if (array_key_exists('readOnly', $config)) {
         $this->readOnly = filter_var($config['readOnly'], FILTER_VALIDATE_BOOLEAN);
     }
     if (!$this->readOnly) {
         if (!array_key_exists('login', $config)) {
             throw new ConfigurationErrorException(self::ERR__LOGIN_REQUIRED);
         }
         if (!array_key_exists('password', $config)) {
             throw new ConfigurationErrorException(self::ERR__PASSWORD_REQUIRED);
         }
     }
     $this->client = ldap_connect($config['host'], $this->port);
     if (!$this->client) {
         throw new ErrorException(self::ERR__AD_CONNECT);
     }
     if ($this->readOnly) {
         $bind = ldap_bind($this->client);
     } else {
         $bind = ldap_bind($this->client, $config['login'], $config['password']);
     }
     if (!$bind) {
         $this->client = false;
         throw new ErrorException(self::ERR__AD_BIND);
     }
     if (!array_key_exists('pinba', $config)) {
         $config['pinba'] = ['type' => 'ldap', 'target' => $config['host']];
     }
     parent::configure($config);
 }