1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Translation\PlatformAdapter\PhraseApp\Bridge\Symfony\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use FAPI\PhraseApp\HttpClientConfigurator; |
6
|
|
|
use FAPI\PhraseApp\PhraseAppClient; |
7
|
|
|
use FAPI\PhraseApp\RequestBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
11
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
12
|
|
|
use Translation\PlatformAdapter\PhraseApp\PhraseApp; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Sascha-Oliver Prolic <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class TranslationAdapterPhraseAppExtension extends Extension |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
23
|
|
|
{ |
24
|
1 |
|
$configuration = new Configuration(); |
25
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
26
|
|
|
|
27
|
1 |
|
$requestBuilder = (new Definition(RequestBuilder::class)) |
28
|
1 |
|
->addArgument(new Reference($config['httplug_message_factory'])); |
29
|
|
|
|
30
|
1 |
|
$clientConfigurator = (new Definition(HttpClientConfigurator::class)) |
31
|
1 |
|
->addArgument($config['token']) |
32
|
1 |
|
->addArgument(new Reference($config['httplug_client'])) |
33
|
1 |
|
->addArgument(new Reference($config['httplug_uri_factory'])); |
34
|
|
|
|
35
|
1 |
|
$apiDef = $container->register('php_translation.adapter.loco.raw'); |
36
|
1 |
|
$apiDef->setClass(PhraseAppClient::class) |
37
|
1 |
|
->setFactory([PhraseAppClient::class, 'configure']) |
38
|
1 |
|
->addArgument($clientConfigurator) |
39
|
1 |
|
->addArgument(null) |
40
|
1 |
|
->addArgument($requestBuilder); |
41
|
|
|
|
42
|
1 |
|
$adapterDef = $container->register('php_translation.adapter.phrase_app'); |
43
|
|
|
$adapterDef |
44
|
1 |
|
->setClass(PhraseApp::class) |
45
|
1 |
|
->addArgument($apiDef) |
46
|
1 |
|
->addArgument($config['project_id']) |
47
|
1 |
|
->addArgument($config['locale_to_id_mapping']) |
48
|
1 |
|
->addArgument($config['domains']); |
49
|
|
|
|
50
|
1 |
|
if (isset($config['default_locale'])) { |
51
|
|
|
$adapterDef->addArgument($config['default_locale']); |
52
|
|
|
} |
53
|
1 |
|
} |
54
|
|
|
} |
55
|
|
|
|