Example #1
0
 /**
  * Copy and create new file
  *
  * @param string $item
  * @param string $output
  * @param bool $force
  * @throws \Oven\Exception\InvalidRecipeException
  * @return string
  */
 protected function copySource($item, $output, $source, $force = false)
 {
     $ingredient = $this->reader->getItem("ingredients.{$item}");
     if (is_null($ingredient)) {
         throw new InvalidRecipeException("Missing {$item} ingredient from the recipe");
     }
     $ingredient = new Ingredient($ingredient);
     if (!$ingredient->getIngredient()->offsetExists('source')) {
         throw new InvalidRecipeException("Unable  to locate {$item} ingredient source");
     }
     $filesystem = $this->reader->filesystem();
     $target = $this->destination . '/' . $ingredient->getSourceDir();
     if (!$filesystem->isDirectory($target)) {
         $filesystem->makeDirectory($target, 0755, true);
     }
     if ($ingredient->isEmptyDir()) {
         return $target;
     }
     $filename = $ingredient->getFilename($output);
     if ($filesystem->exists($target . '/' . $filename) and $force == false) {
         return $target . '/' . $filename;
     }
     $sourceFile = $source . '/' . $ingredient->getSourceFile();
     $content = Parser::buildSource($filesystem->get($sourceFile), $output);
     $filesystem->put($target . '/' . $filename, $content);
     return $target . '/' . $filename;
 }
Example #2
0
 /**
  * @param $output
  */
 public function getFilename($output)
 {
     $name = $this->ingredient->get('name');
     return Parser::extract($name, $output);
 }