Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP 8 and Symfony 5.2 support. #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 13 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
44 changes: 31 additions & 13 deletions src/Bridge/Symfony/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,31 @@ 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);

$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'])
Expand Down
31 changes: 15 additions & 16 deletions src/PhraseApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

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;
use FAPI\PhraseApp\PhraseAppClient;
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;
Expand Down Expand Up @@ -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), [
Expand All @@ -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());

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 = [];

Expand All @@ -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';
Expand Down
12 changes: 6 additions & 6 deletions tests/Functional/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@

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);

// 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);
}
}