示例#1
0
 /**
  *  Generate a file based off of a template
  *
  * @param $fileName
  * @param $template
  * @param string $content
  */
 public function makeFileFromTemplate($fileName, $template, $content = "")
 {
     try {
         $fileContents = \File::get($template);
     } catch (FileNotFoundException $e) {
         $shortTemplate = substr($template, strpos($template, $this->configSettings["pathTo"]["templates"]) + strlen($this->configSettings["pathTo"]["templates"]), strlen($template) - strlen($this->configSettings["pathTo"]["templates"]));
         $this->fileCreator->copyFile("vendor/jrenton/laravel-scaffold/src/Jrenton/LaravelScaffold/templates/" . $shortTemplate, $template);
         $fileContents = \File::get($template);
     }
     $fileContents = $this->replaceNames($fileContents);
     $fileContents = $this->replaceModels($fileContents);
     $fileContents = $this->replaceProperties($fileContents);
     if ($content) {
         $fileContents = str_replace("[content]", $content, $fileContents);
     }
     $namespace = $this->namespace ? "namespace " . $this->namespace . ";" : "";
     $fileContents = str_replace("[namespace]", $namespace, $fileContents);
     if (!$this->configSettings['useRepository']) {
         $fileContents = str_replace($this->nameOf("repositoryInterface"), $this->nameOf("modelName"), $fileContents);
     }
     $this->fileCreator->createFile($fileName, $fileContents);
 }
 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);
         }
     }
 }