/** * Execute the console command. * * @return mixed */ public function fire() { $experiments = Experiment::active()->get(); $goals = array_unique(Goal::active()->orderBy('name')->lists('name')->toArray()); $columns = array_merge(['Experiment', 'Visitors', 'Engagement'], array_map('ucfirst', $goals)); $writer = new Writer(new SplTempFileObject()); $writer->insertOne($columns); foreach ($experiments as $experiment) { $engagement = $experiment->visitors ? $experiment->engagement / $experiment->visitors * 100 : 0; $row = [$experiment->name, $experiment->visitors, number_format($engagement, 2) . " % (" . $experiment->engagement . ")"]; $results = $experiment->goals()->lists('count', 'name'); foreach ($goals as $column) { $count = array_get($results, $column, 0); $percentage = $experiment->visitors ? $count / $experiment->visitors * 100 : 0; $row[] = number_format($percentage, 2) . " % ({$count})"; } $writer->insertOne($row); } $output = (string) $writer; if ($file = $this->argument('file')) { $this->info("Creating {$file}"); File::put($file, $output); } else { $this->line($output); } }
/** * Execute the console command. */ public function fire() { $this->line(''); $this->info('Routes file: app/routes.php'); $message = 'This will rebuild routes.php with all of the packages that' . ' subscribe to the `toolbox.routes` event.'; $this->comment($message); $this->line(''); if ($this->confirm('Proceed with the rebuild? [Yes|no]')) { $this->line(''); $this->info('Backing up routes.php ...'); // Remove the last backup if it exists if (File::exists('app/routes.bak.php')) { File::delete('app/routes.bak.php'); } // Back up the existing file if (File::exists('app/routes.php')) { File::move('app/routes.php', 'app/routes.bak.php'); } // Generate new routes $this->info('Generating routes...'); $routes = Event::fire('toolbox.routes'); // Save new file $this->info('Saving new routes.php...'); if ($routes && !empty($routes)) { $routes = $this->getHeader() . implode("\n", $routes); File::put('app/routes.php', $routes); $this->info('Process completed!'); } else { $this->error('Nothing to save!'); } // Done! $this->line(''); } }
/** * Stores The SupervisorD configuration * * @param $worker */ private function storeSupervisordConfig($worker) { $domain = Domain::findOrFail($worker->domain_id); $file = view('configuration.supervisord', compact('worker', 'domain'))->render(); File::put(Config::get('settings.supervisord_location') . '/worker-' . $worker->id . '.log', $file); $this->log->info('Supervisord Config created'); }
/** * Execute the console command. * * @return mixed */ public function handle() { list($rootFolder, $current, $folder) = $this->setFolder(); $counter = 1; $measurementsCounter = 0; $file = fopen($folder . 'file' . $counter . '.csv', "w"); $maxRows = self::MAX_ROWS - 500; Measurement::with('station')->where('time', '>', Carbon::now()->subMonths(3))->orderBy('time', 'asc')->chunk(500, function ($measurements) use($folder, &$file, &$measurementsCounter, &$counter, $maxRows) { if ($measurementsCounter > $maxRows) { echo "measurements: " . $measurementsCounter . "\n"; echo "file created: " . $counter . ".csv\n"; $measurementsCounter = 0; if (is_resource($file)) { fclose($file); } $counter++; $file = fopen($folder . 'file' . $counter . '.csv', "w"); } foreach ($measurements as $measurement) { $array = $measurement->toArray(); unset($array['station_id'], $array['station']['id']); fputcsv($file, array_flatten($array)); } $measurementsCounter += 500; }); File::put($rootFolder . 'finished.txt', $current); }
public function setUp() { parent::setUp(); $this->testFilePath = "/tmp/laravel-static"; $this->testFileContent = "Test contents!"; File::put($this->testFilePath, $this->testFileContent); }
protected function createFile($fileName, $routeFile, $stubFile) { $stubFile = str_replace('{$NAME$}', $fileName, $stubFile); if (File::put($routeFile, $stubFile)) { $this->info('Route generated!'); } }
protected function saveFileContents($fileName, $content) { $bytesWritten = File::put($fileName, $content); if ($bytesWritten === false) { dd('Error writing file: ' . $fileName); } }
public function getSubmissionVerdict($srcContent, $srcExt) { assert($srcExt == "cpp" || $srcExt == "java" || $srcExt == "py", "'Source code language must be C++, Java or Python'"); $judgingBaseFolder = '../judging/'; $submissionFolderName = uniqid(); $submissionFolder = "{$judgingBaseFolder}{$submissionFolderName}/"; // Write the source code file $srcFpath = "{$submissionFolder}main.{$srcExt}"; File::makeDirectory($submissionFolder); File::put($srcFpath, $srcContent); // Create the required test case files $caseNo = 1; $testcases = $this->testcases()->get(); foreach ($testcases as $tc) { $inFname = "test{$caseNo}.in"; $outFname = "test{$caseNo}.ans"; $inFpath = $submissionFolder . $inFname; $outFpath = $submissionFolder . $outFname; File::put($inFpath, $tc->input); File::put($outFpath, $tc->output); $caseNo += 1; } // Judge! $judgingScript = "python \"{$judgingBaseFolder}judge.py\""; $judgingArguments = sprintf('"%s" "%s" %d', $srcFpath, $submissionFolder, $this['time_limit']); $judgeCommand = "{$judgingScript} {$judgingArguments}"; $verdict = shell_exec($judgeCommand); // Clean-up the submission directory File::deleteDirectory($submissionFolder); return $verdict; }
/** * Store a newly created resource in storage. * * @param \Codeboard\Http\Requests\SetConfigurationRequest $request * @return Response */ public function store(SetConfigurationRequest $request) { $inputData = $request->all(); $data = view('configuration.envoy', $inputData)->render(); File::put(base_path() . '/Envoy.blade.php', $data); return redirect()->route('settings'); }
public function generateAll() { $resources = APIResource::where('route', true)->get(); $namespaces = $this->generateNamespaces($resources); $commands = []; foreach ($namespaces as $namespace => $controllers) { $command = 'apidoc -i ' . app_path() . '/Http/Controllers/' . $namespace . ' '; foreach ($controllers as $controller) { $command .= '-f "' . $controller . '" '; } $command .= '-o ' . public_path() . '/docs/' . $namespace; $command .= ' -t ' . realpath(__DIR__ . '/../../templateDoc'); $commands[] = ['namespace' => $namespace, 'command' => $command, 'index' => public_path() . '/docs/' . $namespace . '/index.html']; } $return = []; $responses = []; foreach ($commands as $command) { exec($command['command'], $return, $status); if ($status != 0) { $response = ['success' => false, 'error' => 'Cannot generate documentation for namespace ' . $command['namespace'] . ' in: ' . public_path() . '/docs/' . $command['namespace']]; } else { $find = '<base href="#" />'; $replace = '<base href="/docs/' . $command['namespace'] . '/" />'; File::put($command['index'], str_replace($find, $replace, file_get_contents($command['index']))); $response = ['success' => true, 'message' => 'Documentation generated for namespace ' . $command['namespace'] . ' in: ' . public_path() . '/docs/' . $command['namespace']]; } $responses[] = $response; } return $responses; }
/** * Assert that a blade string is rendered correctly. * * @param string $render * @param string $string * @param array $data * @return $this */ protected function assertBladeRender($render, $string, $data = []) { $path = __DIR__ . "/views/test.blade.php"; File::put($path, $string); $this->assertEquals($render, view()->file($path, $data)->render()); return $this; }
public function addNewPlace(Request $request) { $this->validate($request, ['place' => 'required']); $existingPlaces = json_decode(File::get(storage_path('app/places.json')), true); $existingPlaces[] = $request->get('place'); File::put(storage_path('app/places.json'), json_encode($existingPlaces)); \Cache::forget('places'); }
public function test() { $subjects = \App\Subject::lists('name')->toJson(); $file = 'subjects.json'; $write = File::put($file, $subjects); if ($write == false) { return 'False roi em oi'; } return 'Good!'; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); $cache_filename = str_slug(str_replace('/', '-', $request->getRequestUri())) . '.js'; $cache_path = public_path() . '/js/cache'; if (!File::exists($cache_path . DIRECTORY_SEPARATOR . $cache_filename)) { File::put($cache_path . DIRECTORY_SEPARATOR . $cache_filename, $response->getContent()); } return $response; }
/** * Check for cache path, and create if missing */ protected function makeStorageSerializerDir() { $purifierCachePath = Config::get('purifier::config.cachePath'); if (File::exists($purifierCachePath) === false) { File::makeDirectory($purifierCachePath); $gitIgnoreContent = '*'; $gitIgnoreContent .= "\n" . '!.gitignore'; File::put($purifierCachePath . '/.gitignore', $gitIgnoreContent); } }
public function fire(ParseFeed $parseFeed) { $this->parse_feed = $parseFeed; try { File::put($this->parse_feed->getDto()->callback_url . '/' . $this->parse_feed->getDto()->request_uuid . '.out', $this->parse_feed->getSerializedResults()); } catch (\Exception $e) { $this->parse_feed->getDto()->process_results[] = sprintf("error writing file %s", $e->getMessage()); } return $this->parse_feed->getDto(); }
public function outputOverview() { $xml = new DomDocument(); $xml->load($this->outputDir . '/logs/phpcs.xml'); $xsl = new DomDocument(); $xsl->load(public_path('packages/ngmy/stand-ci/xsl/phpcs_overview.xsl')); $processor = new XSLTProcessor(); $processor->importStyleSheet($xsl); File::put($this->outputDir . '/phpcs_overview.html', $processor->transformToXML($xml)); }
private function create_scss() { $src = $this->zip_path . '/css/' . $this->fontname . '.css'; $dst = $this->resources_path . 'sass/' . $this->fontname . '/components/'; $cssfile = $this->embed() . $this->stripfontsrc(File::get($src)); if (!File::exists($dst)) { File::makeDirectory($dst, 0755, true); } File::put($dst . 'fontello.scss', $cssfile); $this->info("saved: {$dst}fontello.scss."); }
/** * Execute the console command. * * @return mixed */ public function handle() { $name = $this->argument('name'); switch ($this->option('type')) { case "external": File::put('app/API/Transformers/' . ucfirst($name) . 'Transformer.php', "<?php \n \n namespace app\\API\\Transformers; \n\n class " . ucfirst($name) . "Transformer extends Transformer\n { \n \n \t public function transform(\$item){ } \n \n \t public function columns(){ } \n \n }"); break; default: File::put('packages/Sparkplug/Admin/src/API/Transformers/' . ucfirst($name) . 'Transformer.php', "<?php \n \n namespace Sparkplug\\Admin\\API\\Transformers; \n\n class " . ucfirst($name) . "Transformer extends Transformer\n { \n \n \t public function transform(\$item){ } \n \n \t public function columns(){ } \n \n }"); } }
/** * Store the compiled stub. * * @param $modelName * @param \stdClass $scaffolderConfig * @param $compiled * @param \Scaffolder\Support\FileToCompile $fileToCompile * * @return string */ protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile) { $path = PathParser::parse($scaffolderConfig->paths->migrations) . $this->date->format('Y_m_d_His') . '_create_' . strtolower($modelName) . 's_table.php'; // Store in cache if ($fileToCompile->cached) { File::copy(base_path('scaffolder-config/cache/migration_' . $fileToCompile->hash . self::CACHE_EXT), $path); } else { File::put(base_path('scaffolder-config/cache/migration_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); File::copy(base_path('scaffolder-config/cache/migration_' . $fileToCompile->hash . self::CACHE_EXT), $path); } return $path; }
public function downloadCsv($database) { $this->isLoggedIn(); $this->isSupportedDatabase($database); $response = $this->curlClient->get($this->downloadPagePath, ['query' => ['code' => $database], 'timeout' => 30, 'cookies' => $this->cookieJar]); //write file to downloads $databaseFile = $this->storagePath . '/downloads/' . $database . '.csv.zip'; if (File::exists($databaseFile) === true) { unlink($databaseFile); } File::put($databaseFile, $response->getBody()); }
/** * Store the compiled stub. * * @param $modelName * @param $scaffolderConfig * @param $compiled * @param FileToCompile $fileToCompile * * @return string */ protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) { $path = PathParser::parse($scaffolderConfig->paths->views) . strtolower($modelName) . '/create.blade.php'; // Store in cache if ($fileToCompile->cached) { File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); } else { File::put(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); } return $path; }
/** * Store the compiled stub. * * @param $modelName * @param \stdClass $scaffolderConfig * @param $compiled * @param \Scaffolder\Support\FileToCompile $fileToCompile * * @return string */ protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile) { $path = base_path('../' . strtolower(str_replace(' ', '-', $scaffolderConfig->name . '-api'))) . '/app/Models/' . $modelName . '.php'; // Store in cache if ($fileToCompile->cached) { File::copy(base_path('scaffolder-config/cache/api_model_' . $fileToCompile->hash . self::CACHE_EXT), $path); } else { File::put(base_path('scaffolder-config/cache/api_model_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); File::copy(base_path('scaffolder-config/cache/api_model_' . $fileToCompile->hash . self::CACHE_EXT), $path); } return $path; }
/** * Store the compiled stub. * * @param $modelName * @param $scaffolderConfig * @param $compiled * @param FileToCompile $fileToCompile * * @return string */ protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) { $path = PathParser::parse($scaffolderConfig->paths->models) . $modelName . '.php'; // Store in cache if ($fileToCompile->cached) { File::copy(base_path('scaffolder-config/cache/model_' . $fileToCompile->hash . self::CACHE_EXT), $path); } else { File::put(base_path('scaffolder-config/cache/model_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); File::copy(base_path('scaffolder-config/cache/model_' . $fileToCompile->hash . self::CACHE_EXT), $path); } return $path; }
private function setupTestCase($setupCommand) { $contents = file_get_contents(base_path() . '/tests/TestCase.php'); $pos = strrpos($contents, "refreshDb"); if ($pos === false) { $location = strripos($contents, "}"); $contents = substr_replace($contents, $this->seedStep(), $location, 1); File::put(base_path() . '/tests/TestCase.php', $contents); $setupCommand->info("Added Seed Step to the TestCase class"); } else { $setupCommand->info("Seed step already in TestCase"); } }
function fire($payload) { try { if (File::exists(storage_path('logs/lumen.log'))) { File::put(storage_path('logs/lumen.log'), ''); } $handler = new \App\ThumbMakerService(); $handler->handle($payload); echo file_get_contents(storage_path('logs/lumen.log')); } catch (\Exception $e) { $message = sprintf("Error with worker %s", $e->getMessage()); echo $message; } }
private function createModule() { foreach ($this->moduleFiles as $module) { $folder = base_path() . $this->vendorPath . $module['folder']; if (!File::exists($folder)) { File::makeDirectory($folder, 0775, true); } if (File::exists($folder)) { $fileName = str_replace('Name', $this->properCaseName, $module['file']); $fileName = str_replace('.txt', '.php', $fileName); File::put($folder . '/' . $fileName, $module['content']); } } $this->info('Files created!'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $response = $next($request); // HTML cache if (!$response->isRedirection() && $request->isMethod('get') && !Auth::check() && !config('app.debug') && config('typicms.html_cache')) { if ($this->hasPageThatShouldNotBeCached($response)) { return $response; } $directory = public_path() . '/html' . $request->getPathInfo(); if (!File::isDirectory($directory)) { File::makeDirectory($directory, 0777, true); } File::put($directory . '/index' . ($request->getQueryString() ? md5($request->getQueryString()) : '') . '.html', $response->content()); } return $response; }
/** * Execute the console command. * * @return void */ public function fire() { $patch = PHP_EOL . "require __DIR__.'/../vendor/onefasteuro/flattnr/src/Onefasteuro/Flattnr/Flatten.php';"; $patch .= PHP_EOL . "Onefasteuro\\Flattnr\\Flatten::hijack();" . PHP_EOL; $base_dir = app_path() . '/../'; if ($this->confirm("\nThis will bootstrap Flattnr to run before L4 runs [yes|no]")) { $file = File::get($base_dir . 'bootstrap/autoload.php'); $pos = strpos($file, "<?php"); if ($pos === false) { $this->line("\nYour boostrap file does not seem to be formatted properly."); return; } $file = str_replace('<?php', '<?php' . PHP_EOL . $patch . PHP_EOL, $file); File::put($base_dir . 'bootstrap/autoload.php', $file); $this->line("\nFile bootstrapped successfully."); } }
/** * Writes a value to package configuration file. */ protected function writeConfig($key, $value) { $file = config_path(LadaCacheServiceProvider::CONFIG_FILE); if (!File::exists($file)) { $this->call('vendor:publish'); } try { $contents = File::get($file); $contents = preg_replace("/'" . $key . "'(.*?),\\s?\n/s", "'" . $key . "' => " . $value . ",\n\n", $contents); File::put($file, $contents); } catch (Exception $e) { $this->error('Could not write config file'); return false; } $this->call('config:clear'); return true; }