Skip to content

Commit b97bce5

Browse files
author
Andrew Zhdanovskih
committed
Update packages and code:
- composer.json packages updated for use Symfony 5.1 and Twig 3 - services and configurations updated for avoid deprecations
1 parent df27524 commit b97bce5

File tree

4 files changed

+45
-39
lines changed

4 files changed

+45
-39
lines changed

composer.json

+20-20
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@
1212
],
1313
"require": {
1414
"php": "^7.2",
15-
"doctrine/common": "^2.8",
15+
"doctrine/common": "^2.12",
1616
"doctrine/doctrine-bundle": "^1.8|^2.0",
17-
"doctrine/orm": "^2.6|^3.0",
18-
"doctrine/persistence": "^1.0",
19-
"ramsey/uuid": "^3.8 || ^4",
17+
"doctrine/orm": "^2.7|^3.0",
18+
"doctrine/persistence": "^1.3",
19+
"ramsey/uuid": "^3.8|^4",
2020
"ramsey/uuid-doctrine": "^1.5",
21-
"symfony/config": "^4.1|^5.0",
22-
"symfony/dependency-injection": "^4.1|^5.0",
23-
"symfony/doctrine-bridge": "^4.1|^5.0",
24-
"symfony/finder": "^4.1|^5.0",
25-
"symfony/framework-bundle": "^4.1|^5.0",
26-
"symfony/polyfill-mbstring": "^1",
27-
"symfony/translation": "^4.1|^5.0",
28-
"symfony/twig-bridge": "^4.1|^5.0",
29-
"symfony/twig-bundle": "^4.1|^5.0",
30-
"twig/twig": "^2.4",
31-
"symfony/yaml": "^4.1|^5.0"
21+
"symfony/config": "^4.1|^5",
22+
"symfony/dependency-injection": "^4.1|^5",
23+
"symfony/doctrine-bridge": "^4.1|^5",
24+
"symfony/finder": "^4.1|^5",
25+
"symfony/framework-bundle": "^4.1|^5",
26+
"symfony/polyfill-mbstring": "*",
27+
"symfony/translation": "^4.1|^5",
28+
"symfony/twig-bridge": "^4.1|^5",
29+
"symfony/twig-bundle": "^4.1|^5",
30+
"twig/twig": "^2.4|^3",
31+
"symfony/yaml": "^4.1|^5"
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^8.1",
35-
"symfony/console": "^4.1|^5.0",
36-
"symfony/css-selector": "^4.1|^5.0",
37-
"symfony/dom-crawler": "^4.1|^5.0",
38-
"symfony/phpunit-bridge": "^4.1|^5.0",
39-
"symfony/var-dumper": "^4.1|^5.0"
35+
"symfony/console": "^4.1|^5",
36+
"symfony/css-selector": "^4.1|^5",
37+
"symfony/dom-crawler": "^4.1|^5",
38+
"symfony/phpunit-bridge": "^4.1|^5",
39+
"symfony/var-dumper": "^4.1|^5"
4040
},
4141
"extra": {
4242
"branch-alias": {

src/Command/MigrateToDatabaseCommand.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Style\SymfonyStyle;
19-
use Symfony\Component\DependencyInjection\ContainerInterface;
19+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
2020
use Symfony\Component\Translation\Translator;
2121
use Symfony\Contracts\Translation\TranslatorInterface;
2222

@@ -47,7 +47,7 @@ class MigrateToDatabaseCommand extends Command
4747
protected static $defaultName = 'creative:db-i18n:migrate';
4848

4949
/**
50-
* @var ContainerInterface
50+
* @var ParameterBagInterface
5151
*/
5252
private $container;
5353

@@ -74,17 +74,17 @@ class MigrateToDatabaseCommand extends Command
7474
/**
7575
* MigrateToDatabaseCommand constructor.
7676
*
77-
* @param ContainerInterface $container
78-
* @param TranslatorInterface $translator
79-
* @param ManagerRegistry $doctrine
80-
* @param string|null $name
77+
* @param ParameterBagInterface $container
78+
* @param TranslatorInterface $translator
79+
* @param ManagerRegistry $doctrine
80+
* @param string|null $name
8181
*/
82-
public function __construct(ContainerInterface $container, TranslatorInterface $translator, ManagerRegistry $doctrine, string $name = null)
82+
public function __construct(ParameterBagInterface $container, TranslatorInterface $translator, ManagerRegistry $doctrine, string $name = null)
8383
{
8484
parent::__construct($name);
8585
$this->container = $container;
8686
$this->translator = $translator;
87-
$this->entityClass = $this->container->getParameter('db_i18n.entity');
87+
$this->entityClass = $this->container->get('db_i18n.entity');
8888
$this->doctrine = $doctrine;
8989
}
9090

@@ -113,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
113113
throw new RuntimeException('Translator service of application has no \'getCatalogue\' method');
114114
}
115115

116-
if (!$this->container->hasParameter('locales') || !is_array($this->container->getParameter('locales'))) {
116+
if (!$this->container->has('locales') || !is_array($this->container->get('locales'))) {
117117
throw new RuntimeException('Application container must have a \'locales\' parameter, and this parameter must be an array');
118118
}
119119

@@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
125125
$catalogue = $this->translator->getCatalogue($locale);
126126

127127
$forExport = $catalogue->all($domain);
128-
$exported = $this->exportToDatabase($forExport, $locale, $this->container->getParameter('db_i18n.domain'));
128+
$exported = $this->exportToDatabase($forExport, $locale, $this->container->get('db_i18n.domain'));
129129

130130
$io->writeln(sprintf(
131131
'Loaded form %s: %u messages, exported to database: %s',
@@ -210,7 +210,7 @@ protected function checkEntityExists(string $locale, string $key): EntityInterfa
210210
*/
211211
protected function getLocale(string $filename): ?string
212212
{
213-
$locales = $this->container->getParameter('locales');
213+
$locales = $this->container->get('locales');
214214
$locale = null;
215215
foreach ($locales as $localeParam) {
216216
if (strpos($filename, $localeParam) !== false) {
@@ -236,7 +236,7 @@ protected function locateFile(string $path): string
236236
if (strpos($path, '/') === 0) {
237237
$realPath = $path;
238238
} else {
239-
$realPath = $this->container->getParameter('kernel.root_dir') . '/../' . $path;
239+
$realPath = $this->container->get('kernel.root_dir') . '/../' . $path;
240240
}
241241

242242
if (!is_file($realPath) || !is_readable($realPath)) {

src/Loader/DbLoader.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Creative\DbI18nBundle\Interfaces\TranslationRepositoryInterface;
1313
use Doctrine\Persistence\ManagerRegistry;
1414
use Symfony\Component\DependencyInjection\ContainerInterface;
15+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
1516
use Symfony\Component\Translation\Exception\InvalidResourceException;
1617
use Symfony\Component\Translation\Exception\NotFoundResourceException;
1718
use Symfony\Component\Translation\Loader\LoaderInterface;
@@ -35,13 +36,13 @@ class DbLoader implements LoaderInterface, DbLoaderInterface
3536

3637
/**
3738
* DbLoader constructor.
38-
* @param ContainerInterface $container
39-
* @param ManagerRegistry $doctrine
39+
* @param ParameterBagInterface $container
40+
* @param ManagerRegistry $doctrine
4041
*/
41-
public function __construct(ContainerInterface $container, ManagerRegistry $doctrine)
42+
public function __construct(ParameterBagInterface $container, ManagerRegistry $doctrine)
4243
{
4344
$this->doctrine = $doctrine;
44-
$this->entityClass = $container->getParameter('db_i18n.entity');
45+
$this->entityClass = $container->get('db_i18n.entity');
4546
}
4647

4748
/**
@@ -56,7 +57,7 @@ public function __construct(ContainerInterface $container, ManagerRegistry $doct
5657
* @throws NotFoundResourceException when the resource cannot be found
5758
* @throws InvalidResourceException when the resource cannot be loaded
5859
*/
59-
public function load($resource, $locale, $domain = 'messages')
60+
public function load($resource, string $locale, string $domain = 'messages'): MessageCatalogue
6061
{
6162
$messages = $this->getRepository()->findByDomainAndLocale($domain, $locale);
6263

src/Resources/config/config.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ services:
77
resource: '../../../src'
88
exclude: '../../../src/{Entity,Resources}'
99

10+
doctrine.orm.naming_strategy.underscore:
11+
class: Doctrine\ORM\Mapping\UnderscoreNamingStrategy
12+
arguments:
13+
$numberAware: true
14+
1015
translation.loader.db:
1116
class: Creative\DbI18nBundle\Loader\DbLoader
1217
public: '%kernel.debug%'
1318
arguments:
14-
- '@service_container'
19+
- '@parameter_bag'
1520
- '@doctrine'
1621
tags:
1722
- { name: translation.loader, alias: db }
@@ -23,7 +28,7 @@ services:
2328

2429
Creative\DbI18nBundle\Command\MigrateToDatabaseCommand:
2530
arguments:
26-
- '@service_container'
31+
- '@parameter_bag'
2732
- '@translator.default'
2833
- '@doctrine'
2934
tags: [ console.command ]

0 commit comments

Comments
 (0)