Browse Source

Essai injection de dépendances

develop
Guillaume 3 years ago
parent
commit
5b1fb72dd8
11 changed files with 168 additions and 85 deletions
  1. +32
    -0
      config/dependencies.php
  2. +42
    -42
      config/services.yaml
  3. +9
    -12
      src/Command/TestCommand.php
  4. +1
    -1
      src/Controller/Dashboard/DashboardAdminController.php
  5. +6
    -0
      src/Controller/Site/PageAdminController.php
  6. +23
    -0
      src/Dependency/Definition/DefinitionDependency.php
  7. +0
    -30
      src/Dependency/Reminder/Reminder.php
  8. +20
    -0
      src/Dependency/Reminder/ReminderDependency.php
  9. +18
    -0
      src/Dependency/Ticket/TicketDependency.php
  10. +16
    -0
      src/Dependency/Ticket/TicketMessageDependency.php
  11. +1
    -0
      src/Kernel.php

+ 32
- 0
config/dependencies.php View File

@@ -0,0 +1,32 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function(ContainerConfigurator $configurator) {

$services = $configurator->services();

$baseDirectoryDependency = dirname(__FILE__).'/../src/Dependency/';
$directoriesDenpendencyInjection = scandir($baseDirectoryDependency);
$dependencies = [];
foreach($directoriesDenpendencyInjection as $directory) {
if($directory != '.' && $directory != '..' && is_dir($baseDirectoryDependency.$directory)) {
$filesDenpendencyInjection = scandir($baseDirectoryDependency.$directory);
foreach($filesDenpendencyInjection as $file) {
if($file != '.' && $file != '..') {
$classDependency = 'App\Dependency\\'.$directory.'\\'.str_replace('.php', '', $file) ;
$dependencies[] = new $classDependency;
}
}
}
}

foreach($dependencies as $dependency) {
$aliases = $dependency->getAliases();

foreach($aliases as $alias => $final) {
$services->alias($alias, $final);
}
}

};

+ 42
- 42
config/services.yaml View File

@@ -52,49 +52,49 @@ services:
# please note that last definitions always *replace* previous ones

# Definition
Lc\CaracoleBundle\Definition\MerchantSettingDefinition:
class: App\Definition\MerchantSettingDefinition
Lc\SovBundle\Definition\SiteSettingDefinition:
class: App\Definition\SiteSettingDefinition
#Lc\CaracoleBundle\Definition\MerchantSettingDefinition:
# class: App\Definition\MerchantSettingDefinition
#Lc\SovBundle\Definition\SiteSettingDefinition:
# class: App\Definition\SiteSettingDefinition

# Repository
Lc\SovBundle\Repository\Reminder\ReminderRepositoryInterface:
class: Lc\SovBundle\Repository\Reminder\ReminderRepository
Lc\SovBundle\Repository\File\FileRepositoryInterface:
class: Lc\SovBundle\Repository\File\FileRepository
Lc\SovBundle\Repository\Newsletter\NewsletterRepositoryInterface:
class: Lc\SovBundle\Repository\Newsletter\NewsletterRepository
Lc\SovBundle\Repository\Setting\SiteSettingRepositoryInterface:
class: Lc\SovBundle\Repository\Setting\SiteSettingRepository
Lc\SovBundle\Repository\Site\SiteRepositoryInterface:
class: Lc\SovBundle\Repository\Site\SiteRepository
Lc\SovBundle\Repository\Site\PageRepositoryInterface:
class: Lc\SovBundle\Repository\Site\PageRepository
Lc\SovBundle\Repository\Site\NewsRepositoryInterface:
class: Lc\SovBundle\Repository\Site\NewsRepository
Lc\SovBundle\Repository\Ticket\TicketRepositoryInterface:
class: Lc\SovBundle\Repository\Ticket\TicketRepository
Lc\SovBundle\Repository\Ticket\TicketMessageRepositoryInterface:
class: Lc\SovBundle\Repository\Ticket\TicketMessageRepository
Lc\SovBundle\Repository\User\GroupUserRepositoryInterface:
class: Lc\CaracoleBundle\Repository\User\GroupUserRepository
Lc\SovBundle\Repository\User\UserRepositoryInterface:
class: Lc\SovBundle\Repository\User\UserRepository
Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryInterface:
class: Lc\CaracoleBundle\Repository\Merchant\MerchantRepository
Lc\CaracoleBundle\Repository\User\UserMerchantRepositoryInterface:
class: Lc\CaracoleBundle\Repository\User\UserMerchantRepository
Lc\CaracoleBundle\Repository\User\VisitorRepositoryInterface:
class: Lc\CaracoleBundle\Repository\User\VisitorRepository
Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface:
class: Lc\CaracoleBundle\Repository\Section\SectionRepository
Lc\CaracoleBundle\Repository\PointSale\PointSaleRepositoryInterface:
class: Lc\CaracoleBundle\Repository\PointSale\PointSaleRepository
Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepositoryInterface:
class: Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepository
#Lc\SovBundle\Repository\Reminder\ReminderRepositoryInterface:
# class: Lc\SovBundle\Repository\Reminder\ReminderRepository
#Lc\SovBundle\Repository\File\FileRepositoryInterface:
# class: Lc\SovBundle\Repository\File\FileRepository
#Lc\SovBundle\Repository\Newsletter\NewsletterRepositoryInterface:
# class: Lc\SovBundle\Repository\Newsletter\NewsletterRepository
#Lc\SovBundle\Repository\Setting\SiteSettingRepositoryInterface:
# class: Lc\SovBundle\Repository\Setting\SiteSettingRepository
#Lc\SovBundle\Repository\Site\SiteRepositoryInterface:
# class: Lc\SovBundle\Repository\Site\SiteRepository
#Lc\SovBundle\Repository\Site\PageRepositoryInterface:
# class: Lc\SovBundle\Repository\Site\PageRepository
#Lc\SovBundle\Repository\Site\NewsRepositoryInterface:
# class: Lc\SovBundle\Repository\Site\NewsRepository
#Lc\SovBundle\Repository\Ticket\TicketRepositoryInterface:
# class: Lc\SovBundle\Repository\Ticket\TicketRepository
#Lc\SovBundle\Repository\Ticket\TicketMessageRepositoryInterface:
# class: Lc\SovBundle\Repository\Ticket\TicketMessageRepository
#Lc\SovBundle\Repository\User\GroupUserRepositoryInterface:
# class: Lc\CaracoleBundle\Repository\User\GroupUserRepository
#Lc\SovBundle\Repository\User\UserRepositoryInterface:
# class: Lc\SovBundle\Repository\User\UserRepository
#Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryInterface:
# class: Lc\CaracoleBundle\Repository\Merchant\MerchantRepository
#Lc\CaracoleBundle\Repository\User\UserMerchantRepositoryInterface:
# class: Lc\CaracoleBundle\Repository\User\UserMerchantRepository
#Lc\CaracoleBundle\Repository\User\VisitorRepositoryInterface:
# class: Lc\CaracoleBundle\Repository\User\VisitorRepository
#Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface:
# class: Lc\CaracoleBundle\Repository\Section\SectionRepository
#Lc\CaracoleBundle\Repository\PointSale\PointSaleRepositoryInterface:
# class: Lc\CaracoleBundle\Repository\PointSale\PointSaleRepository
#Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepositoryInterface:
# class: Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepository

# Factory
Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface:
class: Lc\CaracoleBundle\Factory\Reminder\ReminderFactory
Lc\SovBundle\Factory\Ticket\TicketFactoryInterface:
class: Lc\CaracoleBundle\Factory\Ticket\TicketFactory
#Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface:
# class: Lc\CaracoleBundle\Factory\Reminder\ReminderFactory
#Lc\SovBundle\Factory\Ticket\TicketFactoryInterface:
# class: Lc\CaracoleBundle\Factory\Ticket\TicketFactory

+ 9
- 12
src/Command/TestCommand.php View File

@@ -2,27 +2,25 @@

namespace App\Command;

use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQueryInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Lc\CaracoleBundle\Repository\Reminder\ReminderRepositoryQuery;
use Lc\SovBundle\Repository\Reminder\ReminderStore;
use Lc\SovBundle\Repository\Reminder\ReminderStoreInterface;

class TestCommand extends Command
{
protected static $defaultName = 'app:test';
protected static $defaultDescription = 'Add a short description for your command';
protected ReminderRepositoryQuery $query;
protected ReminderStore $store;
protected ReminderRepositoryQueryInterface $query;
protected ReminderStoreInterface $store;

public function __construct(
ReminderRepositoryQuery $query,
ReminderStore $store
)
{
ReminderRepositoryQueryInterface $query,
ReminderStoreInterface $store
) {
$this->query = $query;
$this->store = $store;

@@ -32,9 +30,8 @@ class TestCommand extends Command
protected function configure(): void
{
$this
->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
;
->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
->addOption('option1', null, InputOption::VALUE_NONE, 'Option description');
}

protected function execute(InputInterface $input, OutputInterface $output): int

+ 1
- 1
src/Controller/Dashboard/DashboardAdminController.php View File

@@ -40,7 +40,7 @@ class DashboardAdminController extends CaracDashboardController
[
MenuItem::linkToRoute('setting_merchant', '', 'carac_admin_setting_merchant'),
MenuItem::linkToRoute('setting_section', '', 'carac_admin_setting_section'),
MenuItem::linkToRoute('setting_global', '', 'sov_admin_setting_global'),
MenuItem::linkToRoute('setting_global', '', 'carac_admin_setting_site'),
]
);


+ 6
- 0
src/Controller/Site/PageAdminController.php View File

@@ -4,6 +4,7 @@ namespace App\Controller\Site;

use App\Entity\Site\Page;
use Lc\CaracoleBundle\Controller\Site\PageAdminController as CaracPageAdminController;
use Lc\SovBundle\Factory\Site\PageFactory;

class PageAdminController extends CaracPageAdminController
{
@@ -11,4 +12,9 @@ class PageAdminController extends CaracPageAdminController
{
return Page::class;
}

public function getEntityFactory(): string
{
return PageFactory::class;
}
}

+ 23
- 0
src/Dependency/Definition/DefinitionDependency.php View File

@@ -0,0 +1,23 @@
<?php

namespace App\Dependency\Definition;

use App\Definition\MerchantSettingDefinition;
use App\Definition\SectionSettingDefinition;
use App\Definition\SiteSettingDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
use Lc\SovBundle\Definition\SiteSettingDefinitionInterface;

class DefinitionDependency
{
public function getAliases()
{
return [
MerchantSettingDefinitionInterface::class => MerchantSettingDefinition::class,
SectionSettingDefinitionInterface::class => SectionSettingDefinition::class,
SiteSettingDefinitionInterface::class => SiteSettingDefinition::class,
];
}

}

+ 0
- 30
src/Dependency/Reminder/Reminder.php View File

@@ -1,30 +0,0 @@
<?php

namespace App\Dependency\Reminder;

use App\Entity\Reminder\Reminder;
use Lc\CaracoleBundle\Factory\Reminder\ReminderFactory;
use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
use Lc\SovBundle\Model\Reminder\ReminderInterface;
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryInterface;
use App\Repository\Reminder\ReminderRepository;

class ReminderDependency implements DependencyInterface
{

public function getAliases()
{
return [
ReminderInterface::class => Reminder::class,
ReminderFactoryInterface::class => ReminderFactory::class,
ReminderRepositoryInterface::class => ReminderRepository::class,

// doctrine entity
// factory
// repository
// repository query
// store
];
}

}

+ 20
- 0
src/Dependency/Reminder/ReminderDependency.php View File

@@ -0,0 +1,20 @@
<?php

namespace App\Dependency\Reminder;

use Lc\SovBundle\Repository\Reminder\ReminderStore;
use Lc\SovBundle\Repository\Reminder\ReminderStoreInterface;

class ReminderDependency
{
public function getAliases()
{
return [
//ReminderRepositoryInterface::class => ReminderRepository::class,
//ReminderRepositoryQueryInterface::class => ReminderRepositoryQuery::class,
//ReminderStoreInterface::class => ReminderStore::class,
//ReminderFactoryInterface::class => ReminderFactory::class,
];
}

}

+ 18
- 0
src/Dependency/Ticket/TicketDependency.php View File

@@ -0,0 +1,18 @@
<?php

namespace App\Dependency\Ticket;


use Lc\CaracoleBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Factory\Ticket\TicketFactoryInterface;

class TicketDependency
{
public function getAliases()
{
return [
TicketFactoryInterface::class => TicketFactory::class,
];
}

}

+ 16
- 0
src/Dependency/Ticket/TicketMessageDependency.php View File

@@ -0,0 +1,16 @@
<?php

namespace App\Dependency\Ticket;

use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactoryInterface;

class TicketMessageDependency
{
public function getAliases()
{
return [
//TicketMessageFactoryInterface::class => TicketMessageFactory::class,
];
}
}

+ 1
- 0
src/Kernel.php View File

@@ -18,6 +18,7 @@ class Kernel extends BaseKernel

if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
$container->import('../config/services.yaml');
$container->import('../config/dependencies.php');
$container->import('../config/{services}_'.$this->environment.'.yaml');
} elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) {
(require $path)($container->withPath($path), $this);

Loading…
Cancel
Save