Skip to content

Commit

Permalink
Add support for Symfony ^4.0|^5.0 + fix various deprecations + fix tr…
Browse files Browse the repository at this point in the history
…avis CI (#271)

- Fix Travis tests
- Minimum supported version: Symfony 3.4 version (LTS)
- Added support for the latest versions of Symfony
- Drop support for older versions of PHP (following the minimum supported version of most Symfony packages - 7.1)
  • Loading branch information
vanputten authored and monteiro committed Jan 14, 2020
1 parent 3baf98d commit 1593975
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 63 deletions.
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.1
- 7.2

Expand All @@ -14,6 +11,7 @@ cache:
- $HOME/.composer/cache/files

before_install:
- COMPOSER_MEMORY_LIMIT=-1
- composer self-update
- if [ "$STABILITY" = "dev" ]; then composer config minimum-stability dev; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then composer require symfony/symfony:${SYMFONY_VERSION}; fi;
Expand All @@ -29,11 +27,11 @@ script:
matrix:
fast_finish: true
include:
- php: 5.6
env: SYMFONY_VERSION='~2.7.0'
- php: 5.6
env: SYMFONY_VERSION='~2.8.0'
- php: 5.6
env: SYMFONY_VERSION='~3.4.0'
- php: 7.2
env: SYMFONY_VERSION='^3.4.0'
- php: 7.2
env: SYMFONY_VERSION='^4.0'
- php: 7.2
env: SYMFONY_VERSION='^5.0'
- php: 7.2
env: STABILITY=dev
4 changes: 2 additions & 2 deletions Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class DumpCommand extends Command
* @param TranslationDumper $dumper
* @param $kernelRootDir
*/
public function __construct(TranslationDumper $dumper, $kernelRootDir)
public function __construct(TranslationDumper $dumper, $projectDir)
{
$this->dumper = $dumper;
$this->kernelRootDir = $kernelRootDir;
$this->kernelRootDir = $projectDir . '/app';

parent::__construct();
}
Expand Down
35 changes: 21 additions & 14 deletions Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace Bazinga\Bundle\JsTranslationBundle\Controller;

use Bazinga\Bundle\JsTranslationBundle\Finder\TranslationFinder;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig_Environment;
use Twig\Environment;
use Twig\Loader\LoaderInterface;

/**
* @author William DURAND <[email protected]>
Expand All @@ -23,7 +25,7 @@ class Controller
private $translator;

/**
* @var Twig_Environment
* @var Environment
*/
private $twig;

Expand Down Expand Up @@ -62,25 +64,30 @@ class Controller
private $httpCacheTime;

/**
* @param TranslatorInterface $translator The translator.
* @param Twig_Environment $twig The twig environment.
* @param TranslationFinder $translationFinder The translation finder.
* @param string $cacheDir
* @param boolean $debug
* @param string $localeFallback
* @param string $defaultDomain
* @param int $httpCacheTime
* @param TranslatorInterface $translator The translator.
* @param Environment $twig The twig environment.
* @param TranslationFinder $translationFinder The translation finder.
* @param string $cacheDir
* @param boolean $debug
* @param string $localeFallback
* @param string $defaultDomain
* @param int $httpCacheTime
* @throws \InvalidArgumentException
*/
public function __construct(
TranslatorInterface $translator,
Twig_Environment $twig,
$translator,
Environment $twig,
TranslationFinder $translationFinder,
$cacheDir,
$debug = false,
$localeFallback = '',
$defaultDomain = '',
$httpCacheTime = 86400
) {
if (!$translator instanceof TranslatorInterface && !$translator instanceof LegacyTranslatorInterface) {
throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" as translator is not supported.', get_class($translator)));
}

$this->translator = $translator;
$this->twig = $twig;
$this->translationFinder = $translationFinder;
Expand Down
16 changes: 8 additions & 8 deletions Dumper/TranslationDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Bazinga\Bundle\JsTranslationBundle\Finder\TranslationFinder;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Twig_Environment;
use Twig\Environment;

/**
* @author Adrien Russo <[email protected]>
Expand All @@ -16,7 +16,7 @@ class TranslationDumper
const DEFAULT_TRANSLATION_PATTERN = '/translations/{domain}.{_format}';

/**
* @var \Twig_Environment
* @var Environment
*/
private $twig;

Expand Down Expand Up @@ -56,14 +56,14 @@ class TranslationDumper
private $defaultDomain;

/**
* @param Twig_Environment $twig The twig environment.
* @param TranslationFinder $finder The translation finder.
* @param FileSystem $filesystem The file system.
* @param string $localeFallback
* @param string $defaultDomain
* @param Environment $twig The twig environment.
* @param TranslationFinder $finder The translation finder.
* @param FileSystem $filesystem The file system.
* @param string $localeFallback
* @param string $defaultDomain
*/
public function __construct(
Twig_Environment $twig,
Environment $twig,
TranslationFinder $finder,
Filesystem $filesystem,
$localeFallback = '',
Expand Down
2 changes: 0 additions & 2 deletions Finder/TranslationFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Bazinga\Bundle\JsTranslationBundle\Finder;

use Symfony\Component\Finder\Finder;

/**
* @author William DURAND <[email protected]>
* @author Markus Poerschke <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</service>
<service id="bazinga.jstranslation.dump_command" class="Bazinga\Bundle\JsTranslationBundle\Command\DumpCommand" public="true">
<argument type="service" id="bazinga.jstranslation.translation_dumper" />
<argument>%kernel.root_dir%</argument>
<argument>%kernel.project_dir%</argument>
<tag name="console.command" command="bazinga:js-translation:dump" />
</service>
</services>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Dumper/TranslationDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function setUp()
$this->filesystem->mkdir($this->target);
}

public function tearDown()
public function tearDown(): void
{
if (is_dir($this->target)) {
$this->filesystem->remove($this->target);
Expand Down
10 changes: 6 additions & 4 deletions Tests/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public function getLogDir()

public function registerContainerConfiguration(LoaderInterface $loader)
{
if (self::VERSION_ID < 20800) {
$loader->load(__DIR__.'/config/older_versions_config.yml');
$loader->load(__DIR__.'/config/'.$this->environment.'.yml');

if (self::VERSION_ID >= 40400) {
$loader->load(__DIR__.'/config/base_config_44.yml');
} else {
$loader->load(__DIR__.'/config/'.$this->environment.'.yml');
$loader->load(__DIR__.'/config/base_config.yml');
}

if (self::VERSION_ID > 30200) {
$loader->load(__DIR__.'/config/disable_annotations.yml');
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/app/config/base_config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
framework:
secret: test
router: { resource: "%kernel.root_dir%/config/routing.yml" }
router: { resource: "%kernel.project_dir%/app/config/routing.yml" }
test: ~
translator: { enabled: true }
validation: { enabled: false }
Expand Down
10 changes: 10 additions & 0 deletions Tests/Fixtures/app/config/base_config_44.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# for symfony version >= 4.4.
imports:
- { resource: base_config.yml }

framework:
router:
utf8: true

twig:
exception_controller: null
2 changes: 1 addition & 1 deletion Tests/Fixtures/app/config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ framework:
translator:
fallbacks: ['en']
paths:
- "%kernel.root_dir%/Infrastructure/Ui/Translations"
- "%kernel.project_dir%/app/Infrastructure/Ui/Translations"
8 changes: 0 additions & 8 deletions Tests/Fixtures/app/config/older_versions_config.yml

This file was deleted.

25 changes: 13 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
}
],
"require": {
"symfony/framework-bundle": "~2.7|~3.1|~4.0",
"symfony/finder": "~2.7|~3.1|~4.0",
"symfony/console": "~2.7|~3.1|~4.0",
"symfony/intl": "~2.7|~3.1|~4.0",
"symfony/translation": "~2.7|~3.1|~4.0",
"symfony/twig-bundle": "~2.7|~3.1|~4.0"
"php": "^7.1",
"symfony/framework-bundle": "~3.4|~4.0|~5.0",
"symfony/finder": "~3.4|~4.0|~5.0",
"symfony/console": "~3.4|~4.0|~5.0",
"symfony/intl": "~3.4|~4.0|~5.0",
"symfony/translation": "~3.4|~4.0|~5.0",
"symfony/twig-bundle": "~3.4|~4.0|~5.0"
},
"require-dev": {
"symfony/asset": "~2.7|~3.1|~4.0",
"symfony/yaml": "~2.7|~3.1|~4.0",
"symfony/browser-kit": "~2.7|~3.1|~4.0",
"symfony/twig-bundle": "~2.7|~3.1|~4.0",
"symfony/phpunit-bridge": "~2.7|~3.1|~4.0",
"phpunit/phpunit": "^4.8|~5.7"
"symfony/asset": "~3.4|~4.0|~5.0",
"symfony/yaml": "~3.4|~4.0|~5.0",
"symfony/browser-kit": "~3.4|~4.0|~5.0",
"symfony/twig-bundle": "~3.4|~4.0|~5.0",
"symfony/phpunit-bridge": "^5.0",
"phpunit/phpunit": "^4.8|~5.7|~6.5"
},
"replace": {
"willdurand/expose-translation-bundle": "2.5.*"
Expand Down

0 comments on commit 1593975

Please sign in to comment.