Browse Source

Factory

develop
Guillaume 3 years ago
parent
commit
9c5622e13d
22 changed files with 287 additions and 9 deletions
  1. +18
    -0
      Factory/File/FileFactory.php
  2. +8
    -0
      Factory/File/FileFactoryInterface.php
  3. +18
    -0
      Factory/Newsletter/NewsletterFactory.php
  4. +8
    -0
      Factory/Newsletter/NewsletterFactoryInterface.php
  5. +3
    -2
      Factory/Setting/SiteSettingFactory.php
  6. +8
    -0
      Factory/Setting/SiteSettingFactoryInterface.php
  7. +18
    -0
      Factory/Site/NewsFactory.php
  8. +8
    -0
      Factory/Site/NewsFactoryInterface.php
  9. +3
    -2
      Factory/Site/PageFactory.php
  10. +8
    -0
      Factory/Site/PageFactoryInterface.php
  11. +3
    -2
      Factory/Site/SiteFactory.php
  12. +8
    -0
      Factory/Site/SiteFactoryInterface.php
  13. +2
    -1
      Factory/Ticket/TicketFactory.php
  14. +2
    -1
      Factory/Ticket/TicketMessageFactory.php
  15. +17
    -0
      Factory/User/GroupUserFactory.php
  16. +8
    -0
      Factory/User/GroupUserFactoryInterface.php
  17. +2
    -1
      Factory/User/UserFactory.php
  18. +8
    -0
      Factory/User/UserFactoryInterface.php
  19. +108
    -0
      Maker/FactoryMaker.php
  20. +4
    -0
      Resources/config/services.yaml
  21. +17
    -0
      Resources/maker/factory/factory.tpl.php
  22. +8
    -0
      Resources/maker/factory/factory_interface.tpl.php

+ 18
- 0
Factory/File/FileFactory.php View File

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

namespace Lc\SovBundle\Factory\File;

use App\Entity\File\File;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\File\FileInterface;

class FileFactory extends AbstractFactory implements FileFactoryInterface
{
public function create(): FileInterface
{
$file = new File();

return $file;
}

}

+ 8
- 0
Factory/File/FileFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\File;

interface FileFactoryInterface
{

}

+ 18
- 0
Factory/Newsletter/NewsletterFactory.php View File

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

namespace Lc\SovBundle\Factory\Newsletter;

use App\Entity\Newsletter\Newsletter;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;

class NewsletterFactory extends AbstractFactory implements NewsletterFactoryInterface
{
public function create(): NewsletterInterface
{
$newsletter = new Newsletter();

return $newsletter;
}

}

+ 8
- 0
Factory/Newsletter/NewsletterFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\Newsletter;

interface NewsletterFactoryInterface
{

}

+ 3
- 2
Factory/Setting/SiteSettingFactory.php View File

@@ -4,10 +4,11 @@ namespace Lc\SovBundle\Factory\Setting;

use App\Entity\Setting\SiteSetting;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Setting\SiteSettingInterface;

class SiteSettingFactory extends AbstractFactory
class SiteSettingFactory extends AbstractFactory implements SiteSettingFactoryInterface
{
public function create()
public function create(): SiteSettingInterface
{
$siteSetting = new SiteSetting();


+ 8
- 0
Factory/Setting/SiteSettingFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\Setting;

interface SiteSettingFactoryInterface
{

}

+ 18
- 0
Factory/Site/NewsFactory.php View File

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

namespace Lc\SovBundle\Factory\Site;

use App\Entity\Site\News;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Site\NewsInterface;

class NewsFactory extends AbstractFactory implements NewsFactoryInterface
{
public function create(): NewsInterface
{
$news = new News();

return $news;
}

}

+ 8
- 0
Factory/Site/NewsFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\Site;

interface NewsFactoryInterface
{

}

+ 3
- 2
Factory/Site/PageFactory.php View File

@@ -4,10 +4,11 @@ namespace Lc\SovBundle\Factory\Site;

use App\Entity\Site\Page;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Site\PageInterface;

class PageFactory extends AbstractFactory
class PageFactory extends AbstractFactory implements PageFactoryInterface
{
public function create()
public function create(): PageInterface
{
$page = new Page();


+ 8
- 0
Factory/Site/PageFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\Site;

interface PageFactoryInterface
{

}

+ 3
- 2
Factory/Site/SiteFactory.php View File

@@ -4,10 +4,11 @@ namespace Lc\SovBundle\Factory\Site;

use App\Entity\Site\Site;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Site\SiteInterface;

class SiteFactory extends AbstractFactory
class SiteFactory extends AbstractFactory implements SiteFactoryInterface
{
public function create()
public function create(): SiteInterface
{
$site = new Site();


+ 8
- 0
Factory/Site/SiteFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\Site;

interface SiteFactoryInterface
{

}

+ 2
- 1
Factory/Ticket/TicketFactory.php View File

@@ -4,6 +4,7 @@ namespace Lc\SovBundle\Factory\Ticket;

use App\Entity\Ticket\Ticket;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Ticket\TicketInterface;

class TicketFactory extends AbstractFactory implements TicketFactoryInterface
{
@@ -14,7 +15,7 @@ class TicketFactory extends AbstractFactory implements TicketFactoryInterface
$this->ticketMessageFactory = $ticketMessageFactory;
}

public function create()
public function create(): TicketInterface
{
$ticket = new Ticket();


+ 2
- 1
Factory/Ticket/TicketMessageFactory.php View File

@@ -4,10 +4,11 @@ namespace Lc\SovBundle\Factory\Ticket;

use App\Entity\Ticket\TicketMessage;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Ticket\TicketMessageInterface;

class TicketMessageFactory extends AbstractFactory implements TicketMessageFactoryInterface
{
public function create()
public function create(): TicketMessageInterface
{
$ticketMessage = new TicketMessage();


+ 17
- 0
Factory/User/GroupUserFactory.php View File

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

namespace Lc\SovBundle\Factory\User;

use App\Entity\User\GroupUser;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\User\GroupUserInterface;

class GroupUserFactory extends AbstractFactory implements GroupUserFactoryInterface
{
public function create(): GroupUserInterface
{
$groupUser = new GroupUser();

return $groupUser;
}
}

+ 8
- 0
Factory/User/GroupUserFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\User;

interface GroupUserFactoryInterface
{

}

+ 2
- 1
Factory/User/UserFactory.php View File

@@ -4,10 +4,11 @@ namespace Lc\SovBundle\Factory\User;

use App\Entity\User\User;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\User\UserInterface;

class UserFactory extends AbstractFactory
{
public function create()
public function create(): UserInterface
{
$user = new User();


+ 8
- 0
Factory/User/UserFactoryInterface.php View File

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

namespace Lc\SovBundle\Factory\User;

interface UserFactoryInterface
{

}

+ 108
- 0
Maker/FactoryMaker.php View File

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

namespace Lc\SovBundle\Maker;

use Doctrine\Common\Annotations\Annotation;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;

use function Symfony\Component\String\u;

class FactoryMaker extends AbstractMaker
{
public static function getCommandName(): string
{
return 'make:factory';
}

public static function getCommandDescription(): string
{
return 'Creates a factory';
}

public function configureCommand(Command $command, InputConfiguration $inputConf)
{
$command
/*->addArgument(
'factory-class',
InputArgument::OPTIONAL,
'Choose a name for your factory (e.g. <fg=yellow>MyEntityFactory</>)'
)*/
->addArgument(
'namespace',
InputArgument::OPTIONAL,
'Namespace (e.g. <fg=yellow>Lc\SovBundle\Factory</>)'
)
->addArgument(
'domain',
InputArgument::OPTIONAL,
'Domain (e.g. <fg=yellow>Order</>)'
)
->addArgument(
'entity-class',
InputArgument::OPTIONAL,
'Define the entity (e.g. <fg=yellow>MyEntity</>)'
)
->setHelp('');
}

public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
{
$entityDetails = $generator->createClassNameDetails(
$input->getArgument('entity-class'),
'Entity\\',
''
);

$factoryClass = $input->getArgument('entity-class') . 'Factory';
$factoryDetails = $generator->createClassNameDetails(
$factoryClass,
'Factory\\',
''
);

$options = [
'namespace_path' => $input->getArgument('namespace'),
'domain' => $input->getArgument('domain'),
'entity_class' => $input->getArgument('entity-class'),
'entity' => $entityDetails->getFullName(),
'entity_variable' => '$' . u($input->getArgument('entity-class'))->camel()
];

$generator->generateController(
$factoryDetails->getFullName(),
__DIR__ . '/../Resources/maker/factory/factory.tpl.php',
$options
);

$interfaceName = $factoryClass . 'Interface';
$generator->generateFile(
$generator->getRootDirectory() . '/src/Factory/' . $interfaceName . '.php',
__DIR__ . '/../Resources/maker/factory/factory_interface.tpl.php',
[
'namespace_path' => $input->getArgument('namespace'),
'domain' => $input->getArgument('domain'),
'interface_name' => $interfaceName,
]
);

$generator->writeChanges();

$this->writeSuccessMessage($io);
$io->text('Next: Open your new factory class and configure it!');
}

public function configureDependencies(DependencyBuilder $dependencies)
{
$dependencies->addClassDependency(
Annotation::class,
'doctrine/annotations'
);
}
}

+ 4
- 0
Resources/config/services.yaml View File

@@ -25,3 +25,7 @@ services:
arguments: ["@.inner"]
# EasyCorp\Bundle\EasyAdminBundle\Form\Type\CrudFormType:
# class: Lc\SovBundle\Form\Type\CrudFormType

Lc\SovBundle\Maker\:
resource: '../../Maker/'
tags: [ 'maker.command' ]

+ 17
- 0
Resources/maker/factory/factory.tpl.php View File

@@ -0,0 +1,17 @@
<?= "<?php\n" ?>

namespace <?= $namespace_path; ?>\<?= $domain; ?>;

use App\Entity\<?= $domain; ?>\<?= $entity_class ?>;
use Lc\SovBundle\Factory\AbstractFactory;

class <?= $class_name; ?> extends AbstractFactory implements <?= $class_name; ?>Interface
{
public function create(): <?= $entity_class ?>Interface
{
<?= $entity_variable ?> = new <?= $entity_class ?>();

return <?= $entity_variable ?>;
}

}

+ 8
- 0
Resources/maker/factory/factory_interface.tpl.php View File

@@ -0,0 +1,8 @@
<?= "<?php\n" ?>

namespace <?= $namespace_path; ?>\<?= $domain; ?>;

interface <?= $interface_name; ?>
{

}

Loading…
Cancel
Save