| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Rougin\Combustor\Commands; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Rougin\Combustor\Common\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Rougin\Combustor\Common\Tools; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * Create Layout Command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Creates a new header and footer file for CodeIgniter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @package Combustor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @author  Rougin Gutib <[email protected]> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | class CreateLayoutCommand extends AbstractCommand | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * Checks whether the command is enabled or not in the current environment. | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 3 |  |     public function isEnabled() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 | 3 |  |         return ! Tools::hasLayout(); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * Sets the configurations of the specified command. | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 9 |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 9 |  |         $this->setName('create:layout') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 9 |  |             ->setDescription('Creates a new header and footer file') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 9 |  |             ->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 9 |  |                 'bootstrap', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 9 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 9 |  |                 InputOption::VALUE_NONE, | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 | 3 |  |                 'Includes the Bootstrap CSS/JS Framework tags' | 
            
                                                                        
                            
            
                                    
            
            
                | 47 | 6 |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 | 9 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * Executes the command. | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @param \Symfony\Component\Console\Input\InputInterface   $input | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * @param \Symfony\Component\Console\Output\OutputInterface $output | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * @return object|\Symfony\Component\Console\Output\OutputInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 6 |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 6 |  |         $layoutPath = APPPATH . 'views/layout'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 6 |  |         $data = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 6 |  |         $data['bootstrapContainer'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 6 |  |         $data['scripts'] = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 6 |  |         $data['styleSheets'] = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 6 |  |         $css = '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 6 |  |         if (! is_dir('bower_components/font-awesome') && system('bower install font-awesome --save')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 6 |  |             $css = '<?php echo base_url(\'bower_components/font-awesome/css/font-awesome.min.css\'); ?>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 4 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 6 |  |         $data['styleSheets'][0] = $css; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 6 |  |         if ($input->getOption('bootstrap')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 6 |  |             $data['bootstrapContainer'] = 'container'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 6 |  |             $css = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 6 |  |             $js = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.js'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 6 |  |             $jquery = 'https://code.jquery.com/jquery-2.1.1.min.js'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 6 |  |             if (! is_dir('bower_components/bootstrap') && system('bower install bootstrap#3.3.7 --save')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 6 |  |                 $css = '<?php echo base_url(\'bower_components/bootstrap/dist/css/bootstrap.min.css\'); ?>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 6 |  |                 $js = '<?php echo base_url(\'bower_components/bootstrap/dist/js/bootstrap.min.js\'); ?>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 6 |  |                 $jquery = '<?php echo base_url(\'bower_components/jquery/dist/jquery.min.js\'); ?>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 4 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 6 |  |             array_push($data['styleSheets'], $css); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 6 |  |             array_push($data['scripts'], $jquery); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 6 |  |             array_push($data['scripts'], $js); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 4 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 6 |  |         if (! @mkdir($layoutPath, 0777, true)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 3 |  |             $message = 'The layout directory already exists!'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 3 |  |             return $output->writeln('<error>' . $message . '</error>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 6 |  |         $header = $this->renderer->render('Views/Layout/header.tpl', $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 6 |  |         $footer = $this->renderer->render('Views/Layout/footer.tpl', $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 6 |  |         $headerFile = new File($layoutPath . '/header.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 6 |  |         $footerFile = new File($layoutPath . '/footer.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 6 |  |         $headerFile->putContents($header); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 6 |  |         $footerFile->putContents($footer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 6 |  |         $headerFile->close(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 6 |  |         $footerFile->close(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 6 |  |         $message = 'The layout folder has been created successfully!'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 | 6 |  |         return $output->writeln('<info>' . $message . '</info>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  |