/**
  * 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 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 #3
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function handle()
 {
     $roles = $this->file->getRequire(base_path(config('trust.permissions')));
     $this->call('trust:permissions');
     $all = Permission::all(['id', 'slug']);
     $create = 0;
     $update = 0;
     foreach ($roles as $slug => $attributes) {
         $role = $this->findRole($slug);
         if ($role) {
             if ($this->option('force')) {
                 ++$update;
                 $role->update($attributes + compact('slug'));
             }
         } else {
             ++$create;
             $role = Role::create($attributes + compact('slug'));
         }
         $permissions = array_reduce(Arr::get($attributes, 'permissions', []), function (Collection $result, string $name) use($all) {
             if (hash_equals('*', $name)) {
                 return $all->pluck('id');
             }
             if ($all->count() === $result->count()) {
                 return $result;
             }
             $filtered = $all->filter(function (Permission $permission) use($name) {
                 return Str::is($name, $permission->slug);
             })->pluck('id');
             return $result->merge($filtered);
         }, new Collection());
         $role->permissions()->sync($permissions->toArray());
     }
     $total = $create + $update;
     $this->line("Installed {$total} roles. <info>({$create} new roles, {$update} roles synced)</info>");
 }
Example #4
0
 /**
  * Load a locale from a given path.
  *
  * @param  string  $path
  * @param  string  $locale
  * @param  string  $group
  * @return array
  */
 protected function loadPath($path, $locale, $group)
 {
     if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) {
         return $this->files->getRequire($full);
     }
     return array();
 }
Example #5
0
 /**
  * Find the extensions.
  *
  * @param  array $paths
  * @return array
  */
 public function findExtensions(array $paths)
 {
     $files = array();
     // Iterate over the paths.
     foreach ($paths as $path) {
         // Find the extension files.
         $found = $this->filesystem->glob($path . '/*/*/extension.php');
         // Check if we found some files.
         if (is_array($found)) {
             // Merge the files.
             $files = array_merge($files, $found);
         }
     }
     $extensions = array();
     // Iterate over the files.
     foreach ($files as $file) {
         // Get the extension attributes.
         $attributes = $this->filesystem->getRequire($file);
         // Check if the attributes are valid.
         if (is_array($attributes) && isset($attributes['slug'])) {
             // Initialise the extension class.
             $extensions[$attributes['slug']] = new Extension(dirname($file), $attributes);
         }
     }
     return $extensions;
 }
 /**
  * @param string $locale
  * @param string $group
  * @return array
  */
 public function get($locale, $group)
 {
     if ($this->fs->exists($path = $this->path . "/{$locale}/{$group}.php")) {
         return $this->fs->getRequire($path);
     }
     return [];
 }
Example #7
0
 public function getRequire($fullPath)
 {
     if (!$this->filesystem->exists($fullPath)) {
         return null;
     }
     return $this->filesystem->getRequire($fullPath);
 }
Example #8
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 #9
0
 /**
  * Load the settings from the cache.
  *
  * @param string $env
  *
  * @return array|false
  */
 public function load($env)
 {
     try {
         return $this->files->getRequire($this->path($env));
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * Load the environment variables for the given environment.
  *
  * @param  string  $environment
  * @return array
  */
 public function load($environment = null)
 {
     if ($environment == 'production') {
         $environment = null;
     }
     if (!$this->files->exists($path = $this->getFile($environment))) {
         return array();
     }
     return array_dot($this->files->getRequire($path));
 }
Example #11
0
 /**
  * Load the service provider manifest JSON file.
  *
  * @return array|null
  */
 public function loadManifest()
 {
     // The service manifest is a file containing a JSON representation of every
     // service provided by the application and whether its provider is using
     // deferred loading or should be eagerly loaded on each request to us.
     if ($this->files->exists($this->manifestPath)) {
         $manifest = $this->files->getRequire($this->manifestPath);
         return array_merge(['when' => []], $manifest);
     }
 }
Example #12
0
 private function __construct()
 {
     $this->_http = new Http();
     // Инициализация конфигов
     $fileSystem = new Filesystem();
     $files = $fileSystem->allFiles('config');
     foreach ($files as $file) {
         if (is_array($fileSystem->getRequire($file))) {
             $this->setConfig($fileSystem->getRequire($file), $fileSystem->name($file));
         }
     }
 }
 /**
  * Get a user by its ID.
  *
  * @param  mixed  $id
  * @return \Stidges\LaravelDbNormalizer\Entity
  */
 public function getById($id)
 {
     $users = $this->files->getRequire($this->path);
     $result = [];
     foreach ($users as $user) {
         if ($user['id'] == $id) {
             $result = $user;
             break;
         }
     }
     return $this->normalizer->normalize($result);
 }
 /**
  * Add namespace overrides to configuration.
  *
  * @param $namespace
  * @param $directory
  */
 public function addNamespaceOverrides($namespace, $directory)
 {
     if (!$this->files->isDirectory($directory)) {
         return;
     }
     /* @var SplFileInfo $file */
     foreach ($this->files->allFiles($directory) as $file) {
         $key = trim(str_replace($directory, '', $file->getPath()) . DIRECTORY_SEPARATOR . $file->getBaseName('.php'), DIRECTORY_SEPARATOR);
         // Normalize key slashes.
         $key = str_replace('\\', '/', $key);
         $this->config->set($namespace . '::' . $key, array_replace($this->config->get($namespace . '::' . $key, []), $this->files->getRequire($file->getPathname())));
     }
 }
Example #15
0
 /**
  * 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);
     }
 }
 /**
  * Get all the translations for all modules on disk
  * @return array
  */
 public function all()
 {
     $allFileTranslations = [];
     $files = $this->finder->allFiles($this->getTranslationsDirectory());
     foreach ($files as $file) {
         $lang = $this->getLanguageFrom($file->getRelativePath());
         $path = $file->getRelativePathname();
         $contents = $this->finder->getRequire($this->getTranslationsDirectory() . '/' . $path);
         $trans = array_dot($contents, $this->getModuleFrom($file->getRelativePath()) . '::' . $this->getFileNameFrom($path) . '.');
         foreach ($trans as $key => $value) {
             $allFileTranslations[$lang][$key] = $value;
         }
     }
     return $allFileTranslations;
 }
Example #17
0
 /**
  * Creates an Extension from the given fully qualified extension file.
  *
  * @param  string  $file
  * @return \Cartalyst\Extensions\ExtensionInterface
  * @throws \RuntimeException
  */
 public function create($file)
 {
     $attributes = $this->filesystem->getRequire($file);
     if (!is_array($attributes) || !isset($attributes['slug'])) {
         throw new \RuntimeException("Malformed extension.php at path [{$file}].");
     }
     $slug = $attributes['slug'];
     unset($attributes['slug']);
     $namespace = null;
     if (isset($attributes['namespace'])) {
         $namespace = $attributes['namespace'];
         unset($attributes['namespace']);
     }
     return new Extension($this, $slug, dirname($file), $attributes, $namespace, $this->cache);
 }
 /**
  * Get all the translations for all modules on disk
  * @return array
  */
 public function all()
 {
     $files = $this->getTranslationFilenamesFromPaths($this->loader->paths());
     $translations = [];
     foreach ($files as $locale => $files) {
         foreach ($files as $namespace => $file) {
             $trans = $this->finder->getRequire($file);
             $trans = array_dot($trans);
             foreach ($trans as $key => $value) {
                 $translations[$locale]["{$namespace}.{$key}"] = $value;
             }
         }
     }
     return $translations;
 }
Example #19
0
 /**
  * Loads a locale.
  *
  * @param string $locale A locale
  *
  * @throws NotFoundResourceException when the resource cannot be found
  * @throws InvalidResourceException  when the resource cannot be loaded
  *
  * @return array
  */
 public function load(string $locale) : array
 {
     $filename = "{$this->path}/{$locale}.php";
     try {
         $loaded = $this->files->getRequire($filename);
         if (!is_array($loaded)) {
             throw new InvalidResourceException();
         }
         return $loaded;
     } catch (FileNotFoundException $e) {
         throw new NotFoundResourceException("{$filename} not found.", 0, $e);
     } catch (\Throwable $e) {
         throw new InvalidResourceException("{$filename} has invalid resources.", 0, $e);
     }
 }
Example #20
0
 protected function loadDependencies()
 {
     // No other way of managing the composer dependencies currently.
     // See: https://github.com/concrete5/concrete5-5.7.0/issues/360
     $filesystem = new Filesystem();
     $filesystem->getRequire(__DIR__ . '/vendor/autoload.php');
 }
Example #21
0
 /**
  * Resolve a migration instance from a file.
  *
  * @param  string $path
  * @param  string $file
  * @return array
  */
 public function resolve($path, $file)
 {
     $migration = "{$path}/{$file}.php";
     if ($this->files->exists($migration)) {
         return $this->files->getRequire($migration);
     }
 }
Example #22
0
 /**
  * Load autoloader file.
  *
  * @param  string  $filePath
  *
  * @return void
  */
 protected function loadAutoloaderFile($filePath)
 {
     $filePath = $this->finder->resolveExtensionPath($filePath);
     if ($this->files->isFile($filePath)) {
         $this->files->getRequire($filePath);
     }
 }
Example #23
0
 /**
  * Load a local namespaced translation group for overrides.
  *
  * @param  array $lines
  * @param  string $locale
  * @param  string $group
  * @param  string $namespace
  * @return array
  */
 protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace)
 {
     $file = "{$this->path}/vendor/{$namespace}/{$locale}/{$group}.php";
     if ($this->files->exists($file)) {
         return array_replace_recursive($lines, $this->files->getRequire($file));
     }
     return $lines;
 }
 /**
  * Get paths from the model.
  *
  * @return array
  */
 public function getPaths()
 {
     // When no paths are specified we will try to load
     // them from the cache. The cached paths are composed
     // using the ApiList command from Cloudstack.
     if (empty($this->paths)) {
         $listPath = __DIR__ . '/cache/api_list.php';
         if (!$this->files->exists($listPath)) {
             // Without the API list we can't determine the available
             // Cloudstack API commands. This file needs to be generated
             // before we can use the client.
             throw new \RuntimeException("Cloudstack Client API list not found. This file needs to be generated before using the client.");
         }
         $paths = $this->files->getRequire($listPath);
         $this->paths = $paths;
     }
     return $this->paths;
 }
Example #25
0
 /**
  * @return array|null
  */
 public function loadManifest()
 {
     if ($this->files->exists($this->manifestPath)) {
         $manifest = $this->files->getRequire($this->manifestPath);
         if ($manifest) {
             return array_merge(['when' => []], $manifest);
         }
     }
 }
Example #26
0
 public function save($item, $value, $environment, $group, $namespace = null)
 {
     $path = $this->getStorageDirectory();
     if (!$this->files->exists($path)) {
         $this->files->makeDirectory($path, 0777);
     } elseif (!$this->files->isDirectory($path)) {
         $this->files->delete($path);
         $this->files->makeDirectory($path, 0777);
     }
     $ns_string = 'null';
     if ($namespace) {
         $ns_string = $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 = $this->getFilename($group, $path);
     $current = array();
     if ($this->files->exists($file)) {
         if (\Config::get('concrete.config.temp_save', true)) {
             // Make sure that we miss cache.
             $temp_file = tempnam($path, $group . '_');
             $contents = $this->files->get($file);
             $this->files->put($temp_file, $contents);
             $current = $this->files->getRequire($temp_file);
             $this->files->delete($temp_file);
         } else {
             $current = $this->files->getRequire($file);
         }
     }
     array_set($current, $item, $value);
     $renderer = new Renderer($current);
     $header = array("<?php", "", "/**", " * -----------------------------------------------------------------------------", " * Generated " . date(DATE_ATOM), " *", " * DO NOT EDIT THIS FILE DIRECTLY", " *", " * @item      {$item}", " * @group     {$group}", " * @namespace {$ns_string}", " * -----------------------------------------------------------------------------", " */", "return ");
     $rendered = $renderer->render(PHP_EOL, '    ', implode(PHP_EOL, $header));
     $result = $this->files->put($file, $rendered) !== false;
     if ($result) {
         OpCache::clear($file);
     }
     return $result;
 }
Example #27
0
 protected function parseRecipes(Filesystem $files)
 {
     $recipes = [];
     if ($files->exists(Cocktail::FILE_NAME)) {
         foreach ($files->getRequire(Cocktail::FILE_NAME) as $config) {
             $recipes[] = new Recipe($config);
         }
     }
     return $recipes;
 }
Example #28
0
 /**
  * Load the locale translation files.
  *
  * @param  string  $path
  *
  * @return array
  *
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 private function loadLocaleFiles($path)
 {
     $files = [];
     foreach ($this->filesystem->allFiles($path) as $file) {
         /** @var \Symfony\Component\Finder\SplFileInfo $file */
         $key = str_replace(['.php', DS], ['', '.'], $file->getRelativePathname());
         $files[$key] = ['path' => $file->getRealPath(), 'content' => $this->filesystem->getRequire($file)];
     }
     return $files;
 }
 /**
  * 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 #30
0
 /**
  * install.
  *
  * @method install
  */
 protected function install()
 {
     $storagePath = $this->getLaravel()->storagePath();
     $composerPath = $storagePath . '/app/composer/';
     if ($this->filesystem->exists($composerPath . 'vendor/autoload.php') === false) {
         if ($this->filesystem->isDirectory($composerPath) === false) {
             $this->filesystem->makeDirectory($composerPath, 0777);
         }
         $this->filesystem->put($composerPath . 'composer.phar', file_get_contents('https://getcomposer.org/composer.phar'));
         $composerPhar = new Phar($composerPath . 'composer.phar');
         $composerPhar->extractTo($composerPath);
         unset($composerPhar);
         $this->filesystem->delete($composerPath . 'composer.phar');
     }
     if (empty(getenv('COMPOSER_HOME')) === true) {
         putenv('COMPOSER_HOME=' . $composerPath);
     }
     $this->filesystem->getRequire($composerPath . 'vendor/autoload.php');
     $this->init();
 }