/** * Merges settings to pre-constructed provider config * * @param array|ProviderConfigLike $settings * * @return $this */ public function mergeSettings($settings = array()) { foreach ($settings as $_key => $_value) { if (property_exists($this, $_key)) { try { Option::set($this, $_key, $_value); unset($settings, $_key); continue; } catch (\Exception $_ex) { // Ignore... } } $_setter = Inflector::tag('set_' . $_key); if (method_exists($this, $_setter)) { call_user_func(array($this, $_setter), $_value); unset($settings, $_key, $_setter); } } return $this; }
/** * @param array $contents * * @return \DreamFactory\Oasys\Configs\OAuthProviderConfig */ public function __construct($contents = array()) { Option::set($contents, 'type', static::OAUTH); parent::__construct($contents); }
/** * Create/De-cache a provider and return it * * @param string $providerId * @param array|ProviderConfigLike $config * @param bool $createIfNotFound If false and provider not already created, NULL is returned * * @throws \InvalidArgumentException * @return BaseProvider */ protected static function _createProvider($providerId, $config = null, $createIfNotFound = true) { list($_providerId, $_type, $_mapKey, $_generic) = static::_normalizeProviderId($providerId); $_cacheKey = $_mapKey . ($_generic ?: null); if (null === ($_provider = Option::get(static::$_providerCache, $_cacheKey))) { $_config = empty($config) ? array() : $config; // Get the class mapping... if (null === ($_map = Option::get(static::$_classMap, $_mapKey))) { if (null === ($_map = Option::get(static::$_classMap, $_providerId))) { throw new \InvalidArgumentException('The provider "' . $providerId . '" has no associated mapping. Cannot create.'); } } if (true !== $createIfNotFound && array() == $_config) { return null; } if (!empty($_config) && !$_config instanceof ProviderConfigLike && !is_array($_config) && !is_object($_config)) { throw new \InvalidArgumentException('The "$config" value specified must be null, an object, an array, or an instance of ProviderConfigLike.'); } // Get the base template and merge it into the configuration $_template = BaseProviderConfig::getTemplate($_providerId); // Check the endpoint maps... $_endpoints = Option::get($_config, 'endpoint_map', array()); Option::set($_config, 'endpoint_map', array_merge(Option::get($_template, 'endpoint_map', array()), $_endpoints)); /** @noinspection PhpIncludeInspection */ require $_map['path']; if (empty($_config)) { $_config = array(); } $_className = $_map['namespace'] . '\\' . $_map['class_name']; $_mirror = new \ReflectionClass($_className); // Fill the config with the store values if any if (null !== $_type) { Option::sins($_config, 'type', $_type); } // Load any stored configuration $_config = static::_mergeConfigFromStore($_providerId, $_config); // Instantiate! $_provider = $_mirror->newInstanceArgs(array($_providerId, $_config)); // Cache the current version... Option::set(static::$_providerCache, $_cacheKey, $_provider); } return $_provider; }
/** * @param string $key * @param mixed $value * @param bool $overwrite * * @return $this */ public function set($key, $value, $overwrite = true) { Option::set($this->_map, $this->_hashKey($key), $value, $overwrite); return $this; }
/** * Called before a request to get any additional auth header(s) or payload parameters * (query string for non-POST-type requests) needed for the call. * * Append them to the $headers array as strings in "header: value" format: * * <code> * $_contentType = 'Content-Type: application/json'; * $_origin = 'Origin: teefury.com'; * * $headers[] = $_contentType; * $headers[] = $_origin; * </code> * * and/or append them to the $payload array in $key => $value format: * * <code> * $payload['param1'] = 'value1'; * $payload['param2'] = 'value2'; * $payload['param3'] = 'value3'; * </code> * * @param array $headers The current headers that are going to be sent * @param array $payload * * @throws \DreamFactory\Oasys\Exceptions\OasysConfigurationException * @throws NotImplementedException * @return void */ protected function _getAuthParameters(&$headers = array(), &$payload = array()) { $_token = $this->getConfig('access_token'); // Use the resource url if provided... if ($_token) { $_authHeaderName = $this->getConfig('auth_header_name'); switch ($this->getConfig('access_token_type')) { case TokenTypes::URI: Option::set($payload, $this->getConfig('access_token_param_name'), $_token); $_authHeaderName = null; break; case TokenTypes::BEARER: $_authHeaderName = $_authHeaderName ?: 'Bearer'; break; case TokenTypes::OAUTH: $_authHeaderName = $_authHeaderName ?: 'OAuth'; break; case TokenTypes::MAC: throw new NotImplementedException(); default: throw new OasysConfigurationException('Unknown access token type "' . $this->getConfig('access_token_type') . '".'); } if (null !== $_authHeaderName) { $headers[] = 'Authorization: ' . $_authHeaderName . ' ' . $_token; } } }
/** * Base constructor * * @param array|object $settings An array of key/value pairs that will be placed into storage */ public function __construct($settings = array()) { // Since $_id is read-only we remove it Option::remove($settings, 'id'); // Now, set the rest if (!empty($settings)) { foreach ($settings as $_key => $_value) { Option::set($this, $_key, $_value); } } // Wake-up the events $this->__wakeup(); }
/** * @param array $contents * * @throws \RuntimeException * @return \DreamFactory\Oasys\Configs\LegacyOAuthProviderConfig */ public function __construct($contents = array()) { // Require pecl oauth library... if (!extension_loaded('oauth')) { throw new \RuntimeException('Use of the LegacyOAuthProviderConfig requires the PECL "oauth" extension.'); } Option::set($contents, 'type', static::LEGACY_OAUTH); parent::__construct($contents); }
/** * @param string $key * @param mixed $value * * @return mixed */ public static function set($key, $value = null) { Option::set(static::$_options, static::_getKeyTag($key), $value); }