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");
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
  /**
   * {@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;
  }
 /**
  * @param string $target
  *
  * @return string
  */
 private function siteDetail($target)
 {
     if ($targetConfig = $this->configurationManager->readTarget($target)) {
         $dumper = new Dumper();
         return $dumper->dump($targetConfig, 2);
     }
 }
 /**
  * @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;
 }
 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>');
 }
Beispiel #7
0
 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();
 }
Beispiel #8
0
 /**
  * {@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();
 }
Beispiel #9
0
 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;
 }
Beispiel #10
0
 /**
  */
 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));
 }
 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;
     }
 }
 /**
  * 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;
 }
 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));
         }
     }
 }
Beispiel #14
0
 /**
  * @param mixed $value
  *
  * @return string
  */
 public function dumpToString($value)
 {
     $dumper = new Dumper();
     $dumper->setIndentation(2);
     $yamlString = $dumper->dump($value, 15);
     return $yamlString;
 }
 /**
  * @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));
 }
Beispiel #16
0
 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]);
 }
Beispiel #17
0
 /**
  * {@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>');
                 }
             }
         }
     }
 }
Beispiel #18
0
 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));
     }
 }
 /**
  * {@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;
 }
Beispiel #20
0
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);
}
Beispiel #21
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, $key = '')
 {
     // Get the old value
     $old_value = \Drupal::state()->get($key);
     // First we will show the user the content of the variable about to be edited
     $form['old_value'] = array('#type' => 'item', '#title' => t('Old value for %name', array('%name' => $key)), '#markup' => kprint_r($old_value, TRUE));
     // Store in the form the name of the state variable
     $form['state_name'] = array('#type' => 'hidden', '#value' => $key);
     // Only simple structures are allowed to be edited.
     $disabled = !$this->checkObject($old_value);
     // Set the transport format for the new value. Values:
     //  - plain
     //  - yaml
     $form['transport'] = array('#type' => 'hidden', '#value' => 'plain');
     if (is_array($old_value)) {
         $dumper = new Dumper();
         // Set Yaml\Dumper's default indentation for nested nodes/collections to
         // 2 spaces for consistency with Drupal coding standards.
         $dumper->setIndentation(2);
         // The level where you switch to inline YAML is set to PHP_INT_MAX to
         // ensure this does not occur.
         $old_value = $dumper->dump($old_value, PHP_INT_MAX);
         $form['transport']['#value'] = 'yaml';
     }
     $form['new_value'] = array('#type' => 'textarea', '#title' => t('New value'), '#default_value' => $disabled ? '' : $old_value, '#disabled' => $disabled);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
     $form['actions']['cancel'] = array('#type' => 'link', '#title' => t('Cancel'), '#href' => 'devel/state');
     return $form;
 }
 public function getYaml($entities, $locale)
 {
     // Unflatten array
     $entitiesNested = array();
     foreach ($entities as $entity => $spec) {
         // Legacy support: Don't count *.ss as namespace
         $entity = preg_replace('/\\.ss\\./', '___ss.', $entity);
         $parts = explode('.', $entity);
         $currLevel =& $entitiesNested;
         while ($part = array_shift($parts)) {
             $part = str_replace('___ss', '.ss', $part);
             if (!isset($currLevel[$part])) {
                 $currLevel[$part] = array();
             }
             $currLevel =& $currLevel[$part];
         }
         $currLevel = $spec[0];
     }
     // Write YAML
     $dumper = new Dumper();
     $dumper->setIndentation(2);
     // TODO Dumper can't handle YAML comments, so the context information is currently discarded
     $result = $dumper->dump(array($locale => $entitiesNested), 99);
     return $result;
 }
Beispiel #23
0
 /**
  * @param mixed  $data
  * @param string $format
  * @param array  $context
  *
  * @return string
  */
 public function encode($data, $format, array $context = array())
 {
     if ($this->native) {
         return yaml_emit($data, YAML_UTF8_ENCODING, YAML_LN_BREAK);
     }
     return $this->encoder->dump($data);
 }
Beispiel #24
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $time_start = microtime(true);
     $site = $input->getArgument('site');
     $output->writeln('halting homestead...');
     // exec('cd ~/Homestead && vagrant halt', $result);
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln($result);
     }
     $output->writeln('removing ' . $site . ' from Homestead...');
     $yaml = new Parser();
     $homesteadFile = $yaml->parse(file_get_contents(getenv("HOME") . '/.homestead/Homestead.yaml'));
     $directory = str_replace($homesteadFile['folders'][0]['map'], $homesteadFile['folders'][0]['to'], $directory);
     $sites = $this->removeSiteFromArray($site, $homesteadFile['sites']);
     $homesteadFile['sites'] = $sites;
     $dumper = new Dumper();
     $yaml = $dumper->dump($homesteadFile, 2);
     file_put_contents(getenv("HOME") . '/.homestead/Homestead.yaml', $yaml);
     $output->writeln('adding ' . $site . ' to Hosts...');
     exec('cd ' . __DIR__ . '/../Scripts && sudo php RemoveHosts.php ' . $site);
     $output->writeln('restarting homestead...');
     exec('cd ~/Homestead && vagrant up --provision', $result);
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln($result);
     }
     $output->writeln('SSH into vagrant:');
     $output->writeln("\n<comment>cd ~/Homestead && vagrant ssh</comment>");
     $output->writeln("\n<comment>http://" . $site . ": has been removed</comment>");
     $time_end = microtime(true);
     $time = $time_end - $time_start;
     $output->writeln("\nCompleted in: " . $time . " seconds");
 }
Beispiel #25
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $config_name = '')
 {
     $data = $this->config($config_name)->get();
     if ($data === FALSE) {
         drupal_set_message(t('Config !name does not exist in the system.', array('!name' => $config_name)), 'error');
         return;
     }
     if (empty($data)) {
         drupal_set_message(t('Config !name exists but has no data.', array('!name' => $config_name)), 'warning');
         return;
     }
     $dumper = new Dumper();
     // Set Yaml\Dumper's default indentation for nested nodes/collections to
     // 2 spaces for consistency with Drupal coding standards.
     $dumper->setIndentation(2);
     // The level where you switch to inline YAML is set to PHP_INT_MAX to
     // ensure this does not occur.
     $output = $dumper->dump($data, PHP_INT_MAX);
     $form['name'] = array('#type' => 'value', '#value' => $config_name);
     $form['value'] = array('#type' => 'item', '#title' => t('Old value for %variable', array('%variable' => $config_name)), '#markup' => dpr($output, TRUE));
     $form['new'] = array('#type' => 'textarea', '#title' => t('New value'), '#default_value' => $output);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
     $form['actions']['cancel'] = array('#type' => 'link', '#title' => t('Cancel'), '#href' => 'devel/config');
     return $form;
 }
 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));
 }
 /**
  * Encodes as YAML the passed $input
  *
  * @param $input
  * @param int $inline
  * @return mixed
  */
 public function encode($input, $inline = self::INLINE)
 {
     static $dumper;
     if (null === $dumper) {
         $dumper = new YamlDumper();
     }
     return $dumper->dump($input, $inline);
 }
 /**
  * @return string
  */
 protected function getCompiled()
 {
     if (null === $this->compiled) {
         $dumper = new Dumper();
         $this->compiled = trim(sprintf("%s\n---\n%s", basename(str_replace('\\', '/', get_class($this))), $dumper->dump($this->getCompileProperties(), PHP_INT_MAX)));
     }
     return $this->compiled;
 }
Beispiel #29
0
 public function encode($input, $inline = 0, $dumpObjects = false)
 {
     static $dumper;
     if (null === $dumper) {
         $dumper = new YamlDumper();
     }
     return $dumper->dump($input, $inline, false, $dumpObjects);
 }
Beispiel #30
-1
 /**
  * Update wp-cli.yml with settings from .env files
  *
  * ## OPTIONS
  *
  * <environment>
  * : The name of the environment to set. Typically matched by a .env-<environemnt> file in the project root
  *
  * @param $args
  * @param $assocArgs
  *
  * @when before_wp_load
  */
 public function __invoke($args, $assocArgs)
 {
     $environment = $args[0];
     if (file_exists(WPBOOT_BASEPATH . "/.env")) {
         $dotEnv = new Dotenv(WPBOOT_BASEPATH);
         $dotEnv->load();
     }
     $file = '.env-' . $environment;
     if (file_exists(WPBOOT_BASEPATH . "/{$file}")) {
         $dotEnv = new Dotenv(WPBOOT_BASEPATH, $file);
         $dotEnv->overload();
     }
     try {
         $dotEnv = new Dotenv(__DIR__);
         $dotEnv->required('wppath');
     } catch (\Exception $e) {
         echo $e->getMessage() . "\n";
         return;
     }
     $runner = WP_CLI::get_runner();
     $ymlPath = $runner->project_config_path;
     $yaml = new Yaml();
     $config = $yaml->parse(file_get_contents($ymlPath));
     $config['path'] = $_ENV['wppath'];
     $config['environment'] = $environment;
     $dumper = new Dumper();
     file_put_contents($ymlPath, $dumper->dump($config, 2));
 }