Skip to content

Commit 5281526

Browse files
author
stephaneDecockLocastic
committed
Add theme factory service
1 parent 614fbfb commit 5281526

4 files changed

Lines changed: 41 additions & 4 deletions

File tree

src/Factory/ThemeFactory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Locastic\SymfonyTranslationBundle\Factory;
6+
7+
use Locastic\SymfonyTranslationBundle\Model\Theme;
8+
use Locastic\SymfonyTranslationBundle\Model\ThemeInterface;
9+
10+
final class ThemeFactory implements ThemeFactoryInterface
11+
{
12+
public function createNew(string $name, string $path): ThemeInterface
13+
{
14+
return new Theme($name, $path);
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Locastic\SymfonyTranslationBundle\Factory;
6+
7+
use Locastic\SymfonyTranslationBundle\Model\ThemeInterface;
8+
9+
interface ThemeFactoryInterface
10+
{
11+
public function createNew(string $name, string $path): ThemeInterface;
12+
}

src/Provider/ThemesProvider.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44

55
namespace Locastic\SymfonyTranslationBundle\Provider;
66

7-
use Locastic\SymfonyTranslationBundle\Model\Theme;
7+
use Locastic\SymfonyTranslationBundle\Factory\ThemeFactoryInterface;
88
use Locastic\SymfonyTranslationBundle\Model\ThemeInterface;
99

1010
final class ThemesProvider implements ThemesProviderInterface
1111
{
1212
private DefaultTranslationDirectoryProviderInterface $defaultTranslationDirectoryProvider;
1313

14-
public function __construct(DefaultTranslationDirectoryProviderInterface $defaultTranslationDirectoryProvider)
15-
{
14+
private ThemeFactoryInterface $themeFactory;
15+
16+
public function __construct(
17+
DefaultTranslationDirectoryProviderInterface $defaultTranslationDirectoryProvider,
18+
ThemeFactoryInterface $themeFactory
19+
) {
1620
$this->defaultTranslationDirectoryProvider = $defaultTranslationDirectoryProvider;
21+
$this->themeFactory = $themeFactory;
1722
}
1823

1924
public function getAll(): array
@@ -28,6 +33,6 @@ public function findOneByName(string $name): ?ThemeInterface
2833

2934
public function getDefaultTheme(): ThemeInterface
3035
{
31-
return new Theme(self::NAME_DEFAULT, $this->defaultTranslationDirectoryProvider->getDefaultDirectory());
36+
return $this->themeFactory->createNew(self::NAME_DEFAULT, $this->defaultTranslationDirectoryProvider->getDefaultDirectory());
3237
}
3338
}

src/Resources/config/services.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
</service>
2424

2525
<!-- Factories -->
26+
<service id="Locastic\SymfonyTranslationBundle\Factory\ThemeFactory" />
27+
<service id="Locastic\SymfonyTranslationBundle\Factory\ThemeFactoryInterface"
28+
alias="Locastic\SymfonyTranslationBundle\Factory\ThemeFactory" />
29+
2630
<service id="Locastic\SymfonyTranslationBundle\Factory\TranslationMigrationFactory" />
2731
<service id="Locastic\SymfonyTranslationBundle\Factory\TranslationMigrationFactoryInterface"
2832
alias="Locastic\SymfonyTranslationBundle\Factory\TranslationMigrationFactory" />

0 commit comments

Comments
 (0)