作者:mlant
项目:homeforg
protected function execute(InputInterface $input, OutputInterface $output)
{
$result = '';
$time_start = microtime(true);
$dbname = $input->getArgument('name');
$yaml = new Parser();
$homesteadFile = $yaml->parse(file_get_contents(getenv("HOME") . '/.homestead/Homestead.yaml'));
foreach ($homesteadFile['databases'] as $key => $db) {
if ($db === $dbname) {
unset($homesteadFile['databases'][$key]);
}
}
$dumper = new Dumper();
$yaml = $dumper->dump($homesteadFile, 2);
file_put_contents(getenv("HOME") . '/.homestead/Homestead.yaml', $yaml);
$output->writeln("\nCurrent Databases:");
foreach ($homesteadFile['databases'] as $db) {
$output->writeln("\n<comment>" . $db . "</comment>");
}
$output->writeln('halting homestead...');
exec('cd ~/Homestead && vagrant halt', $result);
$output->writeln('restarting homestead...');
exec('cd ~/Homestead && vagrant up --provision', $result);
$time_end = microtime(true);
$time = $time_end - $time_start;
$output->writeln("\nCompleted in: " . $time . " seconds");
}
作者:chamil
项目:chas
/**
* Executes a command via CLI
*
* @param Console\Input\InputInterface $input
* @param Console\Output\OutputInterface $output
*
* @return int|null|void
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$tempFolder = $input->getOption('temp-folder');
$fs = new Filesystem();
$version = $input->getArgument('version');
$chamiloRoot = $input->getArgument('chamilo_root');
if ($version == '111') {
$file = $chamiloRoot . 'app/config/migrations.yml';
require_once $chamiloRoot . 'app/Migrations/AbstractMigrationChamilo.php';
$this->migrationFile = $file;
return 1;
}
if ($version == '110') {
$file = $chamiloRoot . 'app/config/migrations110.yml';
$this->migrationFile = $file;
return 1;
}
require_once $chamiloRoot . 'app/Migrations/AbstractMigrationChamilo.php';
$migrationsFolder = $tempFolder . '/Migrations/';
if (!$fs->exists($migrationsFolder)) {
$fs->mkdir($migrationsFolder);
}
$migrations = array('name' => 'Chamilo Migrations', 'migrations_namespace' => 'Application\\Migrations\\Schema\\V111', 'table_name' => 'version', 'migrations_directory' => $migrationsFolder);
$dumper = new Dumper();
$yaml = $dumper->dump($migrations, 1);
$file = $migrationsFolder . 'migrations.yml';
file_put_contents($file, $yaml);
$migrationPathSource = __DIR__ . '/../../../Chash/Migrations/';
$fs->mirror($migrationPathSource, $migrationsFolder);
// migrations_directory
$output->writeln("<comment>Chash migrations.yml saved: {$file}</comment>");
$this->migrationFile = $file;
}
作者:jkyt
项目:agol
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['title'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Index title attribute'),
'#description' => $this->t('If set, the contents of title attributes will be indexed.'),
'#default_value' => $this->configuration['title'],
);
$form['alt'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Index alt attribute'),
'#description' => $this->t('If set, the alternative text of images will be indexed.'),
'#default_value' => $this->configuration['alt'],
);
$dumper = new Dumper();
$tags = $dumper->dump($this->configuration['tags'], 2);
$tags = str_replace('\r\n', "\n", $tags);
$tags = str_replace('"', '', $tags);
$t_args['@url'] = Url::fromUri('https://en.wikipedia.org/wiki/YAML')->toString();
$form['tags'] = array(
'#type' => 'textarea',
'#title' => $this->t('Tag boosts'),
'#description' => $this->t('Specify special boost values for certain HTML elements, in <a href="@url">YAML file format</a>. The boost values of nested elements are multiplied, elements not mentioned will have the default boost value of 1. Assign a boost of 0 to ignore the text content of that HTML element.', $t_args),
'#default_value' => $tags,
);
return $form;
}
作者:blasoliv
项目:DrupalConsol
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$yaml = new Parser();
$dumper = new Dumper();
$yaml_file = $input->getArgument('yaml-file');
$yaml_key = $input->getArgument('yaml-key');
$yaml_new_key = $input->getArgument('yaml-new-key');
try {
$yaml_parsed = $yaml->parse(file_get_contents($yaml_file));
} catch (\Exception $e) {
$io->error($this->trans('commands.yaml.merge.messages.error-parsing') . ': ' . $e->getMessage());
return;
}
if (empty($yaml_parsed)) {
$io->info(sprintf($this->trans('commands.yaml.merge.messages.wrong-parse'), $yaml_file));
}
$nested_array = $this->getNestedArrayHelper();
$parents = explode(".", $yaml_key);
$nested_array->replaceKey($yaml_parsed, $parents, $yaml_new_key);
try {
$yaml = $dumper->dump($yaml_parsed, 10);
} catch (\Exception $e) {
$io->error($this->trans('commands.yaml.merge.messages.error-generating') . ': ' . $e->getMessage());
return;
}
try {
file_put_contents($yaml_file, $yaml);
} catch (\Exception $e) {
$io->error($this->trans('commands.yaml.merge.messages.error-writing') . ': ' . $e->getMessage());
return;
}
$io->info(sprintf($this->trans('commands.yaml.update.value.messages.updated'), $yaml_file));
}
作者:jamescaldwel
项目:TestScrib
/**
* @param \Box\TestScribe\InputHistory\InputHistoryData $historyData
*
* @return string
*/
private function convertToYamlString(InputHistoryData $historyData)
{
$dumper = new Dumper();
$data = $historyData->getData();
$dataInYaml = $dumper->dump($data, 2);
return $dataInYaml;
}
作者:legovae
项目:DrupalConsol
protected function execute(InputInterface $input, OutputInterface $output)
{
$yaml = new Parser();
$dumper = new Dumper();
$yaml_file = $input->getArgument('yaml-file');
$yaml_key = $input->getArgument('yaml-key');
$yaml_value = $input->getArgument('yaml-value');
try {
$yaml_parsed = $yaml->parse(file_get_contents($yaml_file));
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $this->trans('commands.yaml.merge.messages.error-parsing') . ': ' . $e->getMessage() . '</error>');
return;
}
if (empty($yaml_parsed)) {
$output->writeln('[+] <info>' . sprintf($this->trans('commands.yaml.merge.messages.wrong-parse'), $yaml_file) . '</info>');
}
$nested_array = $this->getNestedArrayHelper();
$parents = explode(".", $yaml_key);
$nested_array->setValue($yaml_parsed, $parents, $yaml_value, true);
try {
$yaml = $dumper->dump($yaml_parsed, 10);
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $this->trans('commands.yaml.merge.messages.error-generating') . ': ' . $e->getMessage() . '</error>');
return;
}
try {
file_put_contents($yaml_file, $yaml);
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $this->trans('commands.yaml.merge.messages.error-writing') . ': ' . $e->getMessage() . '</error>');
return;
}
$output->writeln('[+] <info>' . sprintf($this->trans('commands.yaml.update.value.messages.updated'), $yaml_file) . '</info>');
}
作者:datasif
项目:storyplaye
public function writeDataToFile($params)
{
// shorthand
$filename = $this->args[0];
// what are we doing?
$printer = new DataPrinter();
$logParams = $printer->convertToString($params);
$log = usingLog()->startAction("create YAML file '{$filename}' with contents '{$logParams}'");
// create an instance of the Symfony YAML writer
$writer = new Dumper();
// create the YAML data
$yamlData = $writer->dump($params, 2);
if (!is_string($yamlData) || strlen($yamlData) < 6) {
throw new E5xx_ActionFailed(__METHOD__, "unable to convert data to YAML");
}
// prepend the YAML marker
$yamlData = '---' . PHP_EOL . $yamlData;
// write the file
//
// the loose FALSE test here is exactly what we want, because we want to catch
// both the situation when the write fails, and when there's zero bytes written
if (!file_put_contents($filename, $yamlData)) {
throw new E5xx_ActionFailed(__METHOD__, "unable to write file '{$filename}'");
}
// all done
$log->endAction();
}
作者:GoZO
项目:DrupalConsol
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$message = $this->getMessageHelper();
$application = $this->getApplication();
$sitesDirectory = $application->getConfig()->getSitesDirectory();
if (!is_dir($sitesDirectory)) {
$message->addErrorMessage(sprintf($this->trans('commands.site.debug.messages.directory-not-found'), $sitesDirectory));
return;
}
// Get the target argument
$target = $input->getArgument('target');
if ($target && $application->getConfig()->loadTarget($target)) {
$targetConfig = $application->getConfig()->getTarget($target);
$dumper = new Dumper();
$yaml = $dumper->dump($targetConfig, 5);
$output->writeln($yaml);
return;
}
$finder = new Finder();
$finder->in($sitesDirectory);
$finder->name("*.yml");
$table = new Table($output);
$table->setHeaders([$this->trans('commands.site.debug.messages.site'), $this->trans('commands.site.debug.messages.host'), $this->trans('commands.site.debug.messages.root')]);
foreach ($finder as $site) {
$siteConfiguration = $site->getBasename('.yml');
$application->getConfig()->loadSite($siteConfiguration);
$environments = $application->getConfig()->get('sites.' . $siteConfiguration);
foreach ($environments as $env => $config) {
$table->addRow([$siteConfiguration . '.' . $env, array_key_exists('host', $config) ? $config['host'] : 'local', array_key_exists('root', $config) ? $config['root'] : '']);
}
}
$table->render();
}
作者:rcuvg
项目:Build-API.
protected function respondWithArray(array $array, array $headers = [])
{
$mimeTypeRaw = Input::server('HTTP_ACCEPT', '*/*');
// If its empty or has */* then default to JSON
if ($mimeTypeRaw === '*/*') {
$mimeType = 'application/json';
} else {
// You'll probably want to do something intelligent with charset if provided
// This chapter just assumes UTF8 everything everywhere
$mimeParts = (array) explode(';', $mimeTypeRaw);
$mimeType = strtolower($mimeParts[0]);
}
switch ($mimeType) {
case 'application/json':
$contentType = 'application/json';
$content = json_encode($array);
break;
case 'application/x-yaml':
$contentType = 'application/x-yaml';
$dumper = new YamlDumper();
$content = $dumper->dump($array, 2);
break;
default:
$contentType = 'application/json';
$content = json_encode(['error' => ['code' => static::CODE_INVALID_MIME_TYPE, 'http_code' => 415, 'message' => sprintf('Content of type %s is not supported.', $mimeType)]]);
}
$response = Response::make($content, $this->statusCode, $headers);
$response->header('Content-Type', $contentType);
return $response;
}
作者:valou
项目:database-installe
/**
*/
public function update()
{
echo 'Update Migrations: ';
$dirIterator = new DirectoryIterator($this->dbFilesDir);
$files = [];
$installed = [];
$i = 0;
foreach ($dirIterator as $dir) {
$file = $dir->getFilename();
if ($file == '.' || $file == '..' || !preg_match('/\\.sql$/', $file)) {
continue;
}
if (in_array($file, $this->successMigration)) {
$installed[] = $file;
continue;
}
$files[$i]['path'] = $dir->getPathname();
$files[$i]['name'] = $file;
$i++;
}
usort($files, function ($val1, $val2) {
return strcmp($val1['name'], $val2['name']);
});
foreach ($files as $file) {
if ($this->install($file['path'])) {
$installed[] = $file['name'];
echo PHP_EOL . $file['name'] . ': Success';
} else {
echo PHP_EOL . $file['name'] . ': Fail';
break;
}
}
$dumper = new Dumper();
file_put_contents($this->ymlFilePath, $dumper->dump($installed));
}
作者:TobeyYan
项目:TranslationEditorBundl
public function export($filename)
{
$fname = basename($filename);
$this->output->writeln("Exporting to <info>" . $filename . "</info>...");
list($name, $locale, $type) = explode('.', $fname);
switch ($type) {
case 'yml':
$data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename' => $filename));
if (!$data) {
$this->output->writeln("Could not find data for this locale");
return;
}
foreach ($data['entries'] as $key => $val) {
if (empty($val)) {
unset($data['entries'][$key]);
}
}
$dumper = new Dumper();
$result = $dumper->dump($data['entries'], 1);
$this->output->writeln(" Writing " . count($data['entries']) . " entries to {$filename}");
if (!$this->input->getOption('dry-run')) {
file_put_contents($filename, $result);
}
break;
case 'xliff':
$this->output->writeln(" Skipping, not implemented");
break;
}
}
作者:lyrasof
项目:lyrasoft.github.i
/**
* export
*
* @param bool $ignoreTrack
* @param bool $prefixOnly
* @param bool $text
*
* @return mixed|string
*/
public function export($ignoreTrack = false, $prefixOnly = false, $text = true)
{
$tableObject = new Table();
$trackObject = new Track();
$tables = $prefixOnly ? $tableObject->listSite() : $tableObject->listAll();
$track = $trackObject->getTrackList();
$result = array();
$this->tableCount = 0;
$this->rowCount = 0;
foreach ($tables as $table) {
$trackStatus = $track->get('table.' . $table, 'none');
if ($trackStatus == 'none' && !$ignoreTrack) {
continue;
}
$result[$table] = $this->getCreateTable($table);
$this->tableCount++;
if ($trackStatus == 'all' || $ignoreTrack) {
$insert = $this->getInserts($table);
if ($insert) {
$result[$table] = array_merge($result[$table], $insert);
}
}
}
$this->state->set('dump.count.tables', $this->tableCount);
$this->state->set('dump.count.rows', $this->rowCount);
$dumper = new Dumper();
$result = json_decode(json_encode($result), true);
return $text ? $dumper->dump($result, 3, 0, false, true) : $result;
}
作者:WeCodePixel
项目:remiii-symfony2-and-google-translat
protected function execute(InputInterface $input, OutputInterface $output)
{
$languages = explode(",", $input->getArgument('languages'));
$finder = new Finder();
$finder->files()->in(__DIR__ . "/../../datas/");
$output_path = __DIR__ . "/../../output/";
$datas_path = __DIR__ . "/../../datas/";
$key = $input->getArgument('base_language');
copy($datas_path . "messages.{$key}.yml", $output_path . "messages.{$key}.yml");
$input = $datas_path . "messages.{$key}.yml";
foreach ($languages as $lang) {
$lang = trim($lang);
$output = $output_path . "messages.{$lang}.yml";
$origin = $datas_path . "messages.{$lang}.yml";
$translator = new Translator($key, $input, $output);
$translator->setLang($lang);
$yaml = Yaml::parse($input);
$dumper = new Dumper();
$copy_yaml = Yaml::parse($origin);
if (is_array($copy_yaml)) {
$translator->readAndTranslate($yaml, '', $copy_yaml);
file_put_contents($output, $dumper->dump($copy_yaml, 2));
} else {
$copy_yaml = $yaml;
$test = Translator::eraseValues($copy_yaml);
$translator->readAndTranslate($yaml, '', $test);
file_put_contents($output, $dumper->dump($test, 2));
}
}
}
作者:jamescaldwel
项目:TestScrib
/**
* @param mixed $value
*
* @return string
*/
public function dumpToString($value)
{
$dumper = new Dumper();
$dumper->setIndentation(2);
$yamlString = $dumper->dump($value, 15);
return $yamlString;
}
作者:gitdown-wik
项目:gitdown-wik
/**
* @Route("/new", name="wiki_create")
* @Method("POST")
*/
public function createAction(Request $request)
{
$name = $request->request->get('name');
$user = $this->getUser();
$slug = $request->request->get('slug');
if (empty($slug)) {
$slug = $this->get('slug')->slugify($name);
}
$repositoryService = $this->get('app.repository');
$repository = $repositoryService->createRepository($slug);
$adminRepository = $repositoryService->getRepository($this->getParameter('app.admin_repository'));
$path = $repository->getWorkingDir();
$fs = new Filesystem();
$fs->dumpFile($path . '/index.md', '# ' . $name);
$repository->setDescription($name);
$repository->run('add', array('-A'));
$repository->run('commit', array('-m Initial commit', '--author="' . $user->getName() . ' <' . $user->getEmail() . '>"'));
$username = $user->getUsername();
$adminPath = $adminRepository->getWorkingDir();
$yamlDumper = new Dumper();
$yamlString = $yamlDumper->dump(array('groups' => null, 'owners' => array($username), 'users' => array($username => 'RW+')), 3);
$fs->dumpFile($adminPath . '/wikis/' . $slug . '.yml', $yamlString);
$adminMessage = sprintf('Added wiki %s', $slug);
$adminRepository->run('add', array('-A'));
$adminRepository->run('commit', array('-m ' . $adminMessage, '--author="' . $user->getName() . ' <' . $user->getEmail() . '>"'));
return $this->redirectToRoute('page_show', array('slug' => $slug));
}
作者:renegar
项目:depip
public function testLaunchInstances()
{
$mockImageId = 'ami-123456';
$instanceConfig = ['AnotherConfig' => '12324'];
$userDataConfig = ['runcmd' => '...'];
$image = $this->getMockBuilder('App\\Platform\\Aws\\Image')->disableOriginalConstructor()->getMock();
$image->expects($this->any())->method('getId')->will($this->returnCallback(function () use($mockImageId) {
return $mockImageId;
}));
$mockEc2Client = $this->getMockEc2Client(['runInstances', 'waitUntilInstanceRunning', 'describeInstances']);
$mockEc2Client->expects($this->once())->method('runInstances')->will($this->returnCallback(function ($config) use($mockImageId, $instanceConfig, $userDataConfig) {
$yamlDumper = new Dumper();
$this->assertEquals(['ImageId' => $mockImageId, 'MinCount' => 1, 'MaxCount' => 1, 'UserData' => base64_encode("#cloud-config\n" . $yamlDumper->dump($userDataConfig)), 'AnotherConfig' => '12324'], $config);
return new GuzzleModel(['Instances' => [['InstanceId' => 'i-123456']]]);
}));
$mockEc2Client->expects($this->once())->method('waitUntilInstanceRunning')->will($this->returnCallback(function ($config) {
$this->assertEquals(['InstanceIds' => ['i-123456']], $config);
}));
$mockEc2Client->expects($this->once())->method('describeInstances')->will($this->returnCallback(function ($config) {
$this->assertEquals(['InstanceIds' => ['i-123456']], $config);
return $this->getGuzzleModelResponse('aws/describe_instances_response');
}));
$client = $this->getMockClient(['getEc2Client']);
$client->expects($this->any())->method('getEc2Client')->will($this->returnValue($mockEc2Client));
$instances = $client->launchInstances($image, 1, $instanceConfig, null, $userDataConfig);
$this->assertCount(1, $instances);
$this->assertInstanceof('App\\Platform\\Aws\\Instance', $instances[0]);
}
作者:jarve
项目:jarve
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$jarves = $this->getJarves();
$filterByObjectKey = $input->getArgument('object-key');
$filterByBundle = $input->getArgument('bundle');
$dumper = new Dumper();
foreach ($jarves->getConfigs() as $bundleConfig) {
if ($filterByBundle && strtolower($filterByBundle) !== strtolower($bundleConfig->getName())) {
continue;
}
foreach ($bundleConfig->getObjects() as $object) {
if ($filterByObjectKey && strtolower($filterByObjectKey) !== strtolower($object->getId())) {
continue;
}
/** @var AbstractStorage $storage */
$storage = $this->getContainer()->get($object->getStorageService());
$storage->configure($object->getKey(), $object);
try {
$data = $storage->export();
echo $dumper->dump([$object->getKey() => $data], 15);
} catch (NotImplementedException $e) {
if (strtolower($filterByBundle) === strtolower($bundleConfig->getName()) && strtolower($filterByObjectKey) === strtolower($object->getId())) {
$output->writeln('<error>Your requested object does not support export</error>');
}
}
}
}
}
作者:mnic
项目:DrupalConsol
protected function writeSplittedFile($yaml_splitted, $file_output_prefix = '', $file_output_suffix = '', DrupalStyle $io)
{
$dumper = new Dumper();
$io->info($this->trans('commands.yaml.split.messages.generating-split'));
foreach ($yaml_splitted as $key => $value) {
if ($file_output_prefix) {
$key = $file_output_prefix . '.' . $key;
}
if ($file_output_suffix) {
$key .= '.' . $file_output_suffix;
}
$filename = $key . '.yml';
try {
$yaml = $dumper->dump($value, 10);
} catch (\Exception $e) {
$io->error(sprintf('%s: %s', $this->trans('commands.yaml.merge.messages.error-generating'), $e->getMessage()));
return;
}
try {
file_put_contents($filename, $yaml);
} catch (\Exception $e) {
$io->error(sprintf('%s: %s', $this->trans('commands.yaml.merge.messages.error-writing'), $e->getMessage()));
return;
}
$io->success(sprintf($this->trans('commands.yaml.split.messages.split-generated'), $filename));
}
}
作者:jarve
项目:jarve
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getArgument('path');
$phpCode = file_get_contents($path);
$phpCode = preg_replace('/class [a-zA-Z]+ extends [a-zA-Z\\\\]+\\s*\\{/', 'class bla {', $phpCode);
$phpCode = preg_replace('/namespace [a-zA-Z\\\\]+;/', '', $phpCode);
$phpCode = str_replace('<?php', '', $phpCode);
echo $phpCode;
eval($phpCode);
$bla = new \bla();
$array = (array) $bla;
unset($array['preview']);
unset($array['export']);
unset($array['nestedRootRemove']);
unset($array['nestedRootEdit']);
unset($array['nestedRootAdd']);
unset($array['removeIcon']);
unset($array['editIcon']);
unset($array['addIcon']);
unset($array['defaultLimit']);
unset($array['workspace']);
unset($array['versioning']);
$dumper = new Dumper();
$yaml = $dumper->dump($array, 10);
print_r($array);
echo "\n\nYAML----------------:\n\n";
echo $yaml;
}
作者:Ryu062
项目:SaNaV
public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false)
{
$yaml = new Dumper();
$yaml->setIndentation($indent);
return $yaml->dump($array, $inline, 0, $exceptionOnInvalidType, $objectSupport);
}