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); }
public function fakeUser() { $this->login(); $batch = Input::get('batch', 0); if (!$batch) { echo "need batch number"; die; } $mobile = DB::table('users')->select('u_mobile')->where('u_mobile', '<', '11000000000')->orderBy('u_mobile', 'DESC')->first(); if (empty($mobile->u_mobile)) { $mobile = 10000000000; } else { $mobile = $mobile->u_mobile; } echo "mobile start at " . $mobile . "</br>"; echo "batch number is " . $batch . "</br>"; set_time_limit(0); $file = new Filesystem(); $re = $file->files('/var/www/qingnianchuangke/head_img'); foreach ($re as $key => $path) { $user = new User(); $user->u_mobile = ++$mobile; $user->u_name = $user->u_nickname = $file->name($path); $ext = $file->extension($path); echo "add:" . $user->u_name . "</br>"; $user->u_head_img = 'http://qnck001.oss-cn-hangzhou.aliyuncs.com/user_head/' . $batch . '/' . ($key + 1) . '.' . $ext; $user->fakeUser(); } echo 'done'; }
/** * Edit a file. * @param string $path Path to the file. * @param string $search What to replace. * @param string $replace Text to replace with. * @return $this|Exception */ public function edit($path) { $this->path = realpath(base_path($this->files->dirname($path))); $this->class = $this->files->name($path); $this->setFile($path); return $this; }
public function getLocales() { if (empty($this->locales)) { $locales = array_merge([config('app.locale')], Translation::groupBy('locale')->lists('locale')); foreach ($this->files->directories($this->app->langPath()) as $localeDir) { $locales[] = $this->files->name($localeDir); } $this->locales = array_unique($locales); sort($this->locales); } return array_diff($this->locales, $this->ignoreLocales); }
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)); } } }
/** * 解析檔案. * * @return array * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ protected function parse() { foreach ($this->files as $file) { $content = $this->removeAnnoys($this->filesystem->get($file)); $rows = HtmlDomParser::str_get_html($content)->find('tr'); // 系所代碼 $department = $this->filesystem->name($file); // 需先移除表格標題列 foreach (array_slice($rows, 1) as $row) { $courses[$department][] = $this->getColumns($row, $department); } if (isset($courses[$department])) { $this->numberOfCourses += count($courses[$department]); } } return $courses ?? []; }
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 !!!"); }
/** * Extract the file name from a file path. * * @param string $path * @return string * @static */ public static function name($path) { return \Illuminate\Filesystem\Filesystem::name($path); }
/** * set new Config value by given key and value. * And save the file. * * @param $key * @param $value * * @return int */ protected function setConfigValue($key, $value) { $fs = new Filesystem(); $fn = $fs->name($key); // First string until dot should be the file name. $filename = strstr($fn, '.', true); if (strpos($filename, '.') !== false) { $filename = $fn; } $this->items->set($key, $value); return $fs->put($this->getConfigDir() . DIRECTORY_SEPARATOR . $filename . '.php', '<?php return ' . var_export($this->items[$fn], true) . ';'); }