1+ <?php
2+
3+ namespace Frosh \Tools \Command ;
4+
5+ use Symfony \Component \Console \Command \Command ;
6+ use Symfony \Component \Console \Input \InputInterface ;
7+ use Symfony \Component \Console \Output \OutputInterface ;
8+ use Symfony \Component \Console \Style \SymfonyStyle ;
9+
10+ class DevEnvCommand extends Command
11+ {
12+ public static $ defaultName = 'frosh:dev:env ' ;
13+ public static $ defaultDescription = 'For testshops - add/change robots.txt to stop crawling ' ;
14+ private string $ envPath ;
15+
16+ public function __construct (string $ envPath )
17+ {
18+ parent ::__construct ();
19+ $ this ->envPath = $ envPath ;
20+ }
21+
22+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
23+ {
24+ $ io = new SymfonyStyle ($ input , $ output );
25+ $ robotsPath = $ this ->envPath ."/robots.txt " ;
26+
27+ $ fileExists = file_exists ($ robotsPath );
28+ if ($ fileExists ) {
29+ $ output ->writeln ('robots.txt exists in public folder ' );
30+
31+ $ file = file_get_contents ($ robotsPath );
32+ $ content = "User-agent: * \nDisallow: / \n\n" .$ file ;
33+ file_put_contents ($ robotsPath , $ content );
34+
35+ $ io ->success ('robots.txt changed :) ' );
36+
37+ return self ::SUCCESS ;
38+ }
39+
40+ $ robotsFile = fopen ($ robotsPath , "w " );
41+ $ robotsContent = "User-agent: * \nDisallow: / " ;
42+ fwrite ($ robotsFile , $ robotsContent );
43+ fclose ($ robotsFile );
44+
45+ $ io ->success ('robots.txt created :) ' );
46+
47+ return self ::SUCCESS ;
48+ }
49+ }
0 commit comments