Ejemplo n.º 1
0
 /**
  * @param array|string        $config     Array with configuration or path to PHP file that will return array
  * @param HttpClientInterface $httpClient
  * @param StorageInterface    $storage
  * @param LoggerInterface     $logger
  *
  * @throws InvalidArgumentException
  */
 public function __construct($config = [], HttpClientInterface $httpClient = null, StorageInterface $storage = null, LoggerInterface $logger = null)
 {
     if (is_string($config) && file_exists($config)) {
         $config = (include $config);
     } elseif (!is_array($config)) {
         throw new InvalidArgumentException('Hybriauth config does not exist on the given path.');
     }
     $this->config = $config + ['debug_mode' => Logger::NONE, 'debug_file' => '', 'curl_options' => null, 'providers' => []];
     $this->storage = $storage ?: new Session();
     $this->logger = $logger ?: new Logger($this->config['debug_mode'], $this->config['debug_file']);
     $this->httpClient = $httpClient ?: new HttpClient();
     if ($this->config['curl_options'] && method_exists($this->httpClient, 'setCurlOptions')) {
         $this->httpClient->setCurlOptions($this->config['curl_options']);
     }
     if (method_exists($this->httpClient, 'setLogger')) {
         $this->httpClient->setLogger($this->logger);
     }
 }
Ejemplo n.º 2
0
 /**
  * Common adapters constructor.
  *
  * @param array               $config
  * @param HttpClientInterface $httpClient
  * @param StorageInterface    $storage
  * @param LoggerInterface     $logger
  */
 public function __construct($config = [], HttpClientInterface $httpClient = null, StorageInterface $storage = null, LoggerInterface $logger = null)
 {
     $this->providerId = str_replace('Hybridauth\\Provider\\', '', get_class($this));
     $this->storage = $storage ?: new Session();
     $this->logger = $logger ?: new Logger(isset($config['debug_mode']) ? $config['debug_mode'] : Logger::NONE, isset($config['debug_file']) ? $config['debug_file'] : '');
     $this->httpClient = $httpClient ?: new HttpClient();
     if (isset($config['curl_options']) && method_exists($this->httpClient, 'setCurlOptions')) {
         $this->httpClient->setCurlOptions($this->config['curl_options']);
     }
     if (method_exists($this->httpClient, 'setLogger')) {
         $this->httpClient->setLogger($this->logger);
     }
     $this->logger->debug('Initialize ' . get_class($this) . '. Provider config: ', $config);
     $this->config = new Data\Collection($config);
     $this->endpoint = $this->config->get('callback');
     $this->initialize();
 }