protected static function generateIfRequired() { $fs = new Filesystem(); if (!isset(static::$values) || !isset(static::$records)) { static::$values = json_decode($fs->get(Path::join(__DIR__, 'data/values.json')), true)[0]; static::$records = json_decode($fs->get(Path::join(__DIR__, 'data/records.json')), true); } }
/** * 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; }
/** * @expectedException \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function testGetThrowsExceptionNonexisitingFile() { $files = new Filesystem(); $files->get(__DIR__ . '/unknown-file.txt'); }