/** * Factory to create new GiantBombClient instance. * * @param array $config * * @returns \GiantBomb\Client\GiantBombClient */ public static function factory($config = array()) { $default = array('baseUrl' => "http://www.giantbomb.com/", 'version' => '1.0', 'apiKey' => null, 'format' => 'json', 'limit' => 100, 'offset' => 0, 'cache' => null); // Validate the configuration options self::validateConfig($config); // Create client configuration $config = Collection::fromConfig($config, $default); // Create the new GiantBomb Client with our Configuration $client = new self($config->get('baseUrl'), $config); if ($config->get('cache') !== null) { $client->createCache($config->get('cache')); } // Set the Service Definition from the versioned file $file = 'giant-bomb-' . str_replace('.', '_', $client->getConfig('version')) . '.json'; $client->setDescription(ServiceDescription::factory(__DIR__ . "/../Resources/config/{$file}")); $parameters = array(); foreach (array('apiKey', 'format') as $key) { $parameters[$key] = $config->get($key); } $config->set('command.params', $parameters); $client->setDefaultOption('query', array('api_key' => $config->get('apiKey'), 'format' => $config->get('format'), 'limit' => $config->get('limit'), 'offset' => $config->get('offset'))); return $client; }