public static function factory($config = []) { $client = new self(); $config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required); $client->configure($config); $client->setUserAgent(self::USER_AGENT, true); self::$consumer_key = $config->get('consumer_key'); self::$consumer_secret = $config->get('consumer_secret'); self::$application_name = $config->get('application_name'); // add a listener to alter every requests and authenticate them through Semantria weird oAuth $client->getEventDispatcher()->addListener('command.before_send', function (Event $event) use($client) { $command = $event['command']; $request = $client->oAuthRequest($command->getRequest()); }); return $client; }