diff --git a/.travis.yml b/.travis.yml index 7aa2433..ec32668 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,28 +10,33 @@ branches: - /^patch-.*$/ php: - - 7.0 - - 7.1 + - 7.2 + - 7.4 + - 8.0 env: global: - TEST_COMMAND="composer test" matrix: - - SYMFONY_VERSION=3.2.* - - SYMFONY_VERSION=2.7.* + - SYMFONY_VERSION=4.4.* + - SYMFONY_VERSION=5.2.* matrix: fast_finish: true include: - - php: 7.0 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" SYMFONY_VERSION=2.7.* + - php: 7.2 + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" SYMFONY_VERSION=4.4.* + - php: 7.4 + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" SYMFONY_VERSION=5.2.* + - php: 8.0 + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" SYMFONY_VERSION=5.2.* - php: hhvm dist: trusty - env: SYMFONY_VERSION=2.8.* + env: SYMFONY_VERSION=4.4.* allow_failures: - php: hhvm dist: trusty - env: SYMFONY_VERSION=2.8.* + env: SYMFONY_VERSION=4.4.* install: - composer require symfony/symfony:${SYMFONY_VERSION} --no-update diff --git a/composer.json b/composer.json index 93a52b4..d3ecf36 100644 --- a/composer.json +++ b/composer.json @@ -13,21 +13,20 @@ } ], "require": { - "php": "^7.0", - "php-translation/common": "^0.2", - "php-translation/symfony-storage": "^0.3.2", - "friendsofapi/phraseapp": "^0.3.0", - "symfony/translation": "^2.7 || ^3.0", - "symfony/yaml": "^2.7 || ^3.0" + "php": "^7.2 || ^8.0", + "php-translation/symfony-storage": "^2.1", + "symfony/translation": "^4.4.20 || ^5.2.5", + "symfony/yaml": "^4.4.20 || ^5.2.5", + "friendsofapi/phraseapp": "^0.3.0" }, "require-dev": { - "phpunit/phpunit": "^6.3", - "nyholm/symfony-bundle-test": "^1.2", - "php-http/curl-client": "^1.6", - "php-http/httplug-bundle": "^1.3", - "guzzlehttp/psr7": "^1.3", - "php-http/message": "^1.4", - "phpunit/php-token-stream": "^1.4.9" + "phpunit/phpunit": "^8.5", + "symfony/framework-bundle": "^4.4.20 || ^5.2.5", + "nyholm/psr7": "^1.2", + "nyholm/symfony-bundle-test": "^1.6.1", + "php-http/curl-client": "^2.0", + "php-http/httplug-bundle": "^1.16", + "php-http/message": "^1.6" }, "autoload": { "psr-4": { @@ -43,7 +42,7 @@ "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-dist": "true", "extra": { "branch-alias": { diff --git a/src/Bridge/Symfony/DependencyInjection/Configuration.php b/src/Bridge/Symfony/DependencyInjection/Configuration.php index 894e9bd..483e986 100644 --- a/src/Bridge/Symfony/DependencyInjection/Configuration.php +++ b/src/Bridge/Symfony/DependencyInjection/Configuration.php @@ -13,21 +13,39 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { - $treeBuilder = new TreeBuilder(); - $root = $treeBuilder->root('translation_adapter_phrase_app'); + $treeBuilder = new TreeBuilder('translation_adapter_phrase_app'); + if (!method_exists($treeBuilder, 'getRootNode')) { + $root = $treeBuilder->root('translation_adapter_phrase_app'); + } else { + $root = $treeBuilder->getRootNode(); + } - $root->children() - ->scalarNode('httplug_client')->defaultValue('httplug.client')->cannotBeEmpty()->end() - ->scalarNode('httplug_message_factory')->defaultValue('httplug.message_factory')->cannotBeEmpty()->end() - ->scalarNode('httplug_uri_factory')->defaultValue('httplug.uri_factory')->cannotBeEmpty()->end() - ->scalarNode('project_id')->cannotBeEmpty()->end() - ->scalarNode('token')->cannotBeEmpty()->end() - ->scalarNode('default_locale')->end() - ->arrayNode('locale_to_id_mapping')->prototype('scalar')->end()->end() - ->arrayNode('domains')->prototype('scalar')->end()->end() - ->end(); + $root + ->children() + ->scalarNode('httplug_client') + ->defaultValue('httplug.client')->cannotBeEmpty() + ->end() + ->scalarNode('httplug_message_factory') + ->defaultValue('httplug.message_factory')->cannotBeEmpty() + ->end() + ->scalarNode('httplug_uri_factory') + ->defaultValue('httplug.uri_factory')->cannotBeEmpty()->end() + ->scalarNode('project_id') + ->cannotBeEmpty() + ->end() + ->scalarNode('token') + ->cannotBeEmpty() + ->end() + ->scalarNode('default_locale')->end() + ->arrayNode('locale_to_id_mapping') + ->prototype('scalar')->end() + ->end() + ->arrayNode('domains') + ->prototype('scalar')->end() + ->end() + ->end(); return $treeBuilder; } diff --git a/src/Bridge/Symfony/DependencyInjection/TranslationAdapterPhraseAppExtension.php b/src/Bridge/Symfony/DependencyInjection/TranslationAdapterPhraseAppExtension.php index 5e1fe3b..bb6b20c 100644 --- a/src/Bridge/Symfony/DependencyInjection/TranslationAdapterPhraseAppExtension.php +++ b/src/Bridge/Symfony/DependencyInjection/TranslationAdapterPhraseAppExtension.php @@ -19,22 +19,23 @@ class TranslationAdapterPhraseAppExtension extends Extension /** * {@inheritdoc} */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $requestBuilder = (new Definition(RequestBuilder::class)) - ->addArgument(new Reference($config['httplug_message_factory'])); + ->addArgument(empty($config['httplug_message_factory']) ? null : new Reference($config['httplug_message_factory'])); $clientConfigurator = (new Definition(HttpClientConfigurator::class)) ->addArgument($config['token']) - ->addArgument(new Reference($config['httplug_client'])) - ->addArgument(new Reference($config['httplug_uri_factory'])); + ->addArgument(empty($config['httplug_client']) ? null : new Reference($config['httplug_client'])) + ->addArgument(empty($config['httplug_uri_factory']) ? null : new Reference($config['httplug_uri_factory'])); - $apiDef = $container->register('php_translation.adapter.loco.raw'); + $apiDef = $container->register('php_translation.adapter.phrase_app.raw'); $apiDef->setClass(PhraseAppClient::class) ->setFactory([PhraseAppClient::class, 'configure']) + ->setPublic(true) ->addArgument($clientConfigurator) ->addArgument(null) ->addArgument($requestBuilder); @@ -42,6 +43,7 @@ public function load(array $configs, ContainerBuilder $container) $adapterDef = $container->register('php_translation.adapter.phrase_app'); $adapterDef ->setClass(PhraseApp::class) + ->setPublic(true) ->addArgument($apiDef) ->addArgument($config['project_id']) ->addArgument($config['locale_to_id_mapping']) diff --git a/src/PhraseApp.php b/src/PhraseApp.php index 5070ebd..c3c7687 100644 --- a/src/PhraseApp.php +++ b/src/PhraseApp.php @@ -2,6 +2,7 @@ namespace Translation\PlatformAdapter\PhraseApp; +use FAPI\PhraseApp\Exception\Domain\UnprocessableEntityException; use FAPI\PhraseApp\Model\Key\KeyCreated; use FAPI\PhraseApp\Model\Key\KeySearchResults; use FAPI\PhraseApp\Model\Translation\Index; @@ -9,6 +10,7 @@ use Symfony\Component\Translation\MessageCatalogueInterface; use Translation\Common\Exception\StorageException; use Translation\Common\Model\Message; +use Translation\Common\Model\MessageInterface; use Translation\Common\Storage; use Translation\Common\TransferableStorage; use Translation\SymfonyStorage\XliffConverter; @@ -60,7 +62,7 @@ public function __construct( /** * {@inheritdoc} */ - public function get($locale, $domain, $key) + public function get(string $locale, string $domain, string $key): ?MessageInterface { /* @var Index $index */ $index = $this->client->translation()->indexLocale($this->projectId, $this->getLocaleId($locale), [ @@ -77,7 +79,7 @@ public function get($locale, $domain, $key) /** * {@inheritdoc} */ - public function create(Message $message) + public function create(MessageInterface $message): void { $localeId = $this->getLocaleId($message->getLocale()); @@ -126,7 +128,7 @@ public function create(Message $message) /** * {@inheritdoc} */ - public function update(Message $message) + public function update(MessageInterface $message): void { $localeId = $this->getLocaleId($message->getLocale()); /* @var KeySearchResults $results */ @@ -164,12 +166,13 @@ public function update(Message $message) /** * {@inheritdoc} */ - public function delete($locale, $domain, $key) + public function delete(string $locale, string $domain, string $key): void { /* @var KeySearchResults $results */ - $results = $this->client->key()->search($this->projectId, $this->getLocaleId($locale), [ + $results = $this->client->key()->search($this->projectId, [ 'tags' => $domain, - 'name' => $domain.'::'.$key + 'name' => $domain.'::'.$key, + 'locale_id' => $this->getLocaleId($locale), ]); foreach ($results as $searchResult) { @@ -183,7 +186,7 @@ public function delete($locale, $domain, $key) /** * {@inheritdoc} */ - public function export(MessageCatalogueInterface $catalogue) + public function export(MessageCatalogueInterface $catalogue, array $options = []): void { $locale = $catalogue->getLocale(); $localeId = $this->getLocaleId($locale); @@ -213,18 +216,20 @@ public function export(MessageCatalogueInterface $catalogue) // ignore empty translation files } } - - return $catalogue; } /** * {@inheritdoc} */ - public function import(MessageCatalogueInterface $catalogue) + public function import(MessageCatalogueInterface $catalogue, array $options = []): void { $locale = $catalogue->getLocale(); $localeId = $this->getLocaleId($locale); + if ($this->defaultLocale) { + $options = ['default_locale' => $this->defaultLocale]; + } + foreach ($this->domains as $domain) { $messages = []; @@ -234,12 +239,6 @@ public function import(MessageCatalogueInterface $catalogue) $catalogue->replace($messages, $domain); - if ($this->defaultLocale) { - $options = ['default_locale' => $this->defaultLocale]; - } else { - $options = []; - } - $data = XliffConverter::catalogueToContent($catalogue, $domain, $options); $file = sys_get_temp_dir() . '/' . $domain . '.' . $locale . '.xlf'; diff --git a/tests/Functional/BundleInitializationTest.php b/tests/Functional/BundleInitializationTest.php index d7f7efa..ddc260d 100644 --- a/tests/Functional/BundleInitializationTest.php +++ b/tests/Functional/BundleInitializationTest.php @@ -18,12 +18,12 @@ class BundleInitializationTest extends BaseBundleTestCase { - protected function getBundleClass() + protected function getBundleClass(): string { return TranslationAdapterPhraseAppBundle::class; } - public function testRegisterBundle() + public function testRegisterBundle(): void { $kernel = $this->createKernel(); $kernel->addBundle(HttplugBundle::class); @@ -31,11 +31,11 @@ public function testRegisterBundle() // Add some configuration $kernel->addConfigFile(__DIR__.'/config/default.yml'); - $this->bootKernel(); - $container = $this->getContainer(); + $kernel->boot(); + $container = $kernel->getContainer(); - $this->assertTrue($container->has('php_translation.adapter.phrase_app')); + self::assertTrue($container->has('php_translation.adapter.phrase_app')); $service = $container->get('php_translation.adapter.phrase_app'); - $this->assertInstanceOf(PhraseApp::class, $service); + self::assertInstanceOf(PhraseApp::class, $service); } }