/**
  *  Create views as specified in the configuration file
  */
 private function createViews()
 {
     $dir = $this->configSettings['pathTo']['views'] . $this->nameOf('viewFolder') . "/";
     if (!\File::isDirectory($dir)) {
         \File::makeDirectory($dir);
         $this->createDirCache[] = $dir;
     }
     $pathToViews = $this->configSettings['pathTo']['templates'] . $this->controllerType . "/";
     foreach ($this->configSettings['views'] as $view) {
         $fileName = $dir . "{$view}.blade.php";
         $success = false;
         try {
             $this->makeFileFromTemplate($fileName, $pathToViews . "{$view}.blade.php");
             $success = true;
         } catch (FileNotFoundException $e) {
             $this->command->error("Template file " . $pathToViews . $view . ".blade.php does not exist! You need to create it to generate that file!");
         }
         if ($success) {
             $transferMap = $this->configSettings['transfers']['views'];
             if (in_array($view, array_keys($transferMap))) {
                 $this->fileCreator->createDirectory($transferMap[$view]);
                 $ngCtrlscript = $transferMap[$view] . '/' . $this->nameOf('viewFolder') . 'Ctrl.js';
                 $this->fileCreator->copyFile($fileName, $ngCtrlscript);
                 $key = array_search($fileName, $this->createdFilesCache);
                 if ($key !== false && array_key_exists($key, $this->createdFilesCache)) {
                     \File::delete($fileName);
                     $this->createdFilesCache[$key] = $ngCtrlscript;
                 }
             }
         }
     }
 }
 private function downloadCSSFramework()
 {
     if ($this->configSettings['downloads']['bootstrap']) {
         $ch = curl_init("https://github.com/twbs/bootstrap/releases/download/v3.1.1/bootstrap-3.1.1-dist.zip");
         $fp = fopen("public/bootstrap.zip", "w");
         curl_setopt($ch, CURLOPT_FILE, $fp);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_exec($ch);
         curl_close($ch);
         fclose($fp);
         $zip = zip_open("public/bootstrap.zip");
         if ($zip) {
             while ($zip_entry = zip_read($zip)) {
                 $foundationFile = "public/" . zip_entry_name($zip_entry);
                 $foundationDir = dirname($foundationFile);
                 $this->fileCreator->createDirectory($foundationDir);
                 if ($foundationFile[strlen($foundationFile) - 1] == "/") {
                     if (!is_dir($foundationDir)) {
                         \File::makeDirectory($foundationDir);
                     }
                 } else {
                     $fp = fopen($foundationFile, "w");
                     if (zip_entry_open($zip, $zip_entry, "r")) {
                         $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                         fwrite($fp, "{$buf}");
                         zip_entry_close($zip_entry);
                         fclose($fp);
                     }
                 }
             }
             zip_close($zip);
             \File::delete('public/bootstrap.zip');
             $dirPath = 'public/bootstrap-3.1.1-dist';
             $this->fileCreator->copyDirectory($dirPath, 'public/bootstrap');
             foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirPath, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $path) {
                 $path->isFile() ? unlink($path->getPathname()) : rmdir($path->getPathname());
             }
             rmdir($dirPath);
         }
         $fileReplace = "\t<link href=\"{{ url('bootstrap/css/bootstrap.min.css') }}\" rel=\"stylesheet\">\n";
         $fileReplace .= "\t<style>\n";
         $fileReplace .= "\t\tbody {\n";
         $fileReplace .= "\t\tpadding-top: 60px;\n";
         $fileReplace .= "\t\t}\n";
         $fileReplace .= "\t</style>\n";
         $fileReplace .= "\t<link href=\"{{ url('bootstrap/css/bootstrap-theme.min.css') }}\" rel=\"stylesheet\">\n";
         $fileReplace .= "<!--[css]-->\n";
         $this->fileContents = str_replace("<!--[css]-->", $fileReplace, $this->fileContents);
         $this->fileContents = str_replace("<!--[javascript]-->", "<script src=\"{{ url('bootstrap/js/bootstrap.min.js') }}\"></script>\n<!--[javascript]-->", $this->fileContents);
     } else {
         if ($this->configSettings['downloads']['foundation']) {
             $ch = curl_init("http://foundation.zurb.com/cdn/releases/foundation-5.2.2.zip");
             $fp = fopen("public/foundation.zip", "w");
             curl_setopt($ch, CURLOPT_FILE, $fp);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_exec($ch);
             curl_close($ch);
             fclose($fp);
             $zip = zip_open("public/foundation.zip");
             if ($zip) {
                 while ($zip_entry = zip_read($zip)) {
                     $foundationFile = "public/" . zip_entry_name($zip_entry);
                     $foundationDir = dirname($foundationFile);
                     $this->fileCreator->createDirectory($foundationDir);
                     $fp = fopen("public/" . zip_entry_name($zip_entry), "w");
                     if (zip_entry_open($zip, $zip_entry, "r")) {
                         $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                         fwrite($fp, "{$buf}");
                         zip_entry_close($zip_entry);
                         fclose($fp);
                     }
                 }
                 zip_close($zip);
                 \File::delete('public/index.html');
                 \File::delete('public/robots.txt');
                 \File::delete('humans.txt');
                 \File::delete('foundation.zip');
                 \File::deleteDirectory('public/js/foundation');
                 \File::deleteDirectory('public/js/vendor');
                 \File::move('public/js/foundation.min.js', 'public/js/foundation.js');
             }
             $fileReplace = "\t<link href=\"{{ url ('css/foundation.min.css') }}\" rel=\"stylesheet\">\n<!--[css]-->";
             $this->fileContents = str_replace("<!--[css]-->", $fileReplace, $this->fileContents);
             $this->fileContents = str_replace("<!--[javascript]-->", "<script src=\"{{ url ('/js/foundation.js') }}\"></script>\n<!--[javascript]-->", $this->fileContents);
         }
     }
 }