/** * @desc Helper function for getting the configuration for http requests * @return \Ivory\HttpAdapter\Configuration */ private function getHttpConfig($config) { // get composer.json to extract version number $composerFile = file_get_contents(dirname(__FILE__) . '/../../composer.json'); $composer = json_decode($composerFile, true); // create Configuration for http adapter $httpConfig = new Configuration(); $baseUrl = $config['protocol'] . '://' . $config['host'] . ($config['port'] ? ':' . $config['port'] : '') . '/api/' . $config['version']; $httpConfig->setBaseUri($baseUrl); $httpConfig->setUserAgent('php-sparkpost/' . $composer['version']); return $httpConfig; }
/** * Get the default HTTP adapter configuration object * * This can be used for example to modify but not completely replace the * default configuration (e.g. to prefix the user agent string), or to use * the default configuration for a non-default HTTP adapter. * * @return \Ivory\HttpAdapter\ConfigurationInterface Configuration object */ public static function defaultHttpAdapterConfiguration() { $configuration = new Configuration(); $configuration->setUserAgent('Prismic-php-kit/' . self::VERSION . ' PHP/' . phpversion()); // We need to add the subscriber to have errors on 4.x.x and 5.x.x. $statusCodeSubscriber = new StatusCodeSubscriber(); $configuration->getEventDispatcher()->addSubscriber($statusCodeSubscriber); return $configuration; }
/** * @inheritdoc */ public function init() { if (!$this->apiKey) { throw new InvalidConfigException('"' . get_class($this) . '::apiKey" must be set.'); } if (!is_string($this->apiKey)) { throw new InvalidConfigException('"' . get_class($this) . '::apiKey" must be a string, ' . gettype($this->apiKey) . ' given.'); } $this->sparkpostConfig['key'] = $this->apiKey; // Initialize the http adapter, cUrl adapter is default $adapterConfig = new Configuration(); $adapterConfig->setTimeout(4); $httpAdapter = $this->httpAdapter ? BaseYii::createObject($this->httpAdapter) : new CurlHttpAdapter($adapterConfig); $this->_sparkPost = new SparkPost($httpAdapter, $this->sparkpostConfig); if ($this->useDefaultEmail && !$this->defaultEmail) { if (!isset(\Yii::$app->params['adminEmail'])) { throw new InvalidConfigException('You must set "' . get_class($this) . '::defaultEmail" or have "adminEmail" key in application params or disable "' . get_class($this) . '::useDefaultEmail"'); } $this->defaultEmail = \Yii::$app->name . '<' . \Yii::$app->params['adminEmail'] . '>'; } }
/** * Get the default HTTP adapter configuration object * * This can be used for example to modify but not completely replace the * default configuration (e.g. to prefix the user agent string), or to use * the default configuration for a non-default HTTP adapter. * * @return \Ivory\HttpAdapter\ConfigurationInterface Configuration object */ public static function defaultHttpAdapterConfiguration() { $configuration = new Configuration(); $configuration->setUserAgent('Prismic-php-kit/' . self::VERSION . ' PHP/' . phpversion()); return $configuration; }