Skip to content

Commit

Permalink
Guzzle Client injected
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-nitsche committed Jan 31, 2017
1 parent 622195c commit 5435578
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Resources/config/methods.xml
Expand Up @@ -21,19 +21,26 @@
<tag name="eko.google_translate.method" />

<argument>%eko_google_translate.api_key%</argument>
<argument type="service" id="eko.guzzle_client" />
</service>

<service id="eko.google_translate.languages" class="Eko\GoogleTranslateBundle\Translate\Method\Languages">
<tag name="eko.google_translate.method" />

<argument>%eko_google_translate.api_key%</argument>
<argument type="service" id="eko.guzzle_client" />
</service>

<service id="eko.google_translate.translator" class="Eko\GoogleTranslateBundle\Translate\Method\Translator">
<tag name="eko.google_translate.method" />

<argument>%eko_google_translate.api_key%</argument>
<argument type="service" id="eko.guzzle_client" />
<argument type="service" id="eko.google_translate.detector" />
</service>

<service id="eko.guzzle_client" class="GuzzleHttp\Client">

</service>
</services>
</container>
11 changes: 6 additions & 5 deletions Translate/Method.php
Expand Up @@ -54,15 +54,16 @@ class Method
protected $counter = 1;

/**
* Constructor.
* Method constructor.
*
* @param string $apiKey API key retrieved from configuration
* @param Stopwatch $stopwatch Symfony profiler Stopwatch service
* @param string $apiKey API key retrieved from configuration
* @param GuzzleClient $client
* @param Stopwatch $stopwatch Symfony profiler Stopwatch service
*/
public function __construct($apiKey, Stopwatch $stopwatch = null)
public function __construct($apiKey, GuzzleClient $client, Stopwatch $stopwatch = null)
{
$this->apiKey = $apiKey;
$this->client = new GuzzleClient();
$this->client = $client;

$this->stopwatch = $stopwatch;
}
Expand Down
12 changes: 7 additions & 5 deletions Translate/Method/Translator.php
Expand Up @@ -12,6 +12,7 @@

use Eko\GoogleTranslateBundle\Translate\Method;
use Eko\GoogleTranslateBundle\Translate\MethodInterface;
use GuzzleHttp\Client as GuzzleClient;
use Symfony\Component\Stopwatch\Stopwatch;

/**
Expand Down Expand Up @@ -49,15 +50,16 @@ class Translator extends Method implements MethodInterface
/**
* Constructor.
*
* @param string $apiKey Google Translate API key
* @param Detector $detector A Detector service
* @param Stopwatch $stopwatch Symfony profiler stopwatch service
* @param string $apiKey Google Translate API key
* @param GuzzleClient $client
* @param Detector $detector A Detector service
* @param Stopwatch $stopwatch Symfony profiler stopwatch service
*/
public function __construct($apiKey, Detector $detector, Stopwatch $stopwatch = null)
public function __construct($apiKey, GuzzleClient $client, Detector $detector, Stopwatch $stopwatch = null)
{
$this->detector = $detector;

return parent::__construct($apiKey, $stopwatch);
return parent::__construct($apiKey, $client, $stopwatch);
}

/**
Expand Down

0 comments on commit 5435578

Please sign in to comment.