3
3
namespace Studoo \Command ;
4
4
5
5
use Studoo \Service \Command \CommandBanner ;
6
+ use Studoo \Service \Command \QuestionType ;
6
7
use Symfony \Component \Console \Command \Command ;
7
8
use Symfony \Component \Console \Input \InputInterface ;
8
9
use Symfony \Component \Console \Output \OutputInterface ;
@@ -12,6 +13,15 @@ class CreateFileDefaultCommand extends CommandManage
12
13
{
13
14
protected static $ defaultName = 'file:default ' ;
14
15
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
+ );
15
25
16
26
17
27
protected function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -21,22 +31,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int
21
31
'Command : ' . self ::$ defaultName
22
32
]);
23
33
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 " ]);
26
51
self ::$ stdOutput ->writeln ([
27
52
'' ,
28
- '<error>[X ] Le fichier est deja present dans le repertoire</error > ' ,
53
+ '<info>[* ] Le fichier est créé ' . $ this -> fileDefautConfig [ $ keyFileDefaut ][ " file " ] . ' </info > ' ,
29
54
''
30
55
]);
31
56
return Command::SUCCESS ;
32
57
}
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 ;
41
59
}
42
60
}
0 commit comments