Example #1
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();
 }
Example #2
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);
 }
Example #3
0
 public function setUp()
 {
     $this->loader = new FileLoader($this->files = new Filesystem());
     $this->group = md5(time() . uniqid());
     $this->namespace = md5(time() . uniqid());
     $this->environment = md5(time() . uniqid());
     $path = DIR_APPLICATION . '/config/';
     $this->loader->addNamespace($this->namespace, $path . $this->namespace);
     $paths = array("generated_overrides/{$this->group}.php" => array('non-namespaced' => true, 'override' => true, 'second' => false), "{$this->group}.php" => array('non-namespaced' => true, 'main_group' => true, 'second' => true, 'last' => false), "{$this->environment}.{$this->group}.php" => array('non-namespaced' => true, 'environment' => true, 'last' => true), "generated_overrides/{$this->namespace}/{$this->group}.php" => array('namespaced' => true, 'override' => true, 'second' => false), "{$this->namespace}/{$this->group}.php" => array('namespaced' => true, 'main_group' => true, 'second' => true, 'last' => false), "{$this->namespace}/{$this->environment}.{$this->group}.php" => array('namespaced' => true, 'environment' => true, 'last' => true));
     foreach ($paths as $relative_path => $array) {
         $split = explode('/', $relative_path);
         $current_path = $path;
         array_pop($split);
         foreach ($split as $directory) {
             $dir = "{$current_path}/{$directory}";
             if (!$this->files->exists($dir)) {
                 $this->files->makeDirectory($dir);
                 $this->to_remove[] = $dir;
             }
             $current_path = $dir;
         }
         $this->to_remove[] = $path . $relative_path;
         $this->files->put($path . $relative_path, id(new Renderer($array))->render());
     }
 }
Example #4
0
 /**
  * @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);
 }
 /**
  * @param $path
  * @param array $data
  */
 public function generate($path, array $data)
 {
     $this->setupDirectory($path);
     $html = $this->renderReport(['analyzedPath' => $data['path'], 'analysis' => $data['result']]);
     // Write report html to the file
     $this->filesystem->put($path . '/index.html', $html);
 }
Example #6
0
 /**
  * write log
  * @param  string $logContent [logContent]
  * @param  string $logDirPath [filepath]
  */
 public function logInfo($logContent, $logDirPath)
 {
     $filesystem = new Filesystem();
     if (!$logContent || !$logDirPath) {
         return false;
     }
     if ($this->getMailLog()) {
         // log file all path
         $logPath = $logDirPath . $this->getLogName();
         if ($filesystem->exists($logPath)) {
             // everyDay new a file
             $content = $filesystem->get($logPath);
             if ($logTime = substr($content, 1, 10)) {
                 if (Carbon::now($this->local)->toDateString() == $logTime) {
                     $filesystem->append($logPath, $logContent . PHP_EOL);
                 } else {
                     $new_log_path = $logDirPath . $logTime . $this->getLogName();
                     if (!$filesystem->exists($new_log_path)) {
                         $filesystem->move($logPath, $new_log_path);
                     }
                     $filesystem->put($logPath, $logContent);
                 }
             }
         } else {
             $filesystem->put($logPath, $logContent);
         }
     }
 }
Example #7
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);
 }
Example #8
0
 /**
  * Create a new migration at the given path.
  *
  * @param  string $name
  * @param  string $path
  * @param $migrations
  * @return string
  */
 public function create($name, $path, $migrations)
 {
     $path = $this->getPath($name, $path);
     $ups = [];
     $downs = [];
     if (isset($migrations['create'])) {
         foreach ($migrations['create'] as $table => $data) {
             $ups[] = $this->populateStub('create', ['table' => $table, 'columns' => $this->format($data['cols'])]);
             $downs[] = $this->populateStub('drop', ['table' => $table]);
         }
     }
     if (isset($migrations['update'])) {
         foreach ($migrations['update'] as $table => $data) {
             $ups[] = $this->populateStub('update', ['table' => $table, 'columns' => isset($data['cols']) ? $this->format($data['cols']) : null, 'foreign_keys' => isset($data['fks']) ? $this->format($data['fks']) : null]);
             $downs[] = $this->populateStub('down', ['table' => $table, 'columns' => isset($data['cols']) ? $this->format($this->drop(array_keys($data['cols']), 'Column')) : null, 'foreign_keys' => isset($data['fks']) ? $this->format($this->drop(array_keys($data['fks']), 'Foreign')) : null]);
         }
     }
     $ups = array_filter($ups, 'strlen');
     $downs = array_filter($downs, 'strlen');
     if ($ups) {
         $this->files->put($path, $this->populateStub('blank', ['class' => studly_case($name), 'up' => $this->format($ups, ''), 'down' => $this->format(array_reverse($downs), '')]));
         return $path;
     }
     return false;
 }
 /**
  * Generate a fully fleshed out controller, if the user wishes.
  */
 public function makeViews()
 {
     $valid = false;
     $indexPath = $this->getPath($this->getClassName(), 'index');
     $this->makeDirectory($indexPath);
     $createPath = $this->getPath($this->getClassName(), 'create');
     $this->makeDirectory($createPath);
     $editPath = $this->getPath($this->getClassName(), 'edit');
     $this->makeDirectory($editPath);
     if (!$this->files->exists($indexPath)) {
         if ($this->files->put($indexPath, $this->compileViewStub('index'))) {
             $valid = true;
         }
     }
     if (!$this->files->exists($createPath)) {
         if ($this->files->put($createPath, $this->compileViewStub('create'))) {
             $valid = true;
         }
     }
     if (!$this->files->exists($editPath)) {
         if ($this->files->put($editPath, $this->compileViewStub('edit'))) {
             $valid = true;
         }
     }
     $masterPath = base_path() . '/resources/views/master.blade.php';
     $stub = $this->files->get(__DIR__ . '/../stubs/views/master.stub');
     if (!$this->files->exists($masterPath)) {
         if ($this->files->put($masterPath, $this->compileViewStub('master'))) {
             $valid = true;
         }
     }
     return $valid;
 }
Example #10
0
 /**
  * Create a new migration at the given path.
  *
  * @param  string  $class
  * @param  string  $table
  * @param  bool    $create
  * @return string
  */
 public function create($class, $table = null, $create = false)
 {
     $stub = $this->getStub($table, $create);
     $this->files->put($this->getPath($class), $this->populateStub($class, $stub, $table));
     $this->firePostCreateHooks();
     return $class;
 }
 /**
  * @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!');
 }
 /**
  * @param $form
  * @param bool $file_name
  * @param array $date_range
  * @return string
  */
 public function exportToFile($form, $file_name = false, $date_range = [], $update_download_id = false)
 {
     $this->initialiseExport($form, $file_name, $date_range);
     $this->buildCsv($update_download_id);
     $this->filesystem->put($this->generateFileName(), $this->csv->__toString());
     return $this->generateFileName();
 }
 public function save($item, $value, $environment, $group, $namespace = null)
 {
     $path = DIR_APPLICATION . '/config/generated_overrides';
     if (!$this->files->exists($path)) {
         $this->files->makeDirectory($path, 0777);
     } elseif (!$this->files->isDirectory($path)) {
         $this->files->delete($path);
         $this->files->makeDirectory($path, 0777);
     }
     if ($namespace) {
         $path = "{$path}/{$namespace}";
         if (!$this->files->exists($path)) {
             $this->files->makeDirectory($path, 0777);
         } elseif (!$this->files->isDirectory($path)) {
             $this->files->delete($path);
             $this->files->makeDirectory($path, 0777);
         }
     }
     $file = "{$path}/{$group}.php";
     $current = array();
     if ($this->files->exists($file)) {
         $current = $this->files->getRequire($file);
     }
     array_set($current, $item, $value);
     $renderer = new Renderer($current);
     return $this->files->put($file, $renderer->render()) !== false;
 }
Example #14
0
 /**
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function reset()
 {
     Dotenv::makeMutable();
     $templateFile = $this->finder->get($this->template);
     $this->finder->put($this->file, $templateFile);
     Dotenv::makeImmutable();
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $fullPath = $this->createBaseMigration();
     $this->files->put($fullPath, $this->getMigrationStub());
     $this->info('Migration created successfully!');
     $this->call('dump-autoload');
 }
Example #16
0
 /**
  * Generate new model if not exists.
  *
  * @return mixed
  */
 protected function generate()
 {
     if ($this->files->put($this->getNewModel(), $this->getStubContent())) {
         return $this->console->info("Model [{$this->modelName}] created successfully.");
     }
     return $this->console->error("Model [{$this->modelName}] already exists.");
 }
Example #17
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;
 }
 /**
  * Enregistrement d'un vote
  *
  * @param string $nom
  * @param array $inputs 
  * @return bool
  */
 public function save($nom, $imputs)
 {
     // On récupère le chemin dans la configuration et on ajoute le nom du fichier
     $path = config('sondage.files.path') . $nom;
     // Si le fichier n'existe pas on le crée et l'initialise
     if (!$this->files->exists($path)) {
         // On récupère les questions
         $questions = config('sondage.' . $nom . '.reponses');
         // On crée un fichier avec le bon nombre de valeurs à 0
         $this->files->put($path, implode(',', array_fill(0, count($questions), 0)));
         // On crée aussi le fichier des Emails
         $this->files->put($path . '_emails', '');
     }
     // On récupère les Emails déjà utilisés
     $emails = $this->files->get($path . '_emails');
     // Si l'Email a déjà été utilisé on renvoie une erreur
     if (strpos($emails, $imputs['email']) !== false) {
         return false;
     }
     // On mémorise l'Email
     $this->files->append($path . '_emails', $imputs['email'] . "\n");
     // Valeurs actuelles des scores
     $score = explode(',', $this->files->get($path));
     // Incrémentation de la valeur de l'option choisie
     ++$score[$imputs['options']];
     // On enregistre les nouvelles valeurs dans le fichier
     $this->files->put($path, implode(',', $score));
     return true;
 }
Example #19
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->call('config:clear');
     $config = $this->getFreshConfiguration();
     $this->files->put($this->laravel->getCachedConfigPath(), '<?php return ' . var_export($config, true) . ';' . PHP_EOL);
     $this->info('Configuration cached successfully!');
 }
Example #20
0
 /**
  * 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');
         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();
         $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}");
         }
     }
 }
Example #21
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $contents = $this->getKeyFile();
     $dbName = $this->argument('database');
     $dbUserName = $this->ask('What is your MySQL username?');
     $dbPassword = $this->secret('What is your MySQL password?');
     // Replace DB credentials taken from env.php file
     $keys = ['MYSQL_DATABASE', 'MYSQL_USERNAME', 'MYSQL_PASSWORD'];
     $search = ["'{$keys['0']}' => ''", "'{$keys['1']}' => ''", "'{$keys['2']}' => ''"];
     $replace = ["'{$keys['0']}' => '{$dbName}'", "'{$keys['1']}' => '{$dbUserName}'", "'{$keys['2']}' => '{$dbPassword}'"];
     $contents = str_replace($search, $replace, $contents, $count);
     if ($count != 3) {
         throw new Exception('Error while writing credentials to .env.php.');
     }
     // Set DB credentials to laravel config
     $this->laravel['config']['database.connections.mysql.database'] = $dbName;
     $this->laravel['config']['database.connections.mysql.username'] = $dbUserName;
     $this->laravel['config']['database.connections.mysql.password'] = $dbPassword;
     $this->error($this->laravel['config']['local.database.connections.mysql.database']);
     // Migrate DB
     if (!Schema::hasTable('migrations')) {
         $this->call('migrate');
         $this->call('db:seed');
     } else {
         $this->error('A migrations table was found in database [' . $dbName . '], no migrate and seed were done.');
     }
     // Write to .env.php
     $env = $this->laravel->environment();
     $newPath = $env == 'production' ? '.env.php' : '.env.' . $env . '.php';
     $this->files->put($newPath, $contents);
 }
Example #22
0
 /**
  * Create a new model at the given path with given data.
  *
  * @param string $path
  * @param array $data
  * @return string
  */
 public function create($path, $data)
 {
     $this->makeDirectory($path);
     $stub = $this->getStub();
     $this->files->put($path, $this->populateStub($data, $stub));
     return $path;
 }
Example #23
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $contents = $this->getKeyFile();
     $dbName = $this->argument('database');
     $dbUserName = $this->ask('What is your MySQL username?');
     $dbPassword = $this->secret('What is your MySQL password?');
     // Replace DB credentials taken from .env.example file
     $keys = ['DB_NAME', 'DB_USERNAME', 'DB_PASSWORD'];
     $search = ["{$keys['0']}=typicms", "{$keys['1']}=homestead", "{$keys['2']}=homestead"];
     $replace = ["{$keys['0']}={$dbName}", "{$keys['1']}={$dbUserName}", "{$keys['2']}={$dbPassword}"];
     $contents = str_replace($search, $replace, $contents, $count);
     if ($count != 3) {
         throw new Exception('Error while writing credentials to .env.');
     }
     // Set DB credentials to laravel config
     $this->laravel['config']['database.connections.mysql.database'] = $dbName;
     $this->laravel['config']['database.connections.mysql.username'] = $dbUserName;
     $this->laravel['config']['database.connections.mysql.password'] = $dbPassword;
     $this->error($this->laravel['config']['local.database.connections.mysql.database']);
     // Migrate DB
     if (!Schema::hasTable('migrations')) {
         $this->call('migrate');
         $this->call('db:seed');
     } else {
         $this->error('A migrations table was found in database [' . $dbName . '], no migrate and seed were done.');
     }
     // Write to .env
     $this->files->put('.env', $contents);
 }
Example #24
0
 /**
  * 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.
  *
  * @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();
 }
 /**
  * Execute the console command.
  *
  * @return bool|null
  */
 public function fire()
 {
     $moduleName = $this->parseName($this->getModuleNameInput());
     $name = $this->parseName($this->getNameInput());
     $path = $this->getPath($moduleName, $name);
     if ($this->alreadyExists($this->getModuleNameInput(), $this->getNameInput())) {
         $this->error($this->type . ' already exists!');
         return false;
     }
     $this->makeDirectory($path);
     switch ($this->type) {
         case "Controller":
             $replaceName = $moduleName . "\\Controllers\\" . $name;
             break;
         case "Model":
             $replaceName = $moduleName . "\\Models\\" . $name;
             break;
         case "Request":
             $replaceName = $moduleName . "\\Requests\\" . $name;
             break;
         case "Policy":
             $replaceName = $moduleName . "\\Policies\\" . $name;
             break;
         default:
             $replaceName = $moduleName . $name;
             break;
     }
     $this->files->put($path, $this->buildClass($replaceName));
     $this->info($this->type . ' created successfully.');
 }
 /**
  * Parse some content.
  *
  * @param $content
  * @return string
  */
 public function parse($content)
 {
     if (!$this->files->isDirectory($path = storage_path('framework/views/asset'))) {
         $this->files->makeDirectory($path);
     }
     $this->files->put(storage_path('framework/views/asset/' . (($filename = md5($content)) . '.twig')), $content);
     return $this->views->make('root::storage/framework/views/asset/' . $filename)->render();
 }
Example #28
0
 /**
  * Create a mapping file.
  *
  * @param $model
  * @param $path
  *
  * @return string
  */
 public function create($model, $path)
 {
     $path = $this->getPath($model, $path);
     $stub = $this->getStub();
     $this->files->put($path, $this->populateStub($model, $stub));
     $this->firePostCreateHooks();
     return $path;
 }
 public function generate()
 {
     $files = $this->documentation->getAllFiles();
     $view = $this->viewFactory->make('documentation::route_templates.routes', compact('files'));
     $filePath = storage_path() . "/routes/documentation_routes.php";
     $fileContents = "<?php\n\n" . $view->render();
     $this->finder->put($filePath, $fileContents);
 }
 public function setUp()
 {
     parent::setUp();
     $this->modulePath = base_path('modules/Blog');
     $this->finder = $this->app['files'];
     $this->artisan('module:make', ['name' => ['Blog']]);
     $this->finder->put($this->modulePath . '/Assets/script.js', 'assetfile');
 }