Skip to content

Commit 31b5a70

Browse files
committed
#75 #in_progress #comment Refactoring de la commande par defaut
1 parent 8cddb04 commit 31b5a70

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/Command/CreateFileDefaultCommand.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Studoo\Command;
44

55
use Studoo\Service\Command\CommandBanner;
6+
use Studoo\Service\Command\QuestionType;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
@@ -12,6 +13,15 @@ class CreateFileDefaultCommand extends CommandManage
1213
{
1314
protected static $defaultName = 'file:default';
1415
protected static $defaultDescription = 'Création du fichier par défaut';
16+
private $fileDefaut = array(
17+
"0" => "Fichier liste des étudiants au format XLSX"
18+
);
19+
private $fileDefautConfig = array(
20+
"0" => [
21+
"file" => "liste-etudiant.xlsx",
22+
"fileRessource" => "/../../ressources/liste-etudiant.xlsx"
23+
]
24+
);
1525

1626

1727
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -21,22 +31,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int
2131
'Command : ' . self::$defaultName
2232
]);
2333

24-
$filesystem = new Filesystem();
25-
if ($filesystem->exists(getcwd() . "/liste-etudiant.xlsx")) {
34+
$choiceFile = new QuestionType($input, $output);
35+
$finalChoiseFile = $choiceFile->Choice("Quel fichier par défaut, voulez vous ?", $this->fileDefaut, 'Merci de choisir un fichier');
36+
$keyFileDefaut = array_search($finalChoiseFile, $this->fileDefaut);
37+
38+
39+
if (array_key_exists($keyFileDefaut, $this->fileDefautConfig)) {
40+
$filesystem = new Filesystem();
41+
if ($filesystem->exists(getcwd() . "/" . $this->fileDefautConfig[$keyFileDefaut]["file"])) {
42+
self::$stdOutput->writeln([
43+
'',
44+
'<error>[X] Le fichier est deja present dans le repertoire</error>',
45+
''
46+
]);
47+
return Command::SUCCESS;
48+
}
49+
50+
$filesystem->copy(__DIR__ . $this->fileDefautConfig[$keyFileDefaut]["fileRessource"], getcwd() . "/" . $this->fileDefautConfig[$keyFileDefaut]["file"]);
2651
self::$stdOutput->writeln([
2752
'',
28-
'<error>[X] Le fichier est deja present dans le repertoire</error>',
53+
'<info>[*] Le fichier est créé ' . $this->fileDefautConfig[$keyFileDefaut]["file"] . '</info>',
2954
''
3055
]);
3156
return Command::SUCCESS;
3257
}
33-
34-
$filesystem->copy(__DIR__ . "/../../ressources/liste-etudiant.xlsx", getcwd() . "/liste-etudiant.xlsx");
35-
self::$stdOutput->writeln([
36-
'',
37-
'<info>[*] Le fichier est créé liste-etudiant.xlsx</info>',
38-
''
39-
]);
40-
return Command::SUCCESS;
58+
return Command::FAILURE;
4159
}
4260
}

0 commit comments

Comments
 (0)