/** * @param $view * @return string * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function getTemplate($view) { if (array_key_exists($view, $this->config['templates']['view']) && ($template = $this->config['templates']['view'][$view])) { return $this->fs->get($template); } return ''; }
/** @test */ public function it_generated_correct_file_with_content() { $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); $file = $this->finder->get($this->modulePath . '/Http/Middleware/SomeMiddleware.php'); $this->assertTrue(str_contains($file, 'class SomeMiddleware')); $this->assertTrue(str_contains($file, 'public function handle(Request $request, Closure $next)')); }
/** * Modules of installed or not installed. * * @param bool $installed * * @return \Illuminate\Support\Collection */ public function getModules($installed = false) { if ($this->modules->isEmpty()) { if ($this->files->isDirectory($this->getModulePath()) && !empty($directories = $this->files->directories($this->getModulePath()))) { (new Collection($directories))->each(function ($directory) use($installed) { if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) { $package = new Collection(json_decode($this->files->get($file), true)); if (Arr::get($package, 'type') == 'notadd-module' && ($name = Arr::get($package, 'name'))) { $module = new Module($name); $module->setAuthor(Arr::get($package, 'authors')); $module->setDescription(Arr::get($package, 'description')); if ($installed) { $module->setInstalled($installed); } if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { $module->setEntry($namespace . 'ModuleServiceProvider'); } } $this->modules->put($directory, $module); } } }); } } return $this->modules; }
/** * @param Request $request * @return mixed * @throws \Exception * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function createMissingController(Request $request) { $namespace = $request->namespace; $controller = $request->controller; $module = $request->module; //Get controllers folder $controllersDir = $this->getMainControllerPath(); //Get controller path for new controller $newControllerDir = $this->getControllerPath($namespace, $module); //Get controller namespace $controllerNamespace = $this->getMainControllerNamespace(); //Get namespace for the new controller $newControllerNamespace = $this->getControllerNamespace($namespace, $module); //Get the file $file = $this->getFileLocation($namespace, $module, $controller); $controllerClass = studly_case($controller . 'Controller'); //Check if file exists $fileExists = $this->fileExists($file); //Check if is dir if (!$this->fs->isDirectory($newControllerDir)) { $this->fs->makeDirectory($newControllerDir, 0755, true, true); } //If file doesnt exist, create the file if (!$fileExists) { $template = $this->builder->setNamespace($newControllerNamespace)->setTemplate($this->fs->get($this->config['templates']['controller']))->setClassName(studly_case($controllerClass))->setUses(Request::class)->buildController(); //Store the file $this->fs->put($file, $template); //Call the created controller return app($newControllerNamespace . '\\' . $controllerClass)->index(); } throw new \Exception('File exists! I don\'t want to override it!'); }
/** * Get a stub file by name. * * @param string $name * @param string $type * @return string */ protected function getStub($name, $type) { if (stripos($name, '.php') === false) { $name = $name . '.php'; } return $this->filesystem->get($this->getStubsPath($type) . '/' . $name); }
public function get($path, array $data = array()) { $filename = $this->files->name($path) . '.' . $this->files->extension($path); $compile_path = \Config::get('view.compiled') . DIRECTORY_SEPARATOR . $filename; $template_last_modified = $this->files->lastModified($path); $cache_last_modified = $this->files->isFile($compile_path) ? $this->files->lastModified($compile_path) : $template_last_modified; $view = $this->files->get($path); $app = app(); // $m = new Mustache_Engine($app['config']->get('handlelars')); // Configuration $cache_disabled = false; $helpers = \Config::get('handlelars.helpers'); // Precompile templates to view cache when necessary $compile = $template_last_modified >= $cache_last_modified || $cache_disabled; if ($compile) { $tpl = LightnCandy::compile($view, compact('helpers')); $this->files->put($compile_path, $tpl); } if (isset($data['__context']) && is_object($data['__context'])) { $data = $data['__context']; } else { $data = array_map(function ($item) { return is_object($item) && method_exists($item, 'toArray') ? $item->toArray() : $item; }, $data); } $renderer = $this->files->getRequire($compile_path); return $renderer($data); }
/** * Retrieve an item and expiry time from the cache by key. * * @param string $key * @return array */ protected function getPayload($key) { $path = $this->path($key); // If the file doesn't exists, we obviously can't return the cache so we will // just return null. Otherwise, we'll get the contents of the file and get // the expiration UNIX timestamps from the start of the file's contents. try { $expire = substr($contents = $this->files->get($path), 0, 10); } catch (Exception $e) { return ['data' => null, 'time' => null]; } // If the current time is greater than expiration timestamps we will delete // the file and return null. This helps clean up the old files and keeps // this directory much cleaner for us as old files aren't hanging out. if (time() >= $expire) { $this->forget($key); return ['data' => null, 'time' => null]; } $data = unserialize(substr($contents, 10)); // Next, we'll extract the number of minutes that are remaining for a cache // so that we can properly retain the time for things like the increment // operation that may be performed on the cache. We'll round this out. $time = ceil(($expire - time()) / 60); return compact('data', 'time'); }
/** * Constructor to set member vars, and read in the * given config file as json, then convert it to an * associative array * * @param string $tpl * @param Filesystem $fs * @param BuildCommand $cmd */ public function __construct($tpl, Filesystem $fs, BuildCommand $cmd) { $this->command = $cmd; $this->filesystem = $fs; $this->command->comment("Foreman", "Reading template from {$tpl}"); $this->config = json_decode($this->filesystem->get($tpl), true); }
public function createFile(array $data) { $project = $this->repository->skipPresenter()->find($data['project_id']); //dd($project); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file'])); }
/** * Execute the console command. * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function fire() { $fullPath = $this->createBaseMigration(); $this->files->put($fullPath, $this->files->get(__DIR__ . '/stubs/database.stub')); $this->info('Migration created successfully!'); $this->call('dump-autoload'); }
/** * Execute the console command. */ public function fire() { $fullPath = $this->createBaseMigration(); $this->files->put($fullPath, $this->files->get(__DIR__ . '/stubs/database.stub')); $this->info('Migration created successfully! Don\'t forget to run "artisan migrate".'); $this->composer->dumpAutoloads(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $model = ucfirst($this->argument('model')); $path = $this->option('path'); if (empty($path)) { $path = database_path(config('smart-seeder.seedDir')); } else { $path = base_path($path); } $env = $this->option('env'); if (!empty($env)) { $path .= "/{$env}"; } if (!$this->files->exists($path)) { // mode 0755 is based on the default mode Laravel use. $this->files->makeDirectory($path, 755, true); } $created = date('Y_m_d_His'); $path .= "/seed_{$created}_{$model}Seeder.php"; $fs = $this->files->get(__DIR__ . '/stubs/DatabaseSeeder.stub'); $namespace = rtrim($this->getAppNamespace(), '\\'); $stub = str_replace('{{seeder}}', "seed_{$created}_" . $model . 'Seeder', $fs); $stub = str_replace('{{namespace}}', " namespace {$namespace};", $stub); $stub = str_replace('{{model}}', $model, $stub); $this->files->put($path, $stub); $message = "Seed created for {$model}"; if (!empty($env)) { $message .= " in environment: {$env}"; } $this->line($message); }
/** * Execute the console command. * * @return void */ public function fire() { if (file_exists($compiled = base_path() . '/bootstrap/compiled.php')) { $this->error('Error generating IDE Helper: first delete bootstrap/compiled.php (php artisan clear-compiled)'); } else { $filename = $this->argument('filename'); $format = $this->option('format'); // Strip the php extension if (substr($filename, -4, 4) == '.php') { $filename = substr($filename, 0, -4); } $filename .= '.' . $format; if ($this->option('memory')) { $this->useMemoryDriver(); } $helpers = ''; if ($this->option('helpers') || $this->config->get('laravel-ide-helper::include_helpers')) { foreach ($this->config->get('laravel-ide-helper::helper_files', array()) as $helper) { if (file_exists($helper)) { $helpers .= str_replace(array('<?php', '?>'), '', $this->files->get($helper)); } } } else { $helpers = ''; } $generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers); $content = $generator->generate($format); $written = $this->files->put($filename, $content); if ($written !== false) { $this->info("A new helper file was written to {$filename}"); } else { $this->error("The helper file could not be created at {$filename}"); } } }
/** * Get the given stub by name. * * @param string $table * * @return void */ protected function getStub($name) { if (stripos($name, '.php.stub') === false) { $name = $name . '.php.stub'; } return $this->files->get($this->getStubPath() . '/' . $name); }
/** * Execute the console command. * * @return mixed */ public function handle() { if (!$this->files->put(app_path() . '/Http/Controllers/Controller.php', $this->files->get(__DIR__ . '/stubs/Controller.stub'))) { $this->error('Could not update the Controller abstract class'); } else { $this->info('Abstract Controller class been successfully updated'); } if ($this->makeMotorsDirectory()) { Artisan::call('make:httplayer:basemotor', array()); $this->info(Artisan::output()); $this->info('app\\Http\\Motors :'); $this->info('Motors Directory has been successfully created! '); } else { $this->error('WHhhooppss! There was a problem! please verify your permissions'); return false; } if ($this->makeTraitsDirectory()) { if (!$this->files->put(app_path() . '/Http/Traits/CRUDTrait.php', $this->files->get(__DIR__ . '/stubs/CRUDtrait.stub'))) { $this->error('Could not update the Controller abstract class'); } else { $this->info('Abstract Controller class been successfully updated'); } $this->info('app\\Http\\Traits :'); $this->info('Motors Directory has been successfully created! '); } else { $this->error('WHhhooppss! There was a problem! please verify your permissions'); return false; } return true; }
public function update($projectId, $fileId, $file, array $data) { try { if (is_null($file)) { $this->validator->setRules(['name' => 'required|max:255', 'description' => 'required']); $this->validator->with($data)->passesOrFail(); $fileUpdate = $this->repository->findWhere(['project_id' => $projectId, 'id' => $fileId])->first(); $fileUpdate->update($data, $fileId); return $this->find($projectId, $fileUpdate->id); } $this->validator->with($data)->passesOrFail(); $fileUpdate = $this->repository->findWhere(['project_id' => $projectId, 'id' => $fileId])->first(); $data['extension'] = $file->getClientOriginalExtension(); $data['file'] = md5(date('Y-m-d H:i:s')) . "." . $data['extension']; $this->storage->put($data['file'], $this->filesystem->get($file)); if ($this->storage->exists($fileUpdate->file)) { $this->storage->delete($fileUpdate->file); } $fileUpdate->update($data, $fileId); return $this->find($projectId, $fileUpdate->id); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } catch (\Exception $e) { return ['error' => true, 'message' => $e->getMessage()]; } }
/** * Grabs a json file and returns a array * * @param string $path The path to the json file * @return array The parsed array */ public function jsonFileToArray($path) { // Get file contents $contents = $this->filesystem->get($path); // Return array return json_decode($contents, true); }
/** * Get recipe files location * * @return string */ public function getRecipePath() { $directory = $this->getDirectoryPath(); $content = $this->filesystem->get($directory . '/' . self::CONFIGFILE); $contentArr = json_decode($content, true); return Arr::get($contentArr, 'recipe_path', null); }
/** * Execute the console command. * * @return mixed */ public function handle() { $series = $this->argument('series'); $data = json_decode($this->filesystem->get(base_path('resources/assets/json/' . $series . '_full.json'))); $series = $this->series->create((array) $data); $this->db->table('cards')->whereNull('series_id')->update(['series_id' => $series->id]); }
/** * Execute the console command. * * @return void */ public function fire() { $fullPath = $this->createBaseMigration(); $this->files->put($fullPath, $this->files->get(__DIR__ . '/stubs/notifications.stub')); $this->info('Migration created successfully!'); $this->composer->dumpAutoloads(); }
/** * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function reset() { Dotenv::makeMutable(); $templateFile = $this->finder->get($this->template); $this->finder->put($this->file, $templateFile); Dotenv::makeImmutable(); }
public function createFile(array $data) { // name, description, extension, file $project = $this->repository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($data['name'] . "." . $data['extension'], $this->fileSystem->get($data['file'])); }
/** * @param $name * @param $username * @param $password * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function write($name, $username, $password, $host) { $environmentFile = $this->finder->get($this->file); $replace = ["DB_HOST={$host}", "DB_PORT=3306", "DB_DATABASE={$name}", "DB_USERNAME={$username}", "DB_PASSWORD={$password}"]; $newEnvironmentFile = str_replace($this->search, $replace, $environmentFile); $this->finder->put($this->file, $newEnvironmentFile); }
/** * {@inheritdoc} */ public function read($sessionId) { if ($this->files->exists($path = $this->path . '/' . $sessionId)) { return $this->files->get($path); } return ''; }
/** * Compile the template. * * @param $templatePath * @param $templateData * @param $filePath * * @return string */ public function compile($templatePath, array $templateData, $filePath) { $template = $this->filesystem->get($templatePath); $compiled = $this->compiler->compile($template, $templateData); $this->makeDirectory(dirname($filePath)); $this->filesystem->put($filePath, $compiled); return $filePath; }
/** * Execute the console command. * * @return void */ public function fire() { $fullPath = $this->createBaseMigration(); $stubPath = __DIR__ . '/../../stubs/auth.stub'; $this->files->put($fullPath, $this->files->get($stubPath)); $this->info('Migration created successfully!'); $this->composer->dumpAutoloads(); }
private function prepareTemplate($template, $data) { $contents = $this->files->get($template); foreach ($data as $key => $value) { $contents = preg_replace("/\\\${$key}\\\$/i", $value, $contents); } return $contents; }
public function createFile(array $data) { // name // description // extension // file $this->storage->put($data['name'] . "." . $data['extension'], $this->filesystem->get($data['file'])); }
/** * Read the log. * * @param string $date * * @throws \GrahamCampbell\LogViewer\Log\FilesystemException * * @return string */ public function read($date) { try { return $this->files->get($this->path($date)); } catch (FileNotFoundException $e) { throw new FilesystemException('There was an reading the log.'); } }
/** * Compile a schema. * * @return array */ public function schema() { $filename = $this->filename(); if ($this->file->exists($filename)) { return unserialize($this->file->get($filename)); } return $this->fresh(); }