/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     foreach ($this->files->files(storage_path() . '/framework/sessions') as $file) {
         $this->files->delete($file);
     }
     $this->info('Session files deleted from storage');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     foreach ($this->files->files(storage_path() . '/logs') as $file) {
         $this->files->delete($file);
     }
     $this->info('Log files deleted from storage');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     foreach ($this->files->files(storage_path() . '/views') as $file) {
         $this->files->delete($file);
     }
     $this->info('Views deleted from cache');
 }
Example #4
0
 /**
  * Do not overwrite a migration file
  *
  * @access protected
  * @param string $filePath
  * @param string $name
  * @return void
  */
 protected function doNotOverwriteFile($filePath, $name)
 {
     foreach ($this->file->files($filePath) as $file) {
         if (strpos($file, $name) !== false) {
             throw new FileExistsException($file);
         }
     }
 }
 /**
  * @param int $minutes
  *
  * @return \Illuminate\Support\Collection
  */
 public function deleteFilesOlderThanMinutes(int $minutes) : Collection
 {
     $timeInPast = Carbon::now()->subMinutes($minutes);
     return collect($this->filesystem->files($this->directory))->filter(function ($file) use($timeInPast) {
         return Carbon::createFromTimestamp(filemtime($file))->lt($timeInPast);
     })->each(function ($file) {
         $this->filesystem->delete($file);
     });
 }
 /**
  * First round
  * @param $path
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function firstRound($path)
 {
     foreach ($this->file->files($path) as $file) {
         //Extension .php
         if (preg_match("|\\.php\$|", $file)) {
             $this->handle($this->file->get($file));
         }
     }
 }
Example #7
0
 /**
  * @return array
  */
 public function getCatalogs()
 {
     $result = array();
     foreach ($this->filesystem->directories($this->getLangDir()) as $langPath) {
         foreach ($this->filesystem->files($langPath) as $file) {
             $catalog = str_replace($langPath . '/', '', $file);
             $catalog = preg_replace('/\\.php$/', '', $catalog);
             $result[$catalog] = $catalog;
         }
     }
     return array_keys($result);
 }
Example #8
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $countries = $this->files->directories($this->path);
     $cities = [];
     foreach ($countries as $countryDirectory) {
         $states = $this->files->files($countryDirectory);
         $country = $this->last(explode(DIRECTORY_SEPARATOR, $countryDirectory));
         foreach ($states as $stateDirectory) {
             list($state, $_) = explode('.', $this->last(explode(DIRECTORY_SEPARATOR, $stateDirectory)));
             $data = $this->loader->load($country, $state, 'en');
             foreach ($data as $key => $name) {
                 $cities[] = ['name' => $name, 'code' => "{$country} {$state} {$key}", 'state_id' => "{$country} {$state}"];
             }
         }
     }
     $cities = Collection::make($cities);
     $hash = md5($cities->toJson());
     if (!$this->option('force') && $hash === $this->hash) {
         $this->line('No new city.');
         return false;
     }
     $cityCodes = $cities->pluck('code');
     $stateCodes = $cities->pluck('state_id')->unique();
     $stateIds = Collection::make(DB::table($this->states)->whereIn('code', $stateCodes)->pluck('id', 'code'));
     $cities = $cities->map(function ($item) use($stateIds) {
         $item['state_id'] = $stateIds->get($item['state_id']);
         return $item;
     });
     $existingCityIDs = Collection::make(DB::table($this->cities)->whereIn('code', $cityCodes)->pluck('id', 'code'));
     $cities = $cities->map(function ($item) use($existingCityIDs) {
         if ($existingCityIDs->has($item['code'])) {
             $item['id'] = $existingCityIDs->get($item['code']);
         }
         return $item;
     });
     $cities = $cities->groupBy(function ($item) {
         return array_has($item, 'id') ? 'update' : 'create';
     });
     DB::transaction(function () use($cities, $hash) {
         $create = Collection::make($cities->get('create'));
         $update = Collection::make($cities->get('update'));
         foreach ($create->chunk(static::QUERY_LIMIT) as $entries) {
             DB::table($this->cities)->insert($entries->toArray());
         }
         foreach ($update as $entries) {
             DB::table($this->cities)->where('id', $entries['id'])->update($entries);
         }
         $this->line("{$create->count()} cities created. {$update->count()} cities updated.");
         $this->files->put(storage_path(static::INSTALL_HISTORY), $hash);
     });
     return true;
 }
Example #9
0
 /**
  * @param Theme $theme
  *
  * @return array
  */
 public function findAvailableTemplates(Theme $theme)
 {
     $files = $this->filesystem->files($theme->getTemplateDirectory());
     $templates = [];
     if (is_array($files)) {
         foreach ($files as $filename) {
             if (pathinfo($filename, PATHINFO_EXTENSION) === 'php') {
                 $templates[] = basename($filename, '.php');
             }
         }
     }
     return $templates;
 }
Example #10
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     \DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     foreach ($this->filesystem->files(__DIR__ . "/../../../../database/migrations") as $file) {
         $this->filesystem->requireOnce($file);
         $migrationClass = $this->classFinder->findClass($file);
         $migration = new $migrationClass();
         $migration->down();
         $migration->up();
     }
     $this->info("Merx tables migrated.");
     \DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Example #11
0
 /**
  * Run package database migrations.
  * Thanks http://stackoverflow.com/questions/27759301/setting-up-integration-tests-in-a-laravel-package
  *
  * @return void
  */
 public function migrate()
 {
     $fileSystem = new Filesystem();
     $classFinder = new ClassFinder();
     $packageMigrations = $fileSystem->files(__DIR__ . "/../../src/Migrations");
     $laravelMigrations = $fileSystem->files(__DIR__ . "/../../vendor/laravel/laravel/database/migrations");
     $migrationFiles = array_merge($laravelMigrations, $packageMigrations);
     foreach ($migrationFiles as $file) {
         $fileSystem->requireOnce($file);
         $migrationClass = $classFinder->findClass($file);
         (new $migrationClass())->up();
     }
 }
Example #12
0
 public function findAvailableTemplates(Theme $theme)
 {
     $files = $this->filesystem->files($theme->getTemplateDirectory());
     $templates = [];
     if (is_array($files)) {
         foreach ($files as $file) {
             if (strpos($file, '.php') !== false) {
                 $file = str_replace($theme->getTemplateDirectory() . '/', '', $file);
                 $templates[] = str_replace('.php', '', $file);
             }
         }
     }
     return $templates;
 }
 /**
  * run package database migrations
  *
  * @return void
  */
 public function migrate()
 {
     $fileSystem = new Filesystem();
     $classFinder = new ClassFinder();
     foreach ($fileSystem->files(__DIR__ . "/migrations") as $file) {
         $fileSystem->requireOnce($file);
         $migrationClass = $classFinder->findClass($file);
         (new $migrationClass())->up();
     }
     foreach ($fileSystem->files(__DIR__ . "/seeds") as $file) {
         $fileSystem->requireOnce($file);
         $migrationClass = $classFinder->findClass($file);
         (new $migrationClass())->run();
     }
 }
 private function parseDir($dir)
 {
     $items = array();
     $files = $this->files->files($dir);
     foreach ($files as $file) {
         $name = basename($file);
         $name = str_replace('.php', '', $name);
         $items[$name] = (require $file);
     }
     $dirs = $this->files->directories($dir);
     foreach ($dirs as $dir) {
         $name = basename($dir);
         $items[$name] = $this->parseDir($dir);
     }
     return $items;
 }
Example #15
0
 /**
  * Create captcha image
  *
  * @param string $config
  * @return ImageManager->response
  */
 public function create($config = 'default')
 {
     $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds');
     $this->fonts = $this->files->files(__DIR__ . '/../assets/fonts');
     $this->fonts = array_values($this->fonts);
     //reset fonts array index
     $this->configure($config);
     $this->text = $this->generate();
     session_start();
     $_SESSION['text'] = $this->text;
     $this->canvas = $this->imageManager->canvas($this->width, $this->height, $this->bgColor);
     if ($this->bgImage) {
         $this->image = $this->imageManager->make($this->background())->resize($this->width, $this->height);
         $this->canvas->insert($this->image);
     } else {
         $this->image = $this->canvas;
     }
     if ($this->contrast != 0) {
         $this->image->contrast($this->contrast);
     }
     $this->text();
     $this->lines();
     if ($this->sharpen) {
         $this->image->sharpen($this->sharpen);
     }
     if ($this->invert) {
         $this->image->invert($this->invert);
     }
     if ($this->blur) {
         $this->image->blur($this->blur);
     }
     return $this->image->response('png', $this->quality);
 }
Example #16
0
 /**
  * @param string $config
  * @return ImageManager->response
  */
 public function create($config = 'default')
 {
     $this->backgrounds = $this->files->files(base_path() . "/resources/assets/Captcha/backgrounds");
     $this->fonts = $this->files->files(base_path() . "/resources/assets/Captcha/fonts");
     $this->configure($config);
     $this->text = $this->generate();
     $this->canvas = $this->imageManager->canvas($this->width, $this->height, $this->bgColor);
     if ($this->bgImage) {
         $this->image = $this->imageManager->make($this->background())->resize($this->width, $this->height);
         $this->canvas->insert($this->image);
     } else {
         $this->image = $this->canvas;
     }
     if ($this->contrast != 0) {
         $this->image->contrast($this->contrast);
     }
     $this->text();
     $this->lines();
     if ($this->sharpen) {
         $this->image->sharpen($this->sharpen);
     }
     if ($this->invert) {
         $this->image->invert($this->invert);
     }
     if ($this->blur) {
         $this->image->blur($this->blur);
     }
     return $this->image->response('png', $this->quality);
 }
 /**
  * Creates the undo file
  *
  * @return void
  */
 protected function createUndoFile()
 {
     // The generated files
     $generatedFiles = [];
     // Scan folders for generated files
     foreach (['app', 'database/migrations'] as $folder) {
         // For every file inside this folder
         foreach ($this->filesystem->files($folder) as $file) {
             // If lastModified time of this file is greater or equal to $this->startTime
             if ($this->filesystem->lastModified($file) >= $this->startTime) {
                 // Add this file to our generated files array
                 $generatedFiles[] = $file;
             }
         }
     }
     // If we do not have any generated files
     if (empty($generatedFiles)) {
         // Show error message and end method execution
         $this->error('No generated files created');
         return;
     }
     // Output generated files to console
     $this->info("The following files have been created:");
     foreach ($generatedFiles as $generatedFile) {
         $this->info("  {$generatedFile}");
     }
     // Save $generatedFiles to undo file if directory is writeable
     if ($this->filesystem->isWritable($this->filePathDirectory)) {
         // Write undo json file
         $this->filesystem->put($this->undoFilePath, json_encode($generatedFiles, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
     } else {
         // Show error that file could not be created
         $this->error('Could not create undo file, not enough permissions perhaps?: ' . $this->undoFilePath);
     }
 }
Example #18
0
 /**
  * Set up the filesystem doubles.
  *
  * @param Filesystem $filesystem
  * @param string $filePath
  * @param bool $isDir
  * @param array $returnDirs
  * @param array $returnFiles
  */
 private function setupFilesystemMethods($filesystem, $filePath, $isDir = false, $returnDirs = [], $returnFiles = [])
 {
     $filesystem->isDirectory($this->postPath)->willReturn($isDir);
     $filesystem->exists($filePath)->willReturn(true);
     $filesystem->get($filePath)->willReturn($this->markdown);
     $filesystem->directories($this->postPath)->willReturn($returnDirs);
     $filesystem->files($this->postPath)->willReturn($returnFiles);
 }
 /**
  * Delete previews older than the given life time configuration.
  */
 private function cleanOldPreviews()
 {
     $oldPreviews = array_filter($this->files->files($this->storage()), function ($file) {
         return time() - $this->files->lastModified($file) > Config::get('mail-debug.lifetime') * 60;
     });
     if ($oldPreviews) {
         $this->files->delete($oldPreviews);
     }
 }
Example #20
0
 /**
  * Get an array of class names of all models.
  *
  * @return array|string Array of class name to module name.
  */
 public function getModels($fullClass = false)
 {
     $out = array();
     // First get the core model classes.
     foreach ($this->fs->files(app_path() . "/Model") as $f) {
         $className = $this->classNameFromFile($f, $fullClass);
         $out[$className] = '';
     }
     // Then get the modules' model classes.
     foreach ($this->getAll() as $name => $path) {
         foreach ($this->fs->files(app_path() . "/../{$path}/Model") as $f) {
             $className = $this->classNameFromFile($f, $fullClass);
             $out[$className] = basename($path);
             // 'Ormic\\' . studly_case($name) . '\Model\\' . $className;
         }
     }
     return $out;
 }
 /**
  * Delete previews older than the given life time configuration.
  *
  * @return void
  */
 private function cleanOldPreviews()
 {
     $oldPreviews = array_filter($this->files->files($this->previewPath), function ($file) {
         return time() - $this->files->lastModified($file) > $this->lifeTime;
     });
     if ($oldPreviews) {
         $this->files->delete($oldPreviews);
     }
 }
Example #22
0
 protected static function loadFixtures()
 {
     $system = new Filesystem();
     foreach ($system->files(__DIR__ . '/../fixtures') as $file) {
         $fixture_name = Str::singular(basename($file, '.php'));
         $fixtures = (require $file);
         static::createFixtures($fixture_name, $fixtures);
     }
 }
Example #23
0
 /**
  * Index all documentation for a given version.
  *
  * @param  string  $version
  * @return void
  */
 public function indexAllDocumentsForVersion($version)
 {
     $versionPath = base_path('resources/docs/' . $version . '/');
     foreach ($this->files->files($versionPath) as $path) {
         if (!in_array(basename($path, '.md'), $this->noIndex)) {
             $this->indexDocument($version, $path);
         }
     }
 }
Example #24
0
 /**
  * Run all database migrations from the specified path
  * 
  * @param  string $path
  * @return void
  */
 protected function migrateDatabaseFromPath($path)
 {
     $fileSystem = new Filesystem();
     $classFinder = new ClassFinder();
     foreach ($fileSystem->files($path) as $file) {
         $fileSystem->requireOnce($file);
         $migrationClass = $classFinder->findClass($file);
         (new $migrationClass())->up();
     }
 }
Example #25
0
 /**
  * run package database migrations
  *
  * @return void
  */
 public function migrate()
 {
     $fileSystem = new Filesystem();
     $classFinder = new ClassFinder();
     foreach ($fileSystem->files(__DIR__ . "/../src/Commands") as $file) {
         $fileSystem->requireOnce($file);
         $migrationClass = $classFinder->findClass($file);
         (new $migrationClass())->fire();
     }
 }
 /**
  * loadConfiguration method
  *
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 protected function loadConfiguration()
 {
     /** @var \Illuminate\Filesystem\Filesystem $fs */
     $fs = new Filesystem();
     $items = new Repository();
     foreach ($fs->files($this->getConfigDir()) as $file) {
         $items->set(Path::getFilenameWithoutExtension($file), $fs->getRequire($file));
     }
     $this->items = $items;
 }
Example #27
0
 public function findAvailableTemplates(Theme $theme)
 {
     $filesArr = $this->filesystem->files($theme->getTemplateDirectory());
     if (!is_array($filesArr)) {
         return [];
     }
     $templatesArr = [];
     foreach ($filesArr as $fileStr) {
         if (strpos($fileStr, '.php') === false) {
             continue;
         }
         // if does not have .php skip it.
         $fileStr = str_replace($theme->getTemplateDirectory() . '/', '', $fileStr);
         // remove the template directory
         $templatesArr[] = str_replace('.php', '', $fileStr);
         // remove .php
     }
     return $templatesArr;
 }
Example #28
0
 /**
  * Bootstrap any application services.
  *
  * @param Filesystem $filesystem
  */
 public function boot(Filesystem $filesystem)
 {
     foreach ($filesystem->files(app_path('Libraries/Macros')) as $file) {
         $filesystem->requireOnce($file);
     }
     if ($this->app->environment(['local'])) {
         $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
         $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
         $this->app->register(\Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class);
     }
 }
 /**
  * Run package database migrations.
  */
 public function migrate()
 {
     $fileSystem = new Filesystem();
     $classFinder = new ClassFinder();
     foreach ($fileSystem->files(__DIR__ . '/App/database/migrations') as $file) {
         $fileSystem->requireOnce($file);
         $migrationClass = $classFinder->findClass($file);
         (new $migrationClass())->down();
         (new $migrationClass())->up();
     }
 }
 public function importTranslations($replace = false)
 {
     $counter = 0;
     foreach ($this->files->directories($this->app->langPath()) as $langPath) {
         $locale = basename($langPath);
         foreach ($this->files->files($langPath) as $file) {
             $info = pathinfo($file);
             $group = $info['filename'];
             if (in_array($group, $this->config['exclude_groups'])) {
                 continue;
             }
             $translations = \Lang::getLoader()->load($locale, $group);
             if ($translations && is_array($translations)) {
                 foreach (array_dot($translations) as $key => $value) {
                     $value = (string) $value;
                     $translation = Translation::firstOrNew(array('locale' => $locale, 'group' => $group, 'key' => $key));
                     // Check if the database is different then the files
                     $newStatus = $translation->value === $value ? Translation::STATUS_SAVED : Translation::STATUS_CHANGED;
                     if ($newStatus !== (int) $translation->status) {
                         $translation->status = $newStatus;
                     }
                     // Only replace when empty, or explicitly told so
                     if ($replace || !$translation->value) {
                         $translation->value = $value;
                     }
                     $translation->save();
                     $counter++;
                 }
             }
         }
     }
     return $counter;
 }