コード例 #1
0
 /**
  * @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 '';
 }
コード例 #2
0
 /** @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)'));
 }
コード例 #3
0
ファイル: ModuleManager.php プロジェクト: notadd/framework
 /**
  * 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!');
 }
コード例 #5
0
ファイル: Generator.php プロジェクト: iGloom/ClosureTable
 /**
  * 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);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
 /**
  * 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');
 }
コード例 #8
0
ファイル: TemplateReader.php プロジェクト: dhaval48/foreman
 /**
  * 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);
 }
コード例 #9
0
 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']));
 }
コード例 #10
0
ファイル: LiqPayTableCommand.php プロジェクト: dkulyk/liqpay
 /**
  * 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');
 }
コード例 #11
0
 /**
  * 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();
 }
コード例 #12
0
 /**
  * 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);
 }
コード例 #13
0
ファイル: GeneratorCommand.php プロジェクト: danncsc/DaanX
 /**
  * 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}");
         }
     }
 }
コード例 #14
0
ファイル: Generator.php プロジェクト: gazsp/baum
 /**
  * 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);
 }
コード例 #15
0
 /**
  * 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;
 }
コード例 #16
0
 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()];
     }
 }
コード例 #17
0
 /**
  * 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);
 }
コード例 #18
0
ファイル: Configurator.php プロジェクト: elepunk/oven
 /**
  * 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);
 }
コード例 #19
0
ファイル: ConvertCards.php プロジェクト: NukaCode/Magic
 /**
  * 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]);
 }
コード例 #20
0
 /**
  * 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();
 }
コード例 #21
0
ファイル: EnvFileWriter.php プロジェクト: SocietyCMS/Core
 /**
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function reset()
 {
     Dotenv::makeMutable();
     $templateFile = $this->finder->get($this->template);
     $this->finder->put($this->file, $templateFile);
     Dotenv::makeImmutable();
 }
コード例 #22
0
 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']));
 }
コード例 #23
0
ファイル: EnvWriter.php プロジェクト: ahuggins/utilities
 /**
  * @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);
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 public function read($sessionId)
 {
     if ($this->files->exists($path = $this->path . '/' . $sessionId)) {
         return $this->files->get($path);
     }
     return '';
 }
コード例 #25
0
 /**
  * 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;
 }
コード例 #26
0
 /**
  * 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();
 }
コード例 #27
0
ファイル: PresenterCommand.php プロジェクト: ryannielson/prez
 private function prepareTemplate($template, $data)
 {
     $contents = $this->files->get($template);
     foreach ($data as $key => $value) {
         $contents = preg_replace("/\\\${$key}\\\$/i", $value, $contents);
     }
     return $contents;
 }
コード例 #28
0
 public function createFile(array $data)
 {
     // name
     // description
     // extension
     // file
     $this->storage->put($data['name'] . "." . $data['extension'], $this->filesystem->get($data['file']));
 }
コード例 #29
0
ファイル: Filesystem.php プロジェクト: abcsun/LogViewer
 /**
  * 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.');
     }
 }
コード例 #30
0
ファイル: Compiler.php プロジェクト: guratr/cruddy
 /**
  * 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();
 }