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)); } } }
/** * @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); }
/** * @inheritDoc */ public function serialize(array $parameters, $fileHeader = null) { $output = ''; if ($fileHeader) { $output .= \NordCode\RoboParameters\wrap_lines($fileHeader, '# ') . "\n"; } return $output . $this->yamlDumper->dump($parameters, 4); }
/** * gets all versions * * @return array version numbers of packages */ public function getPackageVersions() { if ($this->isDesiredVersion('self')) { $versions = [$this->getContextVersion()]; } else { $versions = array(); } $versions = $this->getInstalledPackagesVersion($versions); return $this->yamlDumper->dump($versions); }
public function encode($input, $inline = 0, $dumpObjects = false) { static $dumper; if (null === $dumper) { $dumper = new YamlDumper(); } if (defined('Symfony\\Component\\Yaml\\Yaml::DUMP_OBJECT')) { return $dumper->dump($input, $inline, 0, is_bool($dumpObjects) ? Yaml::DUMP_OBJECT : 0); } return $dumper->dump($input, $inline, 0, false, $dumpObjects); }
/** * Export Menus */ public function export() { $app = Bootstrap::getApplication(); $settings = $app['settings']; if (!isset($settings['content']['menus'])) { return; } $this->readMenus(); $dumper = new Dumper(); remove_all_filters('wp_get_nav_menu_items'); $helpers = $app['helpers']; $exportTaxonomies = $app['exporttaxonomies']; $exportPosts = $app['exportposts']; $baseUrl = get_option('siteurl'); foreach ($settings['content']['menus'] as $menu) { $dir = WPBOOT_BASEPATH . '/bootstrap/menus/' . $menu; array_map('unlink', glob("{$dir}/*")); @mkdir($dir, 0777, true); $menuMeta = array(); $menuMeta['locations'] = array(); if (isset($this->navMenus[$menu])) { $menuMeta['locations'] = $this->navMenus[$menu]->locations; } $file = WPBOOT_BASEPATH . "/bootstrap/menus/{$menu}_manifest"; file_put_contents($file, $dumper->dump($menuMeta, 4)); $menuItems = wp_get_nav_menu_items($menu); foreach ($menuItems as $menuItem) { $obj = get_post($menuItem->ID, ARRAY_A); $obj['post_meta'] = get_post_meta($obj['ID']); switch ($obj['post_meta']['_menu_item_type'][0]) { case 'post_type': $postType = $obj['post_meta']['_menu_item_object'][0]; $postId = $obj['post_meta']['_menu_item_object_id'][0]; $objPost = get_post($postId); $exportPosts->addPost($postType, $objPost->post_name); break; case 'taxonomy': $id = $obj['post_meta']['_menu_item_object_id'][0]; $taxonomy = $obj['post_meta']['_menu_item_object'][0]; $objTerm = get_term($id, $taxonomy); if (!is_wp_error($objTerm)) { $exportTaxonomies->addTerm($taxonomy, $objTerm->slug); } break; } $helpers->fieldSearchReplace($obj, $baseUrl, Bootstrap::NEUTRALURL); $file = $dir . '/' . $menuItem->post_name; file_put_contents($file, $dumper->dump($obj, 4)); } } }
public function testShortcutGetConfigurationMethod() { $envs = ["environment" => "dev", "required_environments" => ["dev", "sandbox"]]; file_put_contents(self::$testCreateDir . "/global.yml", $this->dumper->dump($envs)); $this->configLoader->load(); $this->assertTrue($this->configLoader->getConfig() === $this->configLoader->getConfiguration()); }
/** * @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 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) { $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(); }
/** * @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)); }
/** * {@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; }
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>'); }
/** * 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; }
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"); }
/** * @param string $target * * @return string */ private function siteDetail($target) { if ($targetConfig = $this->configurationManager->readTarget($target)) { $dumper = new Dumper(); return $dumper->dump($targetConfig, 2); } }
/** * {@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; }
/** * {@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; }
/** * {@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>'); } } } } }
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); }
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)); }
/** */ 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 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; }
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; }
/** * All objects must have a string representation. * * @return string $this */ public function __toString() { // Encoder self::$_Encoder = self::$_Encoder ?: new Dumper(); // Encode config return self::$_Encoder->dump(iterator_to_array($this), 2); }
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(); }
/** * Writes the config files. * * ATTENTION: This method DOES NOT perform any sanitize actions. It * overwrites the config files with the options entirely. */ private function writeConfig() { // updates existing files and adds new files if necessary $path = null; $roleNames = array_keys($this->optionData); $baseNames = []; foreach ($this->finder as $file) { /** @var SplFileInfo $file */ if ($path === null) { $path = $file->getPath(); break; } } foreach ($roleNames as $roleName) { $baseNames[] = strtolower($roleName); } foreach ($baseNames as $basename) { $category = $this->optionData[strtoupper($basename)]; $yaml = ConfigUtil::convertToArray($category); $dumpReady = $this->dumper->dump($yaml, 3); $writePath = $path . '/' . $basename . '.yml'; $this->filesystem->dumpFile($writePath, $dumpReady); } foreach ($this->toBeRemoved as $toRemove) { $basename = strtolower($toRemove) . '.yml'; $deletePath = $path . '/' . $basename; $this->filesystem->remove($deletePath); } $this->toBeRemoved = []; }
/** * {@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; }
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]); }
/** * 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)); }