backports murph-skeleton
This commit is contained in:
parent
e670714f0e
commit
d38663da4f
|
@ -31,27 +31,27 @@ class MakeCrudController extends AbstractMaker
|
||||||
->addArgument(
|
->addArgument(
|
||||||
'controller-class',
|
'controller-class',
|
||||||
InputArgument::OPTIONAL,
|
InputArgument::OPTIONAL,
|
||||||
'Choose a name for your CRUD controller class (e.g. <fg=yellow>FooAdminController</>)'
|
'Choose a name for your CRUD controller class (e.g. <fg=yellow>MyEntityAdminController</>)'
|
||||||
)
|
)
|
||||||
->addArgument(
|
->addArgument(
|
||||||
'entity-class',
|
'entity-class',
|
||||||
InputArgument::OPTIONAL,
|
InputArgument::OPTIONAL,
|
||||||
'Define the entity (e.g. <fg=yellow>App\Entity\Foo</>)'
|
'Define the entity (e.g. <fg=yellow>MyEntity</>)'
|
||||||
)
|
)
|
||||||
->addArgument(
|
->addArgument(
|
||||||
'repository-query-class',
|
'repository-query-class',
|
||||||
InputArgument::OPTIONAL,
|
InputArgument::OPTIONAL,
|
||||||
'Define the repository query (e.g. <fg=yellow>App\Repository\FooRepositoryQuery</>)'
|
'Define the repository query (e.g. <fg=yellow>MyEntityRepositoryQuery</>)'
|
||||||
)
|
)
|
||||||
->addArgument(
|
->addArgument(
|
||||||
'factory-class',
|
'factory-class',
|
||||||
InputArgument::OPTIONAL,
|
InputArgument::OPTIONAL,
|
||||||
'Define the factory (e.g. <fg=yellow>App\Factory\FooFactory</>)'
|
'Define the factory (e.g. <fg=yellow>MyEntityFactory</>)'
|
||||||
)
|
)
|
||||||
->addArgument(
|
->addArgument(
|
||||||
'form-class',
|
'form-class',
|
||||||
InputArgument::OPTIONAL,
|
InputArgument::OPTIONAL,
|
||||||
'Define the form (e.g. <fg=yellow>App\Form\FooType</>)'
|
'Define the form (e.g. <fg=yellow>MyEntityType</>)'
|
||||||
)
|
)
|
||||||
->setHelp('')
|
->setHelp('')
|
||||||
;
|
;
|
||||||
|
@ -65,21 +65,41 @@ class MakeCrudController extends AbstractMaker
|
||||||
'Controller'
|
'Controller'
|
||||||
);
|
);
|
||||||
|
|
||||||
$entity = u($input->getArgument('entity-class'));
|
$entityDetails = $generator->createClassNameDetails(
|
||||||
$lastBackSlashIndex = $entity->indexOfLast('\\');
|
$input->getArgument('entity-class'),
|
||||||
$route = u($entity->slice($lastBackSlashIndex))->snake();
|
'Entity\\',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
$repoDetails = $generator->createClassNameDetails(
|
||||||
|
$input->getArgument('repository-query-class'),
|
||||||
|
'Repository\\',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
$formDetails = $generator->createClassNameDetails(
|
||||||
|
$input->getArgument('form-class'),
|
||||||
|
'Type\\',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
$factoryDetails = $generator->createClassNameDetails(
|
||||||
|
$input->getArgument('factory-class'),
|
||||||
|
'Factory\\',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'entity' => (string) $entity,
|
'entity' => $entityDetails->getFullName(),
|
||||||
'route' => (string) $route,
|
'route' => (string) u($entityDetails->getShortName())->snake(),
|
||||||
'repository_query' => $input->getArgument('repository-query-class'),
|
'repository_query' => $repoDetails->getFullName(),
|
||||||
'form' => $input->getArgument('form-class'),
|
'form' => $formDetails->getFullName(),
|
||||||
'factory' => $input->getArgument('factory-class'),
|
'factory' => $factoryDetails->getFullName(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$controllerPath = $generator->generateController(
|
$controllerPath = $generator->generateController(
|
||||||
$controllerClassNameDetails->getFullName(),
|
$controllerClassNameDetails->getFullName(),
|
||||||
__DIR__.'/../Resources/maker/crud-controller/CrudController.tpl.php',
|
__DIR__.'/../Resources/maker/controller/CrudController.tpl.php',
|
||||||
$options
|
$options
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
82
core/Maker/MakeFactory.php
Normal file
82
core/Maker/MakeFactory.php
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\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 MakeFactory 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(
|
||||||
|
'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\\',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
$factoryDetails = $generator->createClassNameDetails(
|
||||||
|
$input->getArgument('factory-class'),
|
||||||
|
'Factory\\',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'entity' => $entityDetails->getFullName(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$factoryPath = $generator->generateController(
|
||||||
|
$factoryDetails->getFullName(),
|
||||||
|
__DIR__.'/../Resources/maker/factory/Factory.tpl.php',
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
|
||||||
|
$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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
85
core/Maker/MakeRepositoryQuery.php
Normal file
85
core/Maker/MakeRepositoryQuery.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\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 MakeRepositoryQuery extends AbstractMaker
|
||||||
|
{
|
||||||
|
public static function getCommandName(): string
|
||||||
|
{
|
||||||
|
return 'make:repository-query';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCommandDescription(): string
|
||||||
|
{
|
||||||
|
return 'Creates a repository query';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureCommand(Command $command, InputConfiguration $inputConf)
|
||||||
|
{
|
||||||
|
$command
|
||||||
|
->addArgument(
|
||||||
|
'repository-class',
|
||||||
|
InputArgument::OPTIONAL,
|
||||||
|
'Define the repository (e.g. <fg=yellow>MyEntityRepository</>)'
|
||||||
|
)
|
||||||
|
->setHelp('')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
|
||||||
|
{
|
||||||
|
$repositoryClass = $input->getArgument('repository-class');
|
||||||
|
|
||||||
|
$repositoryDetails = $generator->createClassNameDetails(
|
||||||
|
$repositoryClass,
|
||||||
|
'Repository\\',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
$queryDetails = $generator->createClassNameDetails(
|
||||||
|
$repositoryClass,
|
||||||
|
'Repository\\',
|
||||||
|
'Query'
|
||||||
|
);
|
||||||
|
|
||||||
|
$id = u($queryDetails->getShortName())
|
||||||
|
->truncate(1)
|
||||||
|
->lower()
|
||||||
|
;
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'repository' => $repositoryDetails->getFullName(),
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$factoryPath = $generator->generateController(
|
||||||
|
$queryDetails->getFullName(),
|
||||||
|
__DIR__.'/../Resources/maker/repository/RepositoryQuery.tpl.php',
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
|
||||||
|
$generator->writeChanges();
|
||||||
|
|
||||||
|
$this->writeSuccessMessage($io);
|
||||||
|
$io->text('Next: Open your new repository query class and configure it!');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureDependencies(DependencyBuilder $dependencies)
|
||||||
|
{
|
||||||
|
$dependencies->addClassDependency(
|
||||||
|
Annotation::class,
|
||||||
|
'doctrine/annotations'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
14
core/Resources/maker/factory/Factory.tpl.php
Normal file
14
core/Resources/maker/factory/Factory.tpl.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?= "<?php\n" ?>
|
||||||
|
|
||||||
|
namespace <?= $namespace; ?>;
|
||||||
|
|
||||||
|
use App\Core\Factory\FactoryInterface;
|
||||||
|
use <?= $entity ?> as Entity;
|
||||||
|
|
||||||
|
class <?= $class_name; ?> implements FactoryInterface
|
||||||
|
{
|
||||||
|
public function create(): Entity
|
||||||
|
{
|
||||||
|
return new Entity();
|
||||||
|
}
|
||||||
|
}
|
15
core/Resources/maker/repository/RepositoryQuery.tpl.php
Normal file
15
core/Resources/maker/repository/RepositoryQuery.tpl.php
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?= "<?php\n" ?>
|
||||||
|
|
||||||
|
namespace <?= $namespace; ?>;
|
||||||
|
|
||||||
|
use App\Core\Repository\RepositoryQuery;
|
||||||
|
use Knp\Component\Pager\PaginatorInterface;
|
||||||
|
use <?= $repository; ?> as Repository;
|
||||||
|
|
||||||
|
class <?= $class_name; ?> extends RepositoryQuery
|
||||||
|
{
|
||||||
|
public function __construct(Repository $repository, PaginatorInterface $paginator)
|
||||||
|
{
|
||||||
|
parent::__construct($repository, '<?= $id; ?>', $paginator);
|
||||||
|
}
|
||||||
|
}
|
|
@ -236,8 +236,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% if loop.last %}
|
||||||
{% if loop.last and (isSortable or configuration.hasBatchAction(context)) %}
|
|
||||||
{% block list_footer %}
|
{% block list_footer %}
|
||||||
{% set count = configuration.fields(context)|length + 1 %}
|
{% set count = configuration.fields(context)|length + 1 %}
|
||||||
{% if configuration.hasBatchAction(context) %}
|
{% if configuration.hasBatchAction(context) %}
|
||||||
|
@ -246,15 +245,17 @@
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="col-12 text-black-50 border-0" colspan="{{ count }}">
|
<td class="col-12 text-black-50 border-0" colspan="{{ count }}">
|
||||||
|
{% block list_footer_before %}{% endblock %}
|
||||||
|
|
||||||
{% if isSortable %}
|
{% if isSortable %}
|
||||||
<div class="d-block mb-2">
|
<div class="mb-2">
|
||||||
<span class="fa fa-hand-pointer"></span>
|
<span class="fa fa-hand-pointer"></span>
|
||||||
{{ 'You can sort items with drag & drop'|trans }}
|
{{ 'You can sort items with drag & drop'|trans }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if configuration.hasBatchAction(context) %}
|
{% if configuration.hasBatchAction(context) %}
|
||||||
<div class="d-block">
|
<div class="mb-2">
|
||||||
<form class="form-inline" action="{{ path(configuration.pageRoute('batch'), {page: pager.currentPageNumber}) }}" id="form-batch" method="POST">
|
<form class="form-inline" action="{{ path(configuration.pageRoute('batch'), {page: pager.currentPageNumber}) }}" id="form-batch" method="POST">
|
||||||
<select class="form-control my-1 mr-sm-2" name="batch[target]">
|
<select class="form-control my-1 mr-sm-2" name="batch[target]">
|
||||||
<option value="selection">{{ 'For selection'|trans }}</option>
|
<option value="selection">{{ 'For selection'|trans }}</option>
|
||||||
|
@ -277,6 +278,8 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% block list_footer_after %}{% endblock %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue