diff --git a/README.md b/README.md index 7bd717c..3094490 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ Here is the list of the currently implemented services. | [Russian Central Bank](http://http://www.cbr.ru) | * | RUB | Yes | | [currencylayer](https://currencylayer.com) | USD (free), * (paid) | * | Yes | | [Cryptonator](https://www.cryptonator.com) | * Crypto (Limited standard currencies) | * Crypto (Limited standard currencies) | No | +| [1Forge](https://1forge.com) | * (free but limited or paid) | * (free but limited or paid) | No | +| [CurrencyDataFeed](https://currencydatafeed.com) | * (free but limited or paid) | * (free but limited or paid) | No | | Array | * | * | Yes | ## Credits diff --git a/composer.json b/composer.json index fe4c4af..743510d 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ }, "require": { "php": "^5.5|^7.0", - "florianv/swap": "^3.0", + "florianv/swap": "^3.3", "psr/cache": "^1.0", "cache/adapter-common": "^0.3" }, diff --git a/config/swap.php b/config/swap.php index 787fafd..9401e73 100644 --- a/config/swap.php +++ b/config/swap.php @@ -33,7 +33,7 @@ | Here is the config spec for each service: | | * "central_bank_of_czech_republic", "central_bank_of_republic_turkey", "european_central_bank", "fixer" - | "google", "national_bank_of_romania", "webservicex", "yahoo", "russian_central_bank" can be enabled with "true" as value. + | "google", "national_bank_of_romania", "webservicex", "russian_central_bank", "cryptonator" can be enabled with "true" as value. | | * 'currency_layer' => [ | 'access_key' => 'secret', // Your app id @@ -49,8 +49,15 @@ | 'token' => 'secret', // The API token | ] | + | * 'currency_data_feed' => [ + | 'api_key' => 'secret', // The API token + | ] + | + | * 'forge' => [ + | 'api_key' => 'secret', // The API token + | ] + | */ - 'services' => [ 'fixer' => true, ], diff --git a/doc/readme.md b/doc/readme.md index ff1ea0d..f52f7e1 100644 --- a/doc/readme.md +++ b/doc/readme.md @@ -250,6 +250,8 @@ Here is the complete list of supported services and their possible configuration 'webservicex' => true, 'xignite' => ['token' => 'token'], 'russian_central_bank' => true, - 'cryptonator' => true + 'cryptonator' => true, + 'currency_data_feed' => ['api_key' => 'secret'], + 'forge' => ['api_key' => 'secret'], ] ``` diff --git a/src/SwapServiceProvider.php b/src/SwapServiceProvider.php index aea2e6f..be7408b 100644 --- a/src/SwapServiceProvider.php +++ b/src/SwapServiceProvider.php @@ -94,10 +94,10 @@ private function registerServices(Container $app) $app->singleton($serviceName, function () use ($config) { return new PhpArray($config); }); - + $app->tag($serviceName, 'swap.service'); - - return; + + continue; } // Process the regular services @@ -200,6 +200,11 @@ public function provides() */ private function getServiceClass($name) { + // WebserviceX is a special case + if ('webservicex' === $name) { + $name = 'webservice_x'; + } + $camelized = ucfirst(implode('', array_map('ucfirst', explode('_', $name)))); return 'Exchanger\\Service\\'.$camelized; diff --git a/tests/SwapServiceProviderTest.php b/tests/SwapServiceProviderTest.php index c6f5a38..30d428f 100644 --- a/tests/SwapServiceProviderTest.php +++ b/tests/SwapServiceProviderTest.php @@ -15,7 +15,22 @@ use Exchanger\ExchangeRate; use Exchanger\ExchangeRateQuery; use Exchanger\HistoricalExchangeRateQuery; +use Exchanger\Service\CentralBankOfCzechRepublic; +use Exchanger\Service\CentralBankOfRepublicTurkey; +use Exchanger\Service\Cryptonator; +use Exchanger\Service\CurrencyDataFeed; +use Exchanger\Service\CurrencyLayer; +use Exchanger\Service\EuropeanCentralBank; use Exchanger\Service\Fixer; +use Exchanger\Service\Forge; +use Exchanger\Service\Google; +use Exchanger\Service\NationalBankOfRomania; +use Exchanger\Service\OpenExchangeRates; +use Exchanger\Service\PhpArray; +use Exchanger\Service\RussianCentralBank; +use Exchanger\Service\WebserviceX; +use Exchanger\Service\Xignite; +use Exchanger\Service\Yahoo; use GrahamCampbell\TestBench\Traits\ServiceProviderTestCaseTrait; use Exchanger\Service\Chain; use Http\Discovery\HttpClientDiscovery; @@ -75,10 +90,33 @@ public function testAllServices() 'xignite' => ['token' => 'token'], 'yahoo' => true, 'russian_central_bank' => true, + 'currency_data_feed' => ['api_key' => 'secret'], + 'forge' => ['api_key' => 'secret'], 'cryptonator' => true, ]); $this->assertInstanceOf(Chain::class, $this->app['swap.chain']); + + $services = $this->app->tagged('swap.service'); + + $this->assertCount(16, $services); + + $this->assertInstanceOf(CentralBankOfCzechRepublic::class, $services[0]); + $this->assertInstanceOf(CentralBankOfRepublicTurkey::class, $services[1]); + $this->assertInstanceOf(CurrencyLayer::class, $services[2]); + $this->assertInstanceOf(EuropeanCentralBank::class, $services[3]); + $this->assertInstanceOf(Fixer::class, $services[4]); + $this->assertInstanceOf(Google::class, $services[5]); + $this->assertInstanceOf(NationalBankOfRomania::class, $services[6]); + $this->assertInstanceOf(OpenExchangeRates::class, $services[7]); + $this->assertInstanceOf(PhpArray::class, $services[8]); + $this->assertInstanceOf(WebserviceX::class, $services[9]); + $this->assertInstanceOf(Xignite::class, $services[10]); + $this->assertInstanceOf(Yahoo::class, $services[11]); + $this->assertInstanceOf(RussianCentralBank::class, $services[12]); + $this->assertInstanceOf(CurrencyDataFeed::class, $services[13]); + $this->assertInstanceOf(Forge::class, $services[14]); + $this->assertInstanceOf(Cryptonator::class, $services[15]); } public function testSwapIsInjectable()