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

Adaptation à symfony Console

parent 0400fb76
No related branches found
No related tags found
No related merge requests found
Pipeline #32236 passed
Showing
with 132 additions and 70 deletions
......@@ -2,10 +2,7 @@
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Laminas\Mvc\Controller\AbstractController
* @var $container \Psr\Container\ContainerInterface
* @var $viewName string
* @var $viewFile string
*/
$cg = \UnicaenCode\Util::codeGenerator();
......
......@@ -2,10 +2,7 @@
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Laminas\Mvc\Controller\AbstractController
* @var $container \Psr\Container\ContainerInterface
* @var $viewName string
* @var $viewFile string
*/
$data = [];
......
......@@ -2,10 +2,7 @@
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Laminas\Mvc\Controller\AbstractController
* @var $container \Psr\Container\ContainerInterface
* @var $viewName string
* @var $viewFile string
*/
$params = \UnicaenCode\Util::codeGenerator()->getGenerator('applicationPhpRenderer');
......
......@@ -2,10 +2,7 @@
/**
* @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('autoloadClassmap');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @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('privileges');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @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('templateMap');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @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('assertion');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @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
......@@ -2,10 +2,7 @@
/**
* @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('controller');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @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('entity');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @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('form');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @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('service');
\ No newline at end of file
......@@ -2,10 +2,7 @@
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Laminas\Mvc\Controller\AbstractController
* @var $container \Psr\Container\ContainerInterface
* @var $viewName string
* @var $viewFile string
*/
if (!\Unicaen\Console\Console::isConsole()){
......
......@@ -2,10 +2,7 @@
/**
* @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('viewHelper');
......
......@@ -2,10 +2,7 @@
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Laminas\Mvc\Controller\AbstractController
* @var $container \Psr\Container\ContainerInterface
* @var $viewName string
* @var $viewFile string
*/
?>
......
......@@ -4,7 +4,8 @@
"require" : {
"laminas/laminas-developer-tools": "^2.8",
"easybook/geshi" : ">=1.0",
"laminas/laminas-file" : "^2.12"
"laminas/laminas-file" : "^2.12",
"symfony/console" : "^6.0|^7.0"
},
"autoload": {
"psr-4": {
......
......@@ -35,6 +35,7 @@ return [
Service\CollectorService::class => Service\Factory\CollectorServiceFactory::class,
Service\IntrospectionService::class => Service\Factory\IntrospectionServiceFactory::class,
Service\CodeGeneratorService::class => Service\Factory\CodeGeneratorServiceFactory::class,
Command\RunCommand::class => Command\RunCommandFactory::class,
],
'invokables' => [
DBAL\Logging\DebugStack::class => DBAL\Logging\DebugStack::class,
......@@ -67,20 +68,9 @@ return [
],
],
'console' => [
'router' => [
'routes' => [
'unicaen-code' => [
'options' => [
'type' => 'catchall',
'route' => 'UnicaenCode <script> [<p0>] [<p1>] [<p2>] [<p3>] [<p4>] [<p5>] [<p6>] [<p7>] [<p8>] [<p9>]',
'defaults' => [
'controller' => 'UnicaenCode\Controller',
'action' => 'console',
],
],
],
],
'laminas-cli' => [
'commands' => [
'unicaen-code:run' => Command\RunCommand::class,
],
],
......
......@@ -83,10 +83,7 @@ variables présentées par le bloc de phpDoc suivant :
``` php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Laminas\Mvc\Controller\AbstractController
* @var $container \Psr\Container\ContainerInterface
* @var $viewName string
* @var $viewFile string
*/
```
......
<?php
namespace UnicaenCode\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use UnicaenCode\Service\Traits\ConfigServiceAwareTrait;
use UnicaenCode\Util;
/**
* Description of RunCommand
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
*/
class RunCommand extends Command
{
use ConfigServiceAwareTrait;
protected function configure(): void
{
$this->setDescription('... description à adapter ...')
->addArgument(
'arguments',
InputArgument::IS_ARRAY,
'Any arguments that you want to pass to this command'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
// Récupération des arguments fournis
$arguments = $input->getArgument('arguments');
$params = [];
$variables = [];
foreach ($arguments as $value) {
if (false !== ($eq = strpos($value, '='))) {
$variables[substr($value, 0, $eq)] = substr($value, $eq + 1);
} else {
$params[] = $value;
}
}
$viewName = $params[0];
$viewFile = $this->getViewFile($viewName);
Util::$currentView = $viewName;
Util::$inputParams = $variables;
if ($viewFile){
$container = Util::getContainer();
extract($variables);
require $viewFile;
}else{
throw new \Exception('Script '.$viewName.' Introuvable');
}
return Command::SUCCESS;
}
private function getViewFile($viewName)
{
$viewDirs = $this->getServiceConfig()->getViewDirs();
$viewFile = null;
foreach( $viewDirs as $viewDir ){
if (file_exists($viewDir.'/'.$viewName.'.php')){
$viewFile = $viewDir.'/'.$viewName.'.php';
break;
}
}
return $viewFile;
}
}
\ No newline at end of file
<?php
namespace UnicaenCode\Command;
use Psr\Container\ContainerInterface;
use UnicaenCode\Service\ConfigService;
use UnicaenCode\Util;
/**
* Description of RunCommandFactory
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
*/
class RunCommandFactory
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return RunCommand
*/
public function __invoke(ContainerInterface $container, $requestedName, $options = null): RunCommand
{
Util::setContainer($container);
$command = new RunCommand;
$command->setServiceConfig($container->get(ConfigService::class));
return $command;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment