Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 80875c7

Browse files
author
Andrew Zhdanovskih
committed
Update all for use new packages and services
1 parent e1c2071 commit 80875c7

File tree

13 files changed

+170
-21
lines changed

13 files changed

+170
-21
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
vendor
22
composer.lock
33
.phpunit.result.cache
4+
var/*
5+
tests/output

‎composer.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"symfony/translation": "^4.1|^5.0",
2828
"symfony/twig-bridge": "^4.1|^5.0",
2929
"symfony/twig-bundle": "^4.1|^5.0",
30-
"twig/extensions": "^1.5",
3130
"twig/twig": "^2.4",
3231
"symfony/yaml": "^4.1|^5.0"
3332
},
@@ -53,6 +52,8 @@
5352
}
5453
},
5554
"autoload-dev": {
56-
"Creative\\DbI18nBundle\\Tests\\": "tests/"
55+
"psr-4": {
56+
"Creative\\DbI18nBundle\\Tests\\": "tests/"
57+
}
5758
}
5859
}

‎phpunit.xml.dist‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
55
backupGlobals="false"
66
colors="true"
7+
bootstrap="./vendor/autoload.php"
78
>
89
<php>
910
<ini name="error_reporting" value="-1" />
1011
<env name="APP_ENV" value="test" />
12+
<env name="APP_DEBUG" value="true" />
1113
<env name="SHELL_VERBOSITY" value="-1" />
14+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=999999" />
15+
<env name="SYMFONY_PHPUNIT_VERSION" value="8.1" />
16+
<env name="KERNEL_CLASS" value="Creative\DbI18nBundle\Tests\Kernel" />
1217
</php>
1318

1419
<testsuites>
@@ -22,4 +27,8 @@
2227
<directory>src</directory>
2328
</whitelist>
2429
</filter>
30+
31+
<listeners>
32+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
33+
</listeners>
2534
</phpunit>

‎src/Command/MigrateToDatabaseCommand.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use Creative\DbI18nBundle\Interfaces\EntityInterface;
1111
use Creative\DbI18nBundle\Interfaces\TranslationRepositoryInterface;
12-
use Symfony\Bridge\Doctrine\RegistryInterface;
12+
use Doctrine\Persistence\ManagerRegistry;
1313
use Symfony\Component\Console\Command\Command;
1414
use Symfony\Component\Console\Exception\RuntimeException;
1515
use Symfony\Component\Console\Input\InputArgument;
@@ -62,7 +62,7 @@ class MigrateToDatabaseCommand extends Command
6262
private $entityClass;
6363

6464
/**
65-
* @var RegistryInterface
65+
* @var ManagerRegistry
6666
*/
6767
private $doctrine;
6868

@@ -76,10 +76,10 @@ class MigrateToDatabaseCommand extends Command
7676
*
7777
* @param ContainerInterface $container
7878
* @param TranslatorInterface $translator
79-
* @param RegistryInterface $doctrine
79+
* @param ManagerRegistry $doctrine
8080
* @param string|null $name
8181
*/
82-
public function __construct(ContainerInterface $container, TranslatorInterface $translator, RegistryInterface $doctrine, string $name = null)
82+
public function __construct(ContainerInterface $container, TranslatorInterface $translator, ManagerRegistry $doctrine, string $name = null)
8383
{
8484
parent::__construct($name);
8585
$this->container = $container;

‎src/DependencyInjection/DbI18nExtension.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ public function load(array $configs, ContainerBuilder $container): void
3535
$container->setParameter('db_i18n.entity', $config['entity']);
3636
$container->setParameter('db_i18n.domain', $config['domain']);
3737
$container->setParameter('db_i18n.root_dir', __DIR__ . '/../');
38-
$container->setParameter('db_i18n.translation_dir', __DIR__ . '/../Resources/translations');
38+
$container->setParameter('db_i18n.translation_dir', $container->getParameter('kernel.cache_dir'));
3939

40+
$localeNames = [$container->getParameter('kernel.default_locale')];
4041
if ($container->hasParameter('locales') && is_array($locales = $container->getParameter('locales'))) {
41-
$this->makeLocaleFiles($locales, $container->getParameter('db_i18n.translation_dir'), $container->getParameter('db_i18n.domain'));
42+
$localeNames = $locales;
4243
}
44+
$this->makeLocaleFiles($localeNames, $container->getParameter('db_i18n.translation_dir'), $container->getParameter('db_i18n.domain'));
4345

4446
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
4547
$loader->load('config.yaml');

‎src/Interfaces/TranslationRepositoryInterface.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Creative\DbI18nBundle\Interfaces;
99

1010
use Doctrine\Common\Collections\Collection;
11-
use Doctrine\Common\Persistence\ObjectRepository;
11+
use Doctrine\Persistence\ObjectRepository;
1212

1313
interface TranslationRepositoryInterface extends ObjectRepository
1414
{

‎src/Loader/DbLoader.php‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
use Creative\DbI18nBundle\Interfaces\DbLoaderInterface;
1111
use Creative\DbI18nBundle\Interfaces\EntityInterface;
1212
use Creative\DbI18nBundle\Interfaces\TranslationRepositoryInterface;
13-
use Doctrine\Common\Persistence\ObjectRepository;
14-
use Doctrine\ORM\EntityManagerInterface;
13+
use Doctrine\Persistence\ManagerRegistry;
1514
use Symfony\Component\DependencyInjection\ContainerInterface;
1615
use Symfony\Component\Translation\Exception\InvalidResourceException;
1716
use Symfony\Component\Translation\Exception\NotFoundResourceException;
@@ -25,7 +24,7 @@
2524
class DbLoader implements LoaderInterface, DbLoaderInterface
2625
{
2726
/**
28-
* @var EntityManagerInterface
27+
* @var ManagerRegistry
2928
*/
3029
private $doctrine;
3130

@@ -37,9 +36,9 @@ class DbLoader implements LoaderInterface, DbLoaderInterface
3736
/**
3837
* DbLoader constructor.
3938
* @param ContainerInterface $container
40-
* @param EntityManagerInterface $doctrine
39+
* @param ManagerRegistry $doctrine
4140
*/
42-
public function __construct(ContainerInterface $container, EntityManagerInterface $doctrine)
41+
public function __construct(ContainerInterface $container, ManagerRegistry $doctrine)
4342
{
4443
$this->doctrine = $doctrine;
4544
$this->entityClass = $container->getParameter('db_i18n.entity');
@@ -73,10 +72,15 @@ public function load($resource, $locale, $domain = 'messages')
7372
}
7473

7574
/**
76-
* @return TranslationRepositoryInterface|ObjectRepository
75+
* {@inheritDoc}
7776
*/
7877
public function getRepository(): TranslationRepositoryInterface
7978
{
80-
return $this->doctrine->getRepository($this->entityClass);
79+
$repository = $this->doctrine->getRepository($this->entityClass);
80+
if ($repository instanceof TranslationRepositoryInterface) {
81+
return $repository;
82+
}
83+
84+
throw new \RuntimeException(\sprintf('Cannot load repository %s', TranslationRepositoryInterface::class));
8185
}
8286
}

‎src/Repository/TranslationRepository.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Creative\DbI18nBundle\Interfaces\TranslationRepositoryInterface;
77
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
88
use Doctrine\Common\Collections\ArrayCollection;
9-
use Symfony\Bridge\Doctrine\RegistryInterface;
9+
use Doctrine\Persistence\ManagerRegistry;
1010

1111
/**
1212
* @method Translation|null find($id, $lockMode = null, $lockVersion = null)
@@ -19,9 +19,9 @@ class TranslationRepository extends ServiceEntityRepository implements Translati
1919
/**
2020
* TranslationRepository constructor.
2121
*
22-
* @param RegistryInterface $registry
22+
* @param ManagerRegistry $registry
2323
*/
24-
public function __construct(RegistryInterface $registry)
24+
public function __construct(ManagerRegistry $registry)
2525
{
2626
parent::__construct($registry, Translation::class);
2727
}

‎src/Resources/config/config.yaml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ services:
99

1010
translation.loader.db:
1111
class: Creative\DbI18nBundle\Loader\DbLoader
12+
public: '%kernel.debug%'
1213
arguments:
1314
- '@service_container'
14-
- '@doctrine.orm.entity_manager'
15+
- '@doctrine'
1516
tags:
1617
- { name: translation.loader, alias: db }
1718

1819
Creative\DbI18nBundle\Interfaces\TranslationRepositoryInterface:
20+
class: Creative\DbI18nBundle\Repository\TranslationRepository
1921
tags:
2022
- { name: doctrine.repository_service }
2123

2224
Creative\DbI18nBundle\Command\MigrateToDatabaseCommand:
25+
arguments:
26+
- '@service_container'
27+
- '@translator.default'
28+
- '@doctrine'
2329
tags: [ console.command ]

‎tests/Kernel.php‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* 23.03.2020
4+
*/
5+
6+
declare(strict_types=1);
7+
8+
namespace Creative\DbI18nBundle\Tests;
9+
10+
use Creative\DbI18nBundle\DbI18nBundle;
11+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
12+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
14+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
15+
16+
class Kernel extends BaseKernel
17+
{
18+
use MicroKernelTrait;
19+
20+
/**
21+
* @inheritDoc
22+
*/
23+
public function registerBundles()
24+
{
25+
return [
26+
new FrameworkBundle(),
27+
new DoctrineBundle(),
28+
new DbI18nBundle(),
29+
];
30+
}
31+
32+
/**
33+
* @inheritDoc
34+
*/
35+
protected function configureRoutes(\Symfony\Component\Routing\RouteCollectionBuilder $routes)
36+
{
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
protected function configureContainer(\Symfony\Component\DependencyInjection\ContainerBuilder $c, \Symfony\Component\Config\Loader\LoaderInterface $loader)
43+
{
44+
$loader->load(__DIR__ . '/doctrine.yaml');
45+
$loader->load(__DIR__ . '/../src/Resources/config', 'glob');
46+
}
47+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /