Skip to content

Add Symfony 4 support #19

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

Merged
merged 6 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ matrix:
- php: 7.0
env: SYMFONY_VERSION=2.8.*
- php: 7.1
env: SYMFONY_VERSION=3.4.x-dev
env: SYMFONY_VERSION=3.4.*
- php: 7.1
env: SYMFONY_VERSION=4.0.x-dev
env: SYMFONY_VERSION=4.0.*
- php: 7.0
env: SYMFONY_VERSION=3.0.*
- php: 7.0
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"require": {
"php": "^5.5 || ^7.0",
"php-translation/common": "^0.2.1",
"symfony/translation": "^2.7 || ^3.0",
"symfony/translation": "^2.7 || ^3.0 || ^4.0",
"nyholm/nsa": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.5 || ^6.2",
"symfony/framework-bundle": "^2.7 || ^3.0"
"symfony/framework-bundle": "^2.7 || ^3.0 || ^4.0"
},
"autoload": {
"psr-4": {
Expand Down
26 changes: 11 additions & 15 deletions src/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

namespace Translation\SymfonyStorage;

use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader as SymfonyTranslationLoader;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\MessageCatalogueInterface;
use Symfony\Component\Translation\Reader\TranslationReader;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class does not exist in sf 3.x.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nyholm that's an interesting case :) TranslationReader does exist since 3.4, but TranslationLoader is deprecated since 3.4 and exists only until 4.0. So, with TranslationReader we can continue supporting the latest version of 3.x and the new versions of 4.x. But if you also want to still maintain 2.8, 3.0, 3.1, 3.2, and 3.3 (I see in Travis config you do it now) - we need to write more legacy code to support those versions. So to move forward, I need to know what do you have in mind about it and what is your further strategy for maintenance of this bundle?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good practice is to support the last 2 LTS versions of symfony. I think we need to write more code here to support both sf 4.0 and sf 2.8.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternatively You create 0.5 and say if one wants to use this on sf older than 3.4 it should use 0.3.2. There is not a lot of commits here so this could work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, That is an option. But Im not sure I want to go down that route. Better to try to support all versions in master.

use Symfony\Component\Translation\Writer\TranslationWriter;
use Translation\Common\Model\Message;
use Translation\Common\Storage;
use Translation\Common\TransferableStorage;

/**
* This storage uses Symfony's writer and loader.
* This storage uses Symfony's writer and reader.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
Expand All @@ -32,9 +32,9 @@ final class FileStorage implements Storage, TransferableStorage
private $writer;

/**
* @var TranslationLoader|SymfonyTranslationLoader
* @var TranslationReader
*/
private $loader;
private $reader;

/**
* @var array directory path
Expand All @@ -52,17 +52,13 @@ final class FileStorage implements Storage, TransferableStorage
private $catalogues;

/**
* @param TranslationWriter $writer
* @param SymfonyTranslationLoader|TranslationLoader $loader
* @param array $dir
* @param array $options
* @param TranslationWriter $writer
* @param TranslationReader $reader
* @param array $dir
* @param array $options
*/
public function __construct(TranslationWriter $writer, $loader, array $dir, array $options = [])
public function __construct(TranslationWriter $writer, TranslationReader $reader, array $dir, array $options = [])
{
if (!$loader instanceof SymfonyTranslationLoader && !$loader instanceof TranslationLoader) {
throw new \LogicException('Second parameter of FileStorage must be a Symfony translation loader or implement Translation\SymfonyStorage\TranslationLoader');
}

if (empty($dir)) {
throw new \LogicException('Third parameter of FileStorage cannot be empty');
}
Expand All @@ -73,7 +69,7 @@ public function __construct(TranslationWriter $writer, $loader, array $dir, arra
}

$this->writer = $writer;
$this->loader = $loader;
$this->reader = $reader;
$this->dir = $dir;
$this->options = $options;
}
Expand Down Expand Up @@ -199,7 +195,7 @@ private function loadCatalogue($locale, array $dirs)
$currentCatalogue = new MessageCatalogue($locale);
foreach ($dirs as $path) {
if (is_dir($path)) {
$this->loader->loadMessages($path, $currentCatalogue);
$this->reader->read($path, $currentCatalogue);
}
}

Expand Down