Skip to content
Snippets Groups Projects
Commit d463888a authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Nouveau générateur de commandes Synfony console

parent 9d6a61d2
No related branches found
No related tags found
No related merge requests found
Pipeline #30971 failed
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Laminas\Mvc\Controller\AbstractController
* @var $container \Psr\Container\ContainerInterface
* @var $viewName string
* @var $viewFile string
*/
\UnicaenCode\Util::codeGenerator()->generer('command');
\ No newline at end of file
<?php
use UnicaenCode\Util;
return [
'title' => 'Création d\'une nouvelle commande console',
'generator' => function (array $params): array {
$class = $params['class'] ?? null;
$type = $params['type'] ?? Util::classType($class) ?? 'Command';
$author = $params['author'] ?? Util::getAuthor();
$template = $params['template'] ?? 'Command';
$namespace = Util::classNamespace($class);
$classname = Util::classClassname($class);
$filename = Util::classFilename($class);
$params['namespace'] = $namespace;
$params['classname'] = $classname;
$params['author'] = $author;
$params['template'] = $template;
$params['type'] = $type;
$params['filename'] = $filename;
$params['commandConfig'] = true;
return $params;
},
'class' => [
'label' => 'Classe de la commande',
'value' => 'Application\Command\ExempleCommand',
],
'name' => [
'label' => 'Nom pour l\'accès à la commande',
'value' => 'module:exemple',
],
'factory' => [
'type' => 'checkbox',
'label' => 'Générer une factory',
'value' => true,
],
'subDir' => [
'type' => 'checkbox',
'label' => 'La Factory sera placée dans un sous-dossier dédié',
'value' => false,
],
];
\ No newline at end of file
<?php
use UnicaenCode\Util;
return [
'title' => 'Génération de configuration de commande console',
'class' => [
'label' => 'Classe de la console',
'value' => 'Application\Command\ExempleCommand',
],
'name' => [
'label' => 'Nom de la commande',
'value' => 'application:exemple',
],
'factory' => [
'label' => 'Classe de la factory correspondante',
'value' => 'Application\Service\ExempleServiceFactory',
],
'generator' => function (array $params): array {
$class = $params['class'] ?? null;
$template = $params['template'] ?? 'CommandConfig';
$namespace = Util::classModule($class, Util::CLASS_MODULE_NAMESPACE);
$filename = Util::classModule($class, Util::CLASS_MODULE_CONFIG)['relPath'] . '/config/module.config.php';
$category = 'services';
$factoryClass = $params['factory']['class'] ?? $class;
$params = [
'factoinvo' => 'factories',
'namespace' => $namespace,
'name' => $params['name'],
'class' => Util::classTruncated($class, $namespace),
'category' => $category,
'template' => $template,
'filename' => $filename,
'factoryClass' => Util::classTruncated($factoryClass, $namespace),
'write' => false, // ne jamais écrire cette config : tout est à copier/coller
];
return $params;
},
];
\ No newline at end of file
<?php
namespace <namespace>;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Description of <classname>
*
* @author <author>
*/
class <classname> extends SymfonyCommand
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
// ... put here the code to create the user
// this method must return an integer number with the "exit status code"
// of the command. You can also use these constants to make code more readable
// return this if there was no problem running the command
// (it's equivalent to returning int(0))
return SymfonyCommand::SUCCESS;
// or return this if some error happened during the execution
// (it's equivalent to returning int(1))
// return Command::FAILURE;
// or return this to indicate incorrect command usage; e.g. invalid options
// or missing arguments (it's equivalent to returning int(2))
// return Command::INVALID
}
}
\ No newline at end of file
<?php
namespace <namespace>;
return [
'laminas-cli' => [
'commands' => [
'<name>' => <class>::class,
],
],
'<category>' => [
'<factoinvo>' => [
<class>::class => <factoryClass>::class,
],
],
];
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment