protected function execute(InputInterface $input, OutputInterface $output) { $this->validateInput($input); $app = $this->selectApp($input); $environment = $this->getSelectedEnvironment(); $cacheKey = implode('-', ['relationships', $environment->id . $environment->project . $app]); $cache = CacheUtil::getCache(); $relationships = $cache->fetch($cacheKey); if (empty($relationships) || $input->getOption('refresh')) { $util = new RelationshipsUtil($this->stdErr); $sshUrl = $environment->getSshUrl($app); $relationships = $util->getRelationships($sshUrl); if (empty($relationships)) { $this->stdErr->writeln('No relationships found'); return 1; } $cache->save($cacheKey, $relationships, 3600); } $value = $relationships; $key = null; if ($property = $input->getOption('property')) { $parents = explode('.', $property); $key = end($parents); $value = Util::getNestedArrayValue($relationships, $parents, $key_exists); if (!$key_exists) { $this->stdErr->writeln("Relationship property not found: <error>{$property}</error>"); return 1; } } $formatter = new PropertyFormatter(); $formatter->yamlInline = 10; $output->writeln($formatter->format($value, $key)); return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->validateInput($input); $shellHelper = $this->getHelper('shell'); $shellHelper->setOutput($this->stdErr); $sshUrl = $this->getSelectedEnvironment()->getSshUrl($this->selectApp($input)); $args = ['ssh', $sshUrl, 'echo $PLATFORM_APPLICATION']; $result = $shellHelper->execute($args, null, true); $appConfig = json_decode(base64_decode($result), true); $value = $appConfig; $key = null; if ($property = $input->getOption('property')) { $parents = explode('.', $property); $key = end($parents); $value = Util::getNestedArrayValue($appConfig, $parents, $key_exists); if (!$key_exists) { $this->stdErr->writeln("Configuration property not found: <error>{$property}</error>"); return 1; } } $formatter = new PropertyFormatter(); $formatter->yamlInline = 10; $output->writeln($formatter->format($value, $key)); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->validateInput($input); $project = $this->getSelectedProject(); $environment = $this->getSelectedEnvironment(); $appName = $this->selectApp($input); $tunnels = $this->getTunnelInfo(); $relationships = []; foreach ($this->filterTunnels($tunnels, $input) as $key => $tunnel) { $service = $tunnel['service']; // Overwrite the service's address with the local tunnel details. $service['host'] = self::LOCAL_IP; $service['ip'] = self::LOCAL_IP; $service['port'] = $tunnel['localPort']; $relationships[$tunnel['relationship']][$tunnel['serviceKey']] = $service; } if (!count($relationships)) { $this->stdErr->writeln('No tunnels found.'); if (count($tunnels) > count($relationships)) { $this->stdErr->writeln("List all tunnels with: <info>platform tunnels --all</info>"); } return 1; } if ($input->getOption('encode')) { if ($input->getOption('property')) { $this->stdErr->writeln('You cannot combine --encode with --property.'); return 1; } $output->writeln(base64_encode(json_encode($relationships))); return 0; } $value = $relationships; $key = null; if ($property = $input->getOption('property')) { $parents = explode('.', $property); $key = end($parents); $value = Util::getNestedArrayValue($relationships, $parents, $key_exists); if (!$key_exists) { $this->stdErr->writeln("Property not found: <error>{$property}</error>"); return 1; } } $formatter = new PropertyFormatter(); $formatter->yamlInline = 10; $output->writeln($formatter->format($value, $key)); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->checkSupport(); $this->validateInput($input); $tunnels = $this->getTunnelInfo(); $relationships = []; foreach ($this->filterTunnels($tunnels, $input) as $key => $tunnel) { $service = $tunnel['service']; // Overwrite the service's address with the local tunnel details. $service = array_merge($service, array_intersect_key(['host' => self::LOCAL_IP, 'ip' => self::LOCAL_IP, 'port' => $tunnel['localPort']], $service)); $relationships[$tunnel['relationship']][$tunnel['serviceKey']] = $service; } if (!count($relationships)) { $this->stdErr->writeln('No tunnels found.'); if (count($tunnels) > count($relationships)) { $this->stdErr->writeln("List all tunnels with: <info>" . self::$config->get('application.executable') . " tunnels --all</info>"); } return 1; } if ($input->getOption('encode')) { if ($input->getOption('property')) { $this->stdErr->writeln('You cannot combine --encode with --property.'); return 1; } $output->writeln(base64_encode(json_encode($relationships))); return 0; } $value = $relationships; if ($property = $input->getOption('property')) { $value = Util::getNestedArrayValue($relationships, explode('.', $property), $keyExists); if (!$keyExists) { $this->stdErr->writeln("Property not found: <error>{$property}</error>"); return 1; } } $formatter = new PropertyFormatter(); $formatter->yamlInline = 10; $output->writeln($formatter->format($value, $property)); return 0; }
protected function applyUserConfigOverrides() { // A whitelist of allowed overrides. $overrideMap = ['api' => 'api', 'local.copy_on_windows' => 'local.copy_on_windows', 'local.drush_executable' => 'local.drush_executable', 'experimental' => 'experimental', 'updates' => 'updates']; $userConfig = $this->getUserConfig(); if (!empty($userConfig)) { foreach ($overrideMap as $userConfigKey => $configKey) { $value = Util::getNestedArrayValue($userConfig, explode('.', $userConfigKey), $exists); if ($exists) { $configParents = explode('.', $configKey); $default = Util::getNestedArrayValue(self::$config, $configParents, $defaultExists); if ($defaultExists && is_array($default)) { if (!is_array($value)) { continue; } $value = array_replace_recursive($default, $value); } Util::setNestedArrayValue(self::$config, $configParents, $value, true); } } } }
/** * Get a nested property of a resource, via a dot-separated string path. * * @param ApiResource $resource * @param string $propertyPath * @param bool $lazyLoad * * @throws \InvalidArgumentException if the property is not found. * * @return mixed */ public static function getNestedProperty(ApiResource $resource, $propertyPath, $lazyLoad = true) { if (!strpos($propertyPath, '.')) { return $resource->getProperty($propertyPath, true, $lazyLoad); } $parents = explode('.', $propertyPath); $propertyName = array_shift($parents); $property = $resource->getProperty($propertyName, true, $lazyLoad); if (!is_array($property)) { throw new \InvalidArgumentException(sprintf('Invalid path "%s": the property "%s" is not an array.', $propertyPath, $propertyName)); } $value = Util::getNestedArrayValue($property, $parents, $keyExists); if (!$keyExists) { throw new \InvalidArgumentException('Property not found: ' . $propertyPath); } return $value; }