/**
  * Extension list.
  *
  * @return \Illuminate\Support\Collection
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function getExtensions()
 {
     if ($this->extensions->isEmpty()) {
         if ($this->files->isDirectory($this->getExtensionPath()) && !empty($vendors = $this->files->directories($this->getExtensionPath()))) {
             collect($vendors)->each(function ($vendor) {
                 if ($this->files->isDirectory($vendor) && !empty($directories = $this->files->directories($vendor))) {
                     collect($directories)->each(function ($directory) {
                         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-extension' && ($name = Arr::get($package, 'name'))) {
                                 $extension = new Extension($name);
                                 $extension->setAuthor(Arr::get($package, 'authors'));
                                 $extension->setDescription(Arr::get($package, 'description'));
                                 if ($entries = data_get($package, 'autoload.psr-4')) {
                                     foreach ($entries as $namespace => $entry) {
                                         $extension->setEntry($namespace . 'Extension');
                                     }
                                 }
                                 $this->extensions->put($directory, $extension);
                             }
                         }
                     });
                 }
             });
         }
     }
     return $this->extensions;
 }
 public function importTranslations($replace = false)
 {
     $counter = 0;
     foreach ($this->files->directories($this->app->langPath()) as $langPath) {
         $locale = basename($langPath);
         foreach ($this->files->allFiles($langPath) as $file) {
             $group = $file->getRelativePathname();
             $group = str_replace('.' . $this->files->extension($group), '', $group);
             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;
 }
 public function importTranslations($replace = false)
 {
     $counter = 0;
     foreach ($this->files->directories($this->app->make('path') . '/lang') 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 = array_dot(\Lang::getLoader()->load($locale, $group));
             foreach ($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;
 }
Exemple #4
0
 /**
  * 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;
 }
 function available_languages()
 {
     $langs = $this->filesystem->directories($this->storage_path);
     $langs = array_map(function ($l) {
         return basename($l);
     }, $langs);
     return $langs;
 }
 /**
  * Handle the command.
  *
  * @param ClassMapGenerator $generator
  * @param Filesystem $files
  */
 public function handle(ClassMapGenerator $generator, Filesystem $files)
 {
     foreach ($files->directories(base_path('storage/streams')) as $directory) {
         if (is_dir($models = $directory . '/models')) {
             $generator->dump($files->directories($models), $models . '/classmap.php');
         }
     }
 }
Exemple #7
0
 public function findInstalledThemes()
 {
     $theme = new Theme();
     $themes = $this->filesystem->directories($theme->getThemesDirectory());
     if (is_array($themes)) {
         foreach ($themes as &$t) {
             $t = new Theme(str_replace($theme->getThemesDirectory() . '/', '', $t));
         }
     }
     return $themes ?: [];
 }
Exemple #8
0
 /**
  * Get all themes.
  *
  * @return Collection
  */
 public function all()
 {
     $themes = [];
     if ($this->files->exists($this->getPath())) {
         $scannedThemes = $this->files->directories($this->getPath());
         foreach ($scannedThemes as $theme) {
             $themes[] = basename($theme);
         }
     }
     return new Collection($themes);
 }
Exemple #9
0
 /**
  * @return mixed
  */
 private function findThemes()
 {
     $directories = $this->filesystem->directories($this->config->get('themes.path'));
     return Collection::make($directories)->reduce(function (&$initial, $directory) {
         $plugin = $this->get_theme_date($directory . '/style.css');
         if (!empty($plugin['Name']) && !empty($plugin['Version'])) {
             $plugin['Name'] = basename($directory);
             $initial[] = $this->transformWPPluginToTheme($plugin);
         }
         return $initial;
     }, []);
 }
Exemple #10
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;
 }
Exemple #11
0
 /**
  * Get all themes
  */
 public function all()
 {
     $themes = array();
     if (!$this->filesystem->isDirectory($path = $this->themesPath)) {
         return array();
     }
     $directories = $this->filesystem->directories($path);
     foreach ($directories as $theme) {
         $themeName = basename($theme);
         $themes[$themeName] = $this->getThemeInfo($themeName);
     }
     return $themes;
 }
Exemple #12
0
 /**
  * Get all module basenames
  *
  * @return array
  */
 protected function getAllBasenames()
 {
     $path = $this->getPath();
     try {
         $collection = collect($this->files->directories($path));
         $basenames = $collection->map(function ($item, $key) {
             return basename($item);
         });
         return $basenames;
     } catch (\InvalidArgumentException $e) {
         return collect(array());
     }
 }
Exemple #13
0
 /**
  * Create a cache of the themes which are available on the filesystem.
  *
  * @return array
  */
 public function findAndInstallThemes()
 {
     $theme = new Theme();
     $directories = $this->filesystem->directories($theme->getThemesDirectory());
     $themes = [];
     if (is_array($directories)) {
         foreach ($directories as $directory) {
             $themeName = basename($directory);
             $themes[] = new Theme($themeName);
         }
     }
     $this->cache->forever($this->cacheKey, $themes);
     return $themes;
 }
 /**
  * Load extensions in memory
  *
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function loadExtensions()
 {
     $extensions = $this->filesystem->directories($this->path);
     foreach ($extensions as $extension) {
         $name = basename($extension);
         $class = $this->extensionClass($name);
         $this->filesystem->getRequire($extension . '/start.php');
         $extensionInstance = new $class($extension, $name);
         if (in_array($name, $this->settings->get('extensions', []))) {
             $extensionInstance->setActive();
         }
         $this->extensions->push($extensionInstance);
     }
 }
Exemple #15
0
 /**
  * @return mixed
  */
 private function findPlugins()
 {
     $directories = $this->filesystem->directories($this->config->get('plugins.path'));
     return Collection::make($directories)->reduce(function (&$initial, $directory) {
         $files = $this->filesystem->glob($directory . '/*.php');
         foreach ($files as $file) {
             $plugin = $this->get_plugin_data($file);
             if (!empty($plugin['Title']) && !empty($plugin['Version'])) {
                 $plugin['Name'] = basename($directory);
                 $initial[] = $this->transformWPPluginToPlugin($plugin);
             }
         }
         return $initial;
     }, []);
 }
Exemple #16
0
 /**
  * Get all modules.
  *
  * @return array
  */
 public function all()
 {
     $modules = array();
     $path = $this->getPath();
     if (!is_dir($path)) {
         return $modules;
     }
     $folders = $this->files->directories($path);
     foreach ($folders as $module) {
         if (!Str::startsWith($module, '.')) {
             $modules[] = basename($module);
         }
     }
     return $modules;
 }
Exemple #17
0
 public function getTranslations($catalog)
 {
     $data = array();
     $rootDir = dirname($this->app->make('path'));
     foreach ($this->filesystem->directories($rootDir . '/resources/lang') as $langPath) {
         $locale = basename($langPath);
         $fileName = $langPath . '/' . $catalog . '.php';
         $date = date_create_from_format('U', filemtime($fileName));
         $translations = array_dot(\Lang::getLoader()->load($locale, $catalog));
         foreach ($translations as $key => $value) {
             $data[$key][$locale] = array('message' => $value, 'updatedAt' => $date->format('c'), 'fileName' => $fileName, 'bundle' => $catalog);
         }
     }
     return $data;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire(Filesystem $files)
 {
     $langDirectory = base_path('resources' . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR);
     $diff = [];
     foreach (ModulesLoader::getRegisteredModules() as $module) {
         if (!is_dir($module->getLocalePath()) or !$module->isPublishable()) {
             continue;
         }
         $locale = $this->input->getOption('locale');
         foreach ($files->directories($module->getLocalePath()) as $localeDir) {
             foreach ($files->allFiles($localeDir) as $localeFile) {
                 $vendorFileDir = $module->getKey() . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFile->getFilename();
                 $vendorFilePath = $langDirectory . $vendorFileDir;
                 if (file_exists($vendorFilePath)) {
                     $localArray = $files->getRequire($localeFile->getRealPath());
                     $vendorArray = $files->getRequire($vendorFilePath);
                     $array = array_keys_exists_recursive($localArray, $vendorArray);
                     $arrayDiff = '';
                     foreach (array_dot($array) as $key => $value) {
                         $arrayDiff .= "{$key}: {$value}\n";
                     }
                     if (empty($arrayDiff)) {
                         continue;
                     }
                     $diff[] = ['modules' . DIRECTORY_SEPARATOR . $vendorFileDir, 'vendor' . DIRECTORY_SEPARATOR . $vendorFileDir];
                     $diff[] = new TableSeparator();
                     $diff[] = [$arrayDiff, var_export(array_merge_recursive($array, $vendorArray), true)];
                     $diff[] = new TableSeparator();
                 }
             }
         }
     }
     $this->table($this->headers, $diff);
 }
 public function stepDirectories($directory)
 {
     // Check for markers
     $alteredDirectoryName = $this->checkAndReplace($directory);
     // Move the directory and use the new name
     if ($directory !== $alteredDirectoryName) {
         exec("mv {$directory} {$alteredDirectoryName}");
         $directory = $alteredDirectoryName;
     }
     // For every file in the directory, rename and check content
     foreach ($this->files->allFiles($directory) as $file) {
         // Check for changes
         $alteredFilename = $this->checkAndReplace($file);
         // Rename file if it changed
         if ($file !== $alteredFilename) {
             rename($file, $alteredFilename);
             $file = $alteredFilename;
         }
         // Check the content in file, and rename as well
         file_put_contents($file, $this->checkAndReplace(file_get_contents($file)));
     }
     // Continue down the tree
     foreach ($this->files->directories($directory) as $childDirectory) {
         $this->stepDirectories($childDirectory);
     }
 }
Exemple #20
0
 /**
  * @return \Illuminate\Support\Collection
  */
 public function getExtensionPaths()
 {
     if ($this->extensionPaths->isEmpty()) {
         if ($this->filesystem->exists($file = $this->getVendorPath() . DIRECTORY_SEPARATOR . 'composer' . DIRECTORY_SEPARATOR . 'installed.json')) {
             $packages = new Collection(json_decode($this->filesystem->get($file), true));
             $packages->each(function (array $package) {
                 $name = Arr::get($package, 'name');
                 if (Arr::get($package, 'type') == 'notadd-extension' && $name) {
                     $this->extensionPaths->put($name, $this->getVendorPath() . DIRECTORY_SEPARATOR . $name);
                 }
             });
         }
         if ($this->filesystem->isDirectory($this->getExtensionPath()) && !empty($directories = $this->filesystem->directories($this->getExtensionPath()))) {
             (new Collection($directories))->each(function ($directory) {
                 if ($this->filesystem->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
                     $package = new Collection(json_decode($this->filesystem->get($file), true));
                     if (Arr::get($package, 'type') == 'notadd-extension' && ($name = Arr::get($package, 'name'))) {
                         $this->extensionPaths->put($name, $directory);
                     }
                 }
             });
         }
     }
     return $this->extensionPaths;
 }
 /**
  * extracts the component instances
  *
  * @return array
  */
 protected function extractComponentInstances()
 {
     $componentInstances = [];
     // let's make sure that components path given is a directory
     if ($this->filesystem->isDirectory($this->path)) {
         foreach ($this->filesystem->directories($this->path) as $dir) {
             if ($this->filesystem->exists($dir . '/Component.php')) {
                 $componentInstance = (require_once $dir . '/Component.php');
                 if ($componentInstance instanceof ComponentInterface) {
                     array_push($componentInstances, $componentInstance);
                 }
             }
         }
     }
     return $componentInstances;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire(Filesystem $files)
 {
     $data = [];
     $newLocale = $this->input->getOption('locale');
     foreach (app('module.loader')->getRegisteredModules() as $module) {
         if (!is_dir($module->getLocalePath())) {
             continue;
         }
         foreach ($files->directories($module->getLocalePath()) as $localeDir) {
             $locale = basename($localeDir);
             if ($locale != $this->copiedLocale) {
                 continue;
             }
             foreach ($files->allFiles($localeDir) as $localeFile) {
                 $data[strtolower($module->getName())][] = $localeFile->getRealPath();
             }
         }
     }
     $langDirectory = base_path('/resources/lang/packages');
     foreach ($data as $namespace => $locales) {
         foreach ($locales as $group => $file) {
             $filename = pathinfo($file, PATHINFO_FILENAME);
             $fileDir = $langDirectory . DIRECTORY_SEPARATOR . $newLocale . DIRECTORY_SEPARATOR . $namespace;
             if (!$files->exists($fileDir)) {
                 $files->makeDirectory($fileDir, 0755, TRUE);
             }
             $files->copy($file, $fileDir . DIRECTORY_SEPARATOR . $filename . '.php');
         }
     }
 }
 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;
 }
Exemple #24
0
 public function __construct()
 {
     $this->fs = new Filesystem();
     foreach ($this->fs->directories(app_path() . '/../modules') as $dir) {
         $moduleName = basename($dir);
         $metafile = $dir . '/module.json';
         $meta = new \stdClass();
         $meta->disabled = false;
         if (file_exists($metafile)) {
             $meta = json_decode(file_get_contents($metafile));
         }
         if (!$meta->disabled) {
             $this->modules[$moduleName] = 'modules/' . $moduleName;
         }
     }
 }
 /**
  * Remove all items from the cache.
  *
  * @return void
  */
 public function flush()
 {
     if ($this->files->isDirectory($this->directory)) {
         foreach ($this->files->directories($this->directory) as $directory) {
             $this->files->deleteDirectory($directory);
         }
     }
 }
 /**
  * Delete subdirectories in the migrations folder.
  *
  * @return void
  */
 public function deleteDirs()
 {
     $dirs = $this->files->directories($this->basePath);
     foreach ($dirs as $dir) {
         $this->files->deleteDirectory($dir);
     }
     $this->info('Subdirectories deleted');
 }
Exemple #27
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);
 }
 public function toc()
 {
     $documentationPath = $this->getDocumentationPath();
     $files = $this->finder->allFiles($documentationPath);
     $directories = $this->finder->directories($documentationPath);
     $toc = [];
     foreach ($directories as $dir) {
         $directoryName = str_replace('-', ' ', basename($dir));
         $toc[$directoryName] = [];
     }
     foreach ($files as $file) {
         $cleanedModuleName = str_replace('-', ' ', $file->getRelativePath());
         if (isset($toc[$cleanedModuleName])) {
             $toc[$cleanedModuleName][] = ['request' => $this->getRequestName($file), 'url' => route('doc.show', [$this->getRouteName($file)]), 'name' => $this->getFileName($file)];
         }
     }
     return $toc;
 }
 public function importTranslations()
 {
     $counter = 0;
     foreach ($this->files->directories($this->app->langPath()) as $langPath) {
         $locale = basename($langPath);
         foreach ($this->files->allfiles($langPath) as $file) {
             $info = pathinfo($file);
             $group = $info['filename'];
             if (in_array($group, $this->config['exclude_groups'])) {
                 continue;
             }
             if ($langPath != $info['dirname']) {
                 $group = substr(str_replace($langPath, '', $info['dirname']) . '/' . $info['filename'], 1);
             }
             $g = Group::firstOrNew(array('label' => $group));
             $g->save();
             $l = Locale::firstOrNew(array('label' => $locale));
             $l->save();
             $translations = \Lang::getLoader()->load($locale, $group);
             if ($translations && is_array($translations)) {
                 foreach (array_dot($translations) as $key => $value) {
                     // process only string values
                     if (is_array($value)) {
                         continue;
                     }
                     $value = (string) $value;
                     $translation = Translation::firstOrNew(['locale_id' => $l->id, 'key' => $key]);
                     $g->translations()->save($translation);
                     // 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;
                     }
                     $translation->value = $value;
                     $translation->save();
                     $counter++;
                 }
             }
         }
     }
     return $counter;
 }
 /**
  * Load directories.
  *
  * @param  string  $dirPath
  *
  * @return \Arcanedev\LaravelLang\Entities\LocaleCollection
  */
 private function loadDirectories($dirPath)
 {
     $locales = new LocaleCollection();
     foreach ($this->filesystem->directories($dirPath) as $path) {
         $excluded = in_array($key = basename($path), $this->excludedFolders);
         if (!$excluded) {
             $locales->add(new Locale($key, $path, $this->loadLocaleFiles($path)));
         }
     }
     return $locales;
 }