/**
  * render
  *
  * @param       $string
  * @param array $vars
  * @return string
  */
 public function render($string, array $vars = array())
 {
     $this->files->put($this->tmpFilePath, $this->compiler->compileString($string));
     if (is_array($vars) && !empty($vars)) {
         extract($vars);
     }
     ob_start();
     include $this->tmpFilePath;
     $var = ob_get_contents();
     ob_end_clean();
     $this->files->delete($this->tmpFilePath);
     return $var;
 }
Esempio n. 2
0
 public function testPrependExistingFiles()
 {
     $files = new Filesystem();
     $files->put(__DIR__ . '/file.txt', 'World');
     $files->prepend(__DIR__ . '/file.txt', 'Hello ');
     $this->assertEquals('Hello World', file_get_contents(__DIR__ . '/file.txt'));
     @unlink(__DIR__ . '/file.txt');
 }
Esempio n. 3
0
 /**
  * generate
  *
  * @param string $stubDir
  * @param string $destDir
  * @param array  $files
  * @param array  $vars
  * @return $this
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function generate($stubDir, $destDir, array $files = [], array $vars = [])
 {
     foreach ($files as $stubFile => $destFile) {
         foreach (array_dot($vars) as $key => $val) {
             $destFile = Str::replace($destFile, '{{' . $key . '}}', $val);
         }
         $stubPath = Path::join($stubDir, $stubFile);
         $destPath = Path::join($destDir, $destFile);
         $destDirPath = Path::getDirectory($destPath);
         if (!$this->files->exists($destDirPath)) {
             $this->files->makeDirectory($destDirPath, 0755, true);
         }
         $rendered = $this->render($this->files->get($stubPath), $vars);
         $this->files->put($destPath, $rendered);
     }
     return $this;
 }