Example #1
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);
 }
 /**
  * 事前ファイル取得
  *
  * @param string $fileName ファイル名
  * @param string $initialValue ファイルが存在しない場合の初期値
  * @return string ファイルの内容
  */
 public function read($fileName, $initialValue = '')
 {
     if (!$this->file->isFile($fileName)) {
         return $initialValue;
     }
     // 前回の保存データーを取得
     return $this->file->get($fileName);
 }
 /**
  * @param string $directory
  *
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  *
  * @return array
  */
 private function getChangelog($directory)
 {
     if (!$this->finder->isFile($directory . '/changelog.yml')) {
         return [];
     }
     $yamlFile = $this->finder->get($directory . '/changelog.yml');
     $yamlParser = new Parser();
     $changelog = $yamlParser->parse($yamlFile);
     $changelog['versions'] = $this->limitLastVersionsAmount(array_get($changelog, 'versions', []));
     return $changelog;
 }
Example #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // 確認是否有 api key
     if (null === $this->apiPublicKey) {
         $this->error('Invalid VirusTotal api public key.');
         return;
     }
     if (!$this->filesystem->isFile($file = $this->argument('file'))) {
         $this->error('File not exists.');
         return;
     }
     // 取得欲儲存的 Model
     if (null === ($model = $this->option('model'))) {
         $model = $this->ask('The Eloquent ORM Model');
     }
     // 取得欲儲存的欄位
     if (null === ($column = $this->option('column'))) {
         $column = $this->ask('The table\'s column to store the result');
     }
     // 取得欲儲存的欄位
     if (null === ($index = $this->option('index'))) {
         $index = $this->ask('The primary key\'s value to specific row');
     }
     // 檢查 Model 是否存在
     if (!class_exists($model)) {
         $this->error('Model not exists.');
         return;
     }
     $model = (new $model())->find($index);
     // 檢查該比資料是否存在
     if (null === $model) {
         $this->error('Model not exists');
         return;
     }
     // 檢查欄位是否存在
     if (!Schema::hasColumn($model->getTableName(), $column)) {
         $this->error('Column not exists.');
         return;
     }
     // 檢查是否有替代檔名
     if (null !== ($fakeName = $this->option('fakeName')) && strlen($fakeName) > 0) {
         $fakePath = temp_path($fakeName);
         $this->filesystem->copy($file, $fakePath);
         $file = $fakePath;
     }
     $virusTotal = new File($this->apiPublicKey);
     $report = $virusTotal->scan($file);
     $model->{$column} = $report['permalink'];
     $model->save();
     if (isset($fakePath)) {
         $this->filesystem->delete($fakePath);
     }
     $this->info('File scan successfully!');
 }
Example #5
0
 /**
  * 初始化匯入資料.
  *
  * @return void
  */
 protected function init()
 {
     $dir = $this->option('dir') ? realpath($this->option('dir')) : false;
     if (false !== $dir && $this->filesystem->isDirectory($dir)) {
         $this->files = array_merge($this->files, $this->filesystem->glob(file_build_path($dir, '*.html')));
     }
     $file = $this->option('file') ? realpath($this->option('file')) : false;
     if (false !== $file && ends_with($file, '.html') && $this->filesystem->isFile($file)) {
         $this->files[] = $file;
     }
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $paths = ServiceProvider::pathsToPublish($this->option('provider'), $this->option('tag'));
     foreach ($paths as $from => $to) {
         if ($this->files->isFile($from)) {
             $this->publishFile($from, $to);
         } elseif ($this->files->isDirectory($from)) {
             $this->publishDirectory($from, $to);
         }
     }
     $this->info('Publishing Complete!');
 }
Example #7
0
 /**
  * Scans a directory
  *
  * @param string $path
  * @return SourceIterator
  */
 public function scan($path)
 {
     if ($this->fs->isDirectory($path)) {
         $iterator = $this->getSourceIterator($path, self::SOURCE_FILE_EXTENSION);
     } elseif ($this->fs->isFile($path)) {
         $filename = $this->getFilePattern($path);
         $path = dirname($path);
         $iterator = $this->getSourceIterator($path, $filename);
     } else {
         throw new RuntimeException(sprintf('Path not found: %s', $path));
     }
     return new SourceIterator($iterator, new Reader($this->fs));
 }
Example #8
0
 /**
  * Fire the install script.
  *
  * @param Command $command
  *
  * @throws Exception
  *
  * @return mixed
  */
 public function fire(Command $command)
 {
     if (!$this->finder->isFile('.env')) {
         throw new Exception('SocietyCMS is not installed. Please run "php artisan society:install" first.');
     }
     if ($command->option('refresh') && !App::environment('demo')) {
         throw new Exception('Refresh option is only available in demo mode.');
     }
     if (!$command->option('force') && !$command->option('refresh')) {
         if (!$command->confirm('Are you sure you want to start Demo Mode?')) {
             throw new Exception('Demo Mode cancelled');
         }
     }
 }
 /**
  * @return string
  *
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function getEnvironment()
 {
     $fileSystem = new Filesystem();
     $environment = '';
     $environmentPath = app()->getBasePath() . '/.env';
     if ($fileSystem->isFile($environmentPath)) {
         $environment = trim($fileSystem->get($environmentPath));
         $envFile = app()->getBasePath() . '/.' . $environment;
         if ($fileSystem->isFile($envFile . '.env')) {
             $dotEnv = new Dotenv(app()->getBasePath() . '/', '.' . $environment . '.env');
             $dotEnv->load();
         }
     }
     return $environment;
 }
Example #10
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 #11
0
 /**
  * Updates an existing template.
  *
  * @param  string  $dirName
  * @param  string  $fileName
  * @param  array   $content
  * @return int
  */
 public function update($dirName, $fileName, $extension, $content, $oldFileName = null, $oldExtension = null)
 {
     $this->validateDirectoryForSave($dirName, $fileName, $extension);
     $path = $this->makeFilePath($dirName, $fileName, $extension);
     /*
      * The same file is safe to rename when the case is changed
      * eg: FooBar -> foobar
      */
     $iFileChanged = $oldFileName !== null && strcasecmp($oldFileName, $fileName) !== 0 || $oldExtension !== null && strcasecmp($oldExtension, $extension) !== 0;
     if ($iFileChanged && $this->files->isFile($path)) {
         throw (new FileExistsException())->setInvalidPath($path);
     }
     /*
      * File to be renamed, as delete and recreate
      */
     $fileChanged = $oldFileName !== null && strcmp($oldFileName, $fileName) !== 0 || $oldExtension !== null && strcmp($oldExtension, $extension) !== 0;
     if ($fileChanged) {
         $this->delete($dirName, $oldFileName, $oldExtension);
     }
     try {
         return $this->files->put($path, $content);
     } catch (Exception $ex) {
         throw (new CreateFileException())->setInvalidPath($path);
     }
 }
Example #12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('sql-file');
     $filesystem = new Filesystem();
     if (!$filesystem->isFile($file)) {
         throw new FileNotFoundException("We could not find the file you wanted to send to the remote server");
     }
     $vars = $input->getArguments();
     $keyLocation = $vars['ssh-secret'];
     if (!$filesystem->isFile($keyLocation)) {
         $output->writeln(sprintf('<error>Oh NO! We couldn\'t find the private key located here: %s</error>', $keyLocation));
         $pattern = '/^~\\//i';
         if (preg_match($pattern, $keyLocation) === 1) {
             $output->writeln('<error>Maybe use the key absolute path?</error>');
         }
         $output->writeln('<error>We are going to bail and let you fix this. </error>');
         return;
     }
     $auth = ['key' => $vars['ssh-secret']];
     $output->writeln("Connecting to remote host");
     $remote = new Connection('remote', $vars['ssh-host'], $vars['ssh-user'], $auth);
     if ($remote->getGateway()) {
         $output->writeln("Connection established. Transferring file " . $file);
     }
     $fileName = $filesystem->name($file);
     $remoteFile = $fileName;
     $remote->put($file, $remoteFile);
     $output->writeln("File transfered. Importing into database");
     $mysqlCommandFormat = "mysql -u %s -p'%s' %s < %s";
     $mysqlImportCommand = sprintf($mysqlCommandFormat, $vars['db-user'], $vars['db-password'], $vars['db-name'], $remoteFile);
     $mysqlDropDbCommand = sprintf("mysql -u %s -p'%s' -e 'DROP DATABASE %s;'", $vars['db-user'], $vars['db-password'], $vars['db-name']);
     $mysqlCreateDbCommand = sprintf("mysql -u %s -p'%s' -e 'CREATE DATABASE %s;'", $vars['db-user'], $vars['db-password'], $vars['db-name']);
     $remote->run($mysqlDropDbCommand, function ($line) use($output) {
     });
     $remote->run($mysqlCreateDbCommand, function ($line) use($output) {
     });
     $remote->run($mysqlImportCommand, function ($line) use($output) {
         $output->writeln($line);
     });
     /*
      * Cleanup the remote machine
      */
     $remote->run('rm ' . $remoteFile, function ($line) {
     });
     $output->writeln("Remote Importer is ALL DONE !!!");
 }
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function createMissingView(Request $request)
 {
     $path = config('view.paths.0');
     $chunks = explode('.', $request->view);
     $file = last($chunks);
     $fileWithExtension = $file . $this->config['view_extension'];
     unset($chunks[count($chunks) - 1]);
     $fullPath = $path . '/' . implode('/', $chunks);
     $template = $this->getTemplate($file);
     if (!$this->fs->isDirectory($fullPath)) {
         $this->fs->makeDirectory($fullPath, 0755, true, true);
     }
     if (!$this->fs->isFile($fullPath . '/' . $fileWithExtension)) {
         $this->fs->put($fullPath . '/' . $fileWithExtension, $template);
     }
     return redirect()->back();
 }
Example #14
0
 /**
  * Handle the command.
  *
  * @param Filesystem $files
  */
 public function handle(Filesystem $files)
 {
     $path = $this->fieldType->getStoragePath();
     if ($path && $files->isFile($path)) {
         return $files->get($path);
     }
     return null;
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $paths = ServiceProvider::pathsToPublish($this->option('provider'), $this->option('tag'));
     if (empty($paths)) {
         return $this->comment("Nothing to publish.");
     }
     foreach ($paths as $from => $to) {
         if ($this->files->isFile($from)) {
             $this->publishFile($from, $to);
         } elseif ($this->files->isDirectory($from)) {
             $this->publishDirectory($from, $to);
         } else {
             $this->error("Can't locate path: <{$from}>");
         }
     }
     $this->info('Publishing Complete!');
 }
 /**
  * Publishes the assets for a tag.
  *
  * @param string $tag
  *
  * @return mixed
  */
 private function publishTag($tag)
 {
     $paths = ServiceProvider::pathsToPublish($this->option('provider'), $tag);
     if (empty($paths)) {
         return $this->comment("Nothing to publish for tag [{$tag}].");
     }
     foreach ($paths as $from => $to) {
         if ($this->files->isFile($from)) {
             $this->publishFile($from, $to);
         } elseif ($this->files->isDirectory($from)) {
             $this->publishDirectory($from, $to);
         } else {
             $this->error("Can't locate path: <{$from}>");
         }
     }
     $this->info("Publishing complete for tag [{$tag}]!");
 }
Example #17
0
 /**
  * Get the changelog for the given module.
  *
  * @param Module $module
  *
  * @return array
  */
 public function changelogFor(Module $module)
 {
     $path = $module->getPath() . '/CHANGELOG.md';
     if (!$this->finder->isFile($path)) {
         return [];
     }
     $parser = new \Changelog\Parser(file_get_contents($path));
     return $parser->getReleases();
 }
 public function __construct($name, $username, $keyLocation, $host, $port = 22)
 {
     $file = new Filesystem();
     if (!$file->isFile($keyLocation)) {
         throw new FileNotFoundException("Private key file doesn't exist at " . $keyLocation);
     }
     $this->keyLocation = $keyLocation;
     $this->port = $port;
     parent::__construct($name, $host, $username, $keyLocation);
 }
Example #19
0
 public static function readYaml($file)
 {
     $filesystem = new Filesystem();
     if (!$filesystem->isFile($file)) {
         throw new FileNotFoundException(sprintf("Yikes!!! Couldn't find the file %s ", $file));
     }
     $parser = new Parser();
     $yaml = $parser->parse(file_get_contents($file));
     return $yaml;
 }
Example #20
0
 /**
  * Get the changelog for the given module
  * @param Module $module
  * @return array
  */
 public function changelogFor(Module $module)
 {
     $path = $module->getPath() . '/changelog.yml';
     if (!$this->finder->isFile($path)) {
         return [];
     }
     $yamlParser = new Parser();
     $changelog = $yamlParser->parse(file_get_contents($path));
     $changelog['versions'] = $this->limitLastVersionsAmount(array_get($changelog, 'versions', []));
     return $changelog;
 }
Example #21
0
 /** @test */
 public function it_creates_empty_assets_folder()
 {
     $this->scaffold->setFiles(['assetsFolder']);
     $this->generateFrontendTheme();
     $this->assertTrue($this->finder->isDirectory($this->testThemePath . '/assets'));
     $this->assertTrue($this->finder->isDirectory($this->testThemePath . '/assets/css'));
     $this->assertTrue($this->finder->isDirectory($this->testThemePath . '/assets/js'));
     $this->assertTrue($this->finder->isDirectory($this->testThemePath . '/assets/images'));
     $this->assertTrue($this->finder->isFile($this->testThemePath . '/assets/!!.gitignore'));
     $this->assertTrue($this->finder->isFile($this->testThemePath . '/assets/css/!!.gitignore'));
     $this->assertTrue($this->finder->isFile($this->testThemePath . '/assets/js/!!.gitignore'));
     $this->assertTrue($this->finder->isFile($this->testThemePath . '/assets/images/!!.gitignore'));
 }
 /**
  * Install files from array.
  *
  * @param $files
  */
 private function install($files)
 {
     foreach ($files as $fileSrc => $fileDst) {
         if (file_exists($fileDst) && !$this->force && !$this->confirmOverwrite(basename($fileDst))) {
             return;
         }
         if ($this->files->isFile($fileSrc)) {
             $this->publishFile($fileSrc, $fileDst);
         } elseif ($this->files->isDirectory($fileSrc)) {
             $this->publishDirectory($fileSrc, $fileDst);
         } else {
             $this->error("Can't locate path: <{$fileSrc}>");
         }
     }
 }
 /**
  * Copy files and/or directories to application.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param array $data
  *
  * @return void
  */
 protected final function copyFilesAndDirectories(array $data)
 {
     foreach ($data as $from => $to) {
         // Prepare $from and $to paths
         $from = base_path(sprintf('vendor/%s/%s/%s', $this->vendor, $this->package, $from));
         $to = base_path($to);
         // Copy files or directory to application
         if ($this->files->isFile($from)) {
             $this->publishFile($from, $to);
         } elseif ($this->files->isDirectory($from)) {
             $this->publishDirectory($from, $to);
         } else {
             $this->getCommand()->error(sprintf('Could not locate path: <%s>', $from));
         }
     }
 }
Example #24
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     Log::info(get_class($this) . ': ' . 'Being called upon to receive an incoming e-mail');
     // Read from stdin (should be piped from cat or MDA)
     $fd = fopen("php://stdin", "r");
     $rawEmail = "";
     while (!feof($fd)) {
         $rawEmail .= fread($fd, 1024);
     }
     fclose($fd);
     $filesystem = new Filesystem();
     $datefolder = Carbon::now()->format('Ymd');
     $path = storage_path() . '/mailarchive/' . $datefolder . '/';
     $file = Uuid::generate(4) . '.eml';
     $filename = $path . $file;
     if (!$filesystem->isDirectory($path)) {
         // If a datefolder does not exist, then create it or die trying
         if (!$filesystem->makeDirectory($path)) {
             Log::error(get_class($this) . ': ' . 'Unable to create directory: ' . $path);
             $this->exception($rawEmail);
         }
         chown($path, 'abuseio');
         chgrp($path, 'abuseio');
     }
     if ($filesystem->isFile($filename)) {
         Log::error(get_class($this) . ': ' . 'File already exists: ' . $path . $filename);
         $this->exception($rawEmail);
         chown($path . $filename, 'abuseio');
         chgrp($path . $filename, 'abuseio');
     }
     if ($filesystem->put($filename, $rawEmail) === false) {
         Log::error(get_class($this) . ': ' . 'Unable to write file: ' . $filename);
         $this->exception($rawEmail);
     }
     if ($this->option('noQueue') == true) {
         // In debug mode we don't queue the job
         Log::debug(get_class($this) . ': ' . 'Queuing disabled. Directly handling message file: ' . $filename);
         $processer = new EmailProcess($filename);
         $processer->handle();
     } else {
         Log::info(get_class($this) . ': ' . 'Pushing incoming email into queue file: ' . $filename);
         $this->dispatch(new EmailProcess($filename));
     }
     Log::info(get_class($this) . ': ' . 'Successfully received the incoming e-mail');
     return true;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filesystem = new Filesystem();
     if ($filesystem->isFile(self::SETTINGS_FILE)) {
         $helper = $this->getHelper('question');
         $output->writeln(sprintf('<question>The settings file \'%s\' already exists. If you continue you will overwrite the file and loose any existing settings. Are you sure?</question>', self::SETTINGS_FILE));
         $question = new ConfirmationQuestion('(y/n)? ', FALSE);
         if (!$helper->ask($input, $output, $question)) {
             $output->writeln("<comment>Settings file was not generated. Come back soon! </comment>");
         }
     }
     $settings = ['local' => ['database' => ['username' => 'my-local-db-user', 'password' => 'my-super-secret-password', 'database' => 'database-name']], 'remote' => ['ssh' => ['host' => 'servername:portname', 'username' => 'ssh-user', 'private-key' => 'absolute-key-loacation'], 'database' => ['username' => 'my-remote-db-user', 'password' => 'my-super-secret-password', 'database' => 'remote-database-name']]];
     $dumper = new Dumper();
     $contents = $dumper->dump($settings, 6);
     file_put_contents(self::SETTINGS_FILE, $contents);
     $output->writeln('<info>New settings file written</info>');
 }
Example #26
0
 /**
  * Attempt to save response to HTML file
  *
  * @param \Illuminate\Http\Request $request
  * @param \Illuminate\Http\Response $response
  */
 public function save(Request $request, Response $response)
 {
     if (false === $this->enabled) {
         return;
     }
     if (false === $this->canSave($request, $response)) {
         return;
     }
     $fullpath = $this->getFilePath($request);
     $dir = dirname($fullpath);
     if (true === $this->filesystem->isFile($fullpath)) {
         throw new \RuntimeException('Bump. Static file exists.');
     }
     if (false === $this->filesystem->isDirectory($dir)) {
         $this->filesystem->makeDirectory($dir, 0777, true);
     }
     $this->filesystem->put($fullpath, $response->getContent());
 }
Example #27
0
 /**
  * Determine if the given path is a file.
  *
  * @param string $file
  * @return bool 
  * @static 
  */
 public static function isFile($file)
 {
     return \Illuminate\Filesystem\Filesystem::isFile($file);
 }
Example #28
0
 /** @test */
 public function it_should_not_create_thumbs_for_pdf_files()
 {
     $this->imagy->get("{$this->mediaPath}test-pdf.pdf", 'smallThumb', true);
     $this->assertFalse($this->finder->isFile(public_path() . "{$this->mediaPath}test-pdf_smallThumb.png"));
 }
    public function exportTranslations($group, $recursing = 0)
    {
        // TODO: clean up this recursion crap
        // this can come from the command line
        $ltm_translations = $this->getTranslationsTableName();
        if (!$recursing) {
            $this->clearErrors();
            $group = self::fixGroup($group);
        }
        if ($group && $group !== '*') {
            $this->getConnection()->affectingStatement("DELETE FROM {$ltm_translations} WHERE is_deleted = 1");
        } elseif (!$recursing) {
            $this->getConnection()->affectingStatement("DELETE FROM {$ltm_translations} WHERE is_deleted = 1 AND `group` = ?", [$group]);
        }
        $inDatabasePublishing = $this->inDatabasePublishing();
        if ($inDatabasePublishing < 3 && $inDatabasePublishing && ($inDatabasePublishing < 2 || !$recursing)) {
            if ($group && $group !== '*') {
                $this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET saved_value = value, status = ? WHERE (saved_value <> value || status <> ?) AND `group` = ?
SQL
, [Translation::STATUS_SAVED_CACHED, Translation::STATUS_SAVED, $group]);
                $translations = $this->translation->query()->where('status', '<>', Translation::STATUS_SAVED)->where('group', '=', $group)->get(['group', 'key', 'locale', 'saved_value']);
            } else {
                $this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET saved_value = value, status = ? WHERE (saved_value <> value || status <> ?)
SQL
, [Translation::STATUS_SAVED_CACHED, Translation::STATUS_SAVED]);
                $translations = $this->translation->query()->where('status', '<>', Translation::STATUS_SAVED)->get(['group', 'key', 'locale', 'saved_value']);
            }
            /* @var $translations Collection */
            $this->clearCache($group);
            $this->clearUsageCache(false, $group);
            $translations->each(function ($tr) {
                $this->cacheTranslation($tr->group . '.' . $tr->key, $tr->saved_value, $tr->locale);
            });
        }
        if (!$inDatabasePublishing || $inDatabasePublishing === 2 || $inDatabasePublishing === 3) {
            if (!in_array($group, $this->config(self::EXCLUDE_GROUPS_KEY))) {
                if ($group == '*') {
                    $this->exportAllTranslations(1);
                }
                if ($inDatabasePublishing !== 3) {
                    $this->clearCache($group);
                    $this->clearUsageCache(false, $group);
                }
                $tree = $this->makeTree($this->translation->where('group', $group)->whereNotNull('value')->orderby('key')->get());
                $configRewriter = new TranslationFileRewriter();
                $exportOptions = array_key_exists('export_format', $this->config()) ? TranslationFileRewriter::optionFlags($this->config('export_format')) : null;
                // Laravel 5.1
                $base_path = $this->app->basePath();
                $pathTemplateResolver = new PathTemplateResolver($this->files, $base_path, $this->config('language_dirs'), '5');
                $zipRoot = $base_path . $this->config('zip_root', mb_substr($this->app->langPath(), 0, -4));
                // Laravel 4.2
                //$base_path = base_path();
                //$pathTemplateResolver = new PathTemplateResolver($this->files, $base_path, $this->config('language_dirs'), '4');
                //$zipRoot = $base_path . $this->config('zip_root', mb_substr($this->app->make('path').'/lang', 0, -4));
                if (mb_substr($zipRoot, -1) === '/') {
                    $zipRoot = substr($zipRoot, 0, -1);
                }
                foreach ($tree as $locale => $groups) {
                    if (isset($groups[$group])) {
                        $translations = $groups[$group];
                        // use the new path mapping
                        $computedPath = $pathTemplateResolver->groupFilePath($group, $locale);
                        $path = $base_path . $computedPath;
                        if ($computedPath) {
                            $configRewriter->parseSource($this->files->exists($path) && $this->files->isFile($path) ? $this->files->get($path) : '');
                            $output = $configRewriter->formatForExport($translations, $exportOptions);
                            if ($this->zipExporting) {
                                $pathPrefix = mb_substr($path, 0, mb_strlen($zipRoot));
                                $filePathName = $pathPrefix === $zipRoot ? mb_substr($path, mb_strlen($zipRoot)) : $path;
                                //$this->makeDirPath($filePathName);
                                $this->zipExporting->addFromString($filePathName, $output);
                            } else {
                                try {
                                    $this->makeDirPath($path);
                                    if (($result = $this->files->put($path, $output)) === false) {
                                        $this->errors[] = "Failed to write to {$path}";
                                    }
                                } catch (Exception $e) {
                                    $this->errors[] = $e->getMessage();
                                }
                            }
                        }
                    }
                }
                if (!$inDatabasePublishing) {
                    $this->translation->where('group', $group)->update(array('status' => Translation::STATUS_SAVED, 'saved_value' => new Expression('value')));
                }
            }
        }
    }
Example #30
0
 /**
  * Fire the install script
  * @param  Command   $command
  * @return mixed
  * @throws Exception
  */
 public function fire(Command $command)
 {
     if ($this->finder->isFile('.env') && !$command->option('force')) {
         throw new Exception('Asgard has already been installed. You can already log into your administration.');
     }
 }