public function testChecksIfHasKey() { $this->assertFalse($this->coll->hasKey('test')); $this->coll->add('test', 'value'); $this->assertEquals(true, $this->coll->hasKey('test')); $this->coll->add('test2', 'value2'); $this->assertEquals(true, $this->coll->hasKey('test')); $this->assertEquals(true, $this->coll->hasKey('test2')); $this->assertFalse($this->coll->hasKey('testing')); $this->assertEquals(false, $this->coll->hasKey('AB-C', 'junk')); }
/** * Validate and prepare configuration parameters * * @param array $config Configuration values to apply. * @param array $defaults Default parameters * @param array $required Required parameter names * * @return Collection * @throws InvalidArgumentException if a parameter is missing */ public static function prepareConfig(array $config = null, array $defaults = null, array $required = null) { $collection = new Collection($defaults); foreach ((array) $config as $key => $value) { $collection->set($key, $value); } foreach ((array) $required as $key) { if ($collection->hasKey($key) === false) { throw new ValidationException("Config must contain a '{$key}' key"); } } return $collection; }
private function handleEndpoint(Collection $config) { // Alias "endpoint" with "base_url" for forwards compatibility. if ($config['endpoint']) { $config[Options::BASE_URL] = $config['endpoint']; return; } if ($config[Options::BASE_URL]) { return; } $endpoint = call_user_func($config['endpoint_provider'], array('scheme' => $config[Options::SCHEME], 'region' => $config[Options::REGION], 'service' => $config[Options::SERVICE])); $config[Options::BASE_URL] = $endpoint['endpoint']; // Set a signature if one was not explicitly provided. if (!$config->hasKey(Options::SIGNATURE) && isset($endpoint['signatureVersion'])) { $config->set(Options::SIGNATURE, $endpoint['signatureVersion']); } // The the signing region if endpoint rule specifies one. if (isset($endpoint['credentialScope'])) { $scope = $endpoint['credentialScope']; if (isset($scope['region'])) { $config->set(Options::SIGNATURE_REGION, $scope['region']); } } }
/** * Update a configuration object from a service description * * @param Collection $config Config to update * * @return ServiceDescription * @throws InvalidArgumentException */ protected function updateConfigFromDescription(Collection $config) { $description = $config->get(Options::SERVICE_DESCRIPTION); if (!$description instanceof ServiceDescription) { // Inject the version into the sprintf template if it is a string if (is_string($description)) { $description = sprintf($description, $config->get(Options::VERSION)); } $description = ServiceDescription::factory($description); $config->set(Options::SERVICE_DESCRIPTION, $description); } if (!$config->get(Options::SERVICE)) { $config->set(Options::SERVICE, $description->getData('endpointPrefix')); } if ($iterators = $description->getData('iterators')) { $this->setIteratorsConfig($iterators); } // Make sure a valid region is set $region = $config->get(Options::REGION); $global = $description->getData('globalEndpoint'); if (!$global && !$region) { throw new InvalidArgumentException('A region is required when using ' . $description->getData('serviceFullName')); } elseif ($global && (!$region || $description->getData('namespace') !== 'S3')) { $region = 'us-east-1'; $config->set(Options::REGION, 'us-east-1'); } if (!$config->get(Options::BASE_URL)) { $endpoint = call_user_func($config->get('endpoint_provider'), array('scheme' => $config->get(Options::SCHEME), 'region' => $region, 'service' => $config->get(Options::SERVICE))); $config->set(Options::BASE_URL, $endpoint['endpoint']); // Set a signature if one was not explicitly provided. if (!$config->hasKey(Options::SIGNATURE) && isset($endpoint['signatureVersion'])) { $config->set(Options::SIGNATURE, $endpoint['signatureVersion']); } } return $description; }