/** * Write a file * * @param string $path The directory to put the file in (in the current destination) * @param string $content The file content * @param string $filename The file name * @param string $extension The file extension */ public function write($path, $content, $extension = 'html', $filename = 'index') { $directory = sprintf('%s/%s', $this->destination, trim($path, '/')); $file = sprintf('%s.%s', $filename, $extension); if (!$this->files->exists($directory)) { $this->files->mkdir($directory); } $this->files->dumpFile(sprintf('%s/%s', $directory, $file), $content); }
/** * Highlight a portion of code with pygmentize * * @param string $value * @param string $language * * @return string */ public function highlight($value, $language) { $path = tempnam($this->tmp, 'pyg'); if ($language === 'php' && substr($value, 0, 5) !== '<?php') { $value = '<?php ' . PHP_EOL . $value; } $this->files->dumpFile($path, $value); $value = $this->pygmentize($path, $language); unlink($path); if (preg_match('#^<div class="highlight"><pre>#', $value) && preg_match('#</pre></div>$#', $value)) { return substr($value, 28, strlen($value) - 40); } return $value; }
public function testCleanUp() { $fs = new FileSystem(); $fs->dumpFile($this->tmpDir . '/dummy-file', 'Dummy content.'); $dw = new FilesystemDataWriter(new Filesystem(), $this->tmpDir); $dw->setUp(); $this->assertFileNotExists($this->tmpDir . '/dummy-file'); }
public function save() { $items = array(); foreach ($this->instances as $key => $instance) { $items[$key] = $this->encodeItem($instance); } $this->fs->dumpFile($this->getFile(), $this->encodeDocument($items), $this->getFileMode()); }
protected function setSystemCrontab(OutputInterface $output, $newContents) { $tempCronFileName = '/tmp/madrak_io_easy_cron_deployment.cron.' . time(); $filesystem = new FileSystem(); $filesystem->dumpFile($tempCronFileName, $newContents); $process = new Process('crontab ' . $tempCronFileName); try { $process->mustRun(); return $process->getOutput(); } catch (ProcessFailedException $e) { $this->outputFormattedBlock($output, ['Error!', 'There was an error while attempting to overwrite the existing crontab list.', $e->getMessage()], 'error'); exit; } }
/** * @param FormMetadata $formMetadata * @return string */ public function generate(FormMetadata $formMetadata) { $formMetadata->setCode($this->view->render('templates/class.php.twig', ['form' => $formMetadata])); $this->fileSystem->mkdir($formMetadata->classDirectory()); $this->fileSystem->dumpFile($formMetadata->classFilename(), $formMetadata->code()); }
/** * Writes a local drush alias file. */ public function writeDrushAlias() { $drush_alias_file_path = "{$_SERVER['HOME']}/.drush/{$this->app->name}.aliases.drushrc.php"; $drush_alias_file = array(); $drush_alias_file[] = '<?php'; foreach ($this->app->environments as $environment_name => $environment) { $factory = new self($environment, $this->app); $path = "/source/" . $environment['document_root']; $drush_alias_file[] = '// DO NOT EDIT. This is generated by Terra. Any changes will be overridden when the environment is re-enabled.'; $drush_alias_file[] = "\$aliases['{$environment_name}'] = array("; $drush_alias_file[] = " 'uri' => '{$factory->getHost()}:{$factory->getPort()}',"; $drush_alias_file[] = " 'root' => '{$path}',"; $drush_alias_file[] = " 'remote-host' => '{$factory->getHost()}',"; $drush_alias_file[] = " 'remote-user' => 'root',"; $drush_alias_file[] = " 'ssh-options' => '-p {$factory->getDrushPort()}',"; $drush_alias_file[] = ');'; } $fs = new FileSystem(); try { $fs->dumpFile($drush_alias_file_path, implode("\n", $drush_alias_file)); return true; } catch (IOException $e) { return false; } }
/** * Write the docker-compose.yml file. * @return bool */ public function writeConfig() { // Create the app/environment folder $fs = new FileSystem(); try { $fs->mkdir($this->getDockerComposePath()); } catch (IOExceptionInterface $e) { return FALSE; } // Create the environments docker-compose file. $dumper = new Dumper(); try { $fs->remove($this->getDockerComposePath() . '/docker-compose.yml'); $fs->dumpFile($this->getDockerComposePath() . '/docker-compose.yml', $dumper->dump($this->getDockerComposeArray(), 10)); return TRUE; } catch (IOExceptionInterface $e) { return FALSE; } }
public function save() { $this->load(); $this->fs->dumpFile($this->getFile(), Yaml::dump($this->data), $this->getFileMode()); }
/** * Install Behat yaml files. * * @codeCoverageIgnore */ protected function writeBehatYamlFiles() { $filesystem = new FileSystem(); try { $filesystem->dumpFile($this->settings->getBaseDir() . '/behat.yml', $this->twig->render('behat.yml.dist', $this->settings->getArrayCopy())); $filesystem->dumpFile($this->settings->getBaseDir() . '/behat.dev.yml', $this->twig->render('behat.dev.yml.dist', $this->settings->getArrayCopy())); } catch (IOException $e) { $this->output->writeln(sprintf('<error>Could not write behat config file, error: "%s"</error>', $e->getMessage())); return; } $this->output->writeln('Behat configuration files are written'); }