format() public method

public format ( mixed $value, string $property = null ) : string
$value mixed
$property string
return string
 /**
  * @param string          $property
  * @param string          $value
  * @param Environment     $environment
  *
  * @return int
  */
 protected function setProperty($property, $value, Environment $environment)
 {
     if (!$this->validateValue($property, $value)) {
         return 1;
     }
     $type = $this->getType($property);
     if ($type === 'boolean' && $value === 'false') {
         $value = false;
     }
     settype($value, $type);
     $currentValue = $environment->getProperty($property, false);
     if ($currentValue === $value) {
         $this->stdErr->writeln("Property <info>{$property}</info> already set as: " . $this->formatter->format($environment->getProperty($property, false), $property));
         return 0;
     }
     $environment->update(array($property => $value));
     $this->stdErr->writeln("Property <info>{$property}</info> set to: " . $this->formatter->format($environment[$property], $property));
     $rebuildProperties = array('enable_smtp', 'restrict_robots');
     if (in_array($property, $rebuildProperties) && !$environment->getLastActivity()) {
         $this->rebuildWarning();
     }
     // Refresh the stored environments.
     $this->getEnvironments($this->getSelectedProject(), true);
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $info = $this->api()->getMyAccount((bool) $input->getOption('refresh'));
     $formatter = new PropertyFormatter($input);
     $propertyWhitelist = ['id', 'uuid', 'display_name', 'username', 'mail', 'has_key'];
     $info = array_intersect_key($info, array_flip($propertyWhitelist));
     $property = $input->getArgument('property');
     if ($input->getOption('property')) {
         if ($property) {
             throw new InvalidArgumentException(sprintf('You cannot use both the <%s> argument and the --%s option', 'property', 'property'));
         }
         $property = $input->getOption('property');
     }
     if ($property) {
         if (!isset($info[$property])) {
             throw new \InvalidArgumentException('Property not found: ' . $property);
         }
         $output->writeln($formatter->format($info[$property], $property));
         return 0;
     }
     unset($info['uuid']);
     $values = [];
     $header = [];
     foreach ($propertyWhitelist as $property) {
         if (isset($info[$property])) {
             $values[] = $formatter->format($info[$property], $property);
             $header[] = $property;
         }
     }
     $table = new Table($input, $output);
     $table->renderSimple($values, $header);
     return 0;
 }
 /**
  * Display domain information.
  *
  * @param Domain          $domain
  * @param OutputInterface $output
  * @param int $indent
  */
 protected function displayDomain(Domain $domain, OutputInterface $output, $indent = 2)
 {
     $formatter = new PropertyFormatter();
     $indent = str_repeat(' ', $indent);
     $output->writeln($indent . "Name: {$domain->name}");
     $output->writeln($indent . "Has SSL certificate: " . $formatter->format(!empty($domain->ssl['has_certificate'])));
     $output->writeln($indent . "Added: " . $formatter->format($domain->created_at, 'created_at'));
 }
 /**
  * Recursively build rows of the domain table.
  *
  * @param Domain[] $tree
  *
  * @return array
  */
 protected function buildDomainRows(array $tree)
 {
     $rows = array();
     $formatter = new PropertyFormatter();
     foreach ($tree as $domain) {
         $rows[] = array($domain['id'], $formatter->format((bool) $domain['has_certificate']), $formatter->format($domain['created_at'], 'created_at'));
     }
     return $rows;
 }
 /**
  * @param Environment     $environment
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function listProperties(Environment $environment, OutputInterface $output)
 {
     $this->stdErr->writeln("Metadata for the environment <info>" . $environment['id'] . "</info>:");
     $table = new Table($output);
     $table->setHeaders(array("Property", "Value"));
     foreach ($environment->getProperties() as $key => $value) {
         $table->addRow(array($key, $this->formatter->format($value, $key)));
     }
     $table->render();
     return 0;
 }
 /**
  * @param Subscription $subscription
  * @param Table        $table
  *
  * @return int
  */
 protected function listProperties(Subscription $subscription, Table $table)
 {
     $headings = [];
     $values = [];
     foreach ($subscription->getProperties() as $key => $value) {
         $headings[] = new AdaptiveTableCell($key, ['wrap' => false]);
         $values[] = $this->formatter->format($value, $key);
     }
     $table->renderSimple($values, $headings);
     return 0;
 }
 /**
  * @param Integration     $integration
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function displayIntegration(Integration $integration, InputInterface $input, OutputInterface $output)
 {
     $table = new Table($input, $output);
     $info = [];
     foreach ($integration->getProperties() as $property => $value) {
         $info[$property] = $this->propertyFormatter->format($value, $property);
     }
     if ($integration->hasLink('#hook')) {
         $info['hook_url'] = $this->propertyFormatter->format($integration->getLink('#hook'));
     }
     $table->renderSimple(array_values($info), array_keys($info));
 }
 /**
  * @param Subscription $subscription
  * @param Table        $table
  *
  * @return int
  */
 protected function listProperties(Subscription $subscription, Table $table)
 {
     $headings = [];
     $values = [];
     foreach ($subscription->getProperties() as $key => $value) {
         $value = $this->formatter->format($value, $key);
         $value = wordwrap($value, 50, "\n", true);
         $headings[] = $key;
         $values[] = $value;
     }
     $table->renderSimple($values, $headings);
     return 0;
 }
 /**
  * @param Subscription    $subscription
  *
  * @return int
  */
 protected function listProperties(Subscription $subscription)
 {
     $this->stdErr->writeln("Metadata for the subscription <info>" . $subscription->id . "</info>:");
     $table = new Table($this->output);
     $table->setHeaders(array("Property", "Value"));
     foreach ($subscription->getProperties() as $key => $value) {
         $value = $this->formatter->format($value, $key);
         $value = wordwrap($value, 50, "\n", true);
         $table->addRow(array($key, $value));
     }
     $table->render();
     return 0;
 }
 /**
  * @param string      $property
  * @param string      $value
  * @param Environment $environment
  * @param bool        $noWait
  *
  * @return int
  */
 protected function setProperty($property, $value, Environment $environment, $noWait)
 {
     if (!$this->validateValue($property, $value)) {
         return 1;
     }
     $type = $this->getType($property);
     if ($type === 'boolean' && $value === 'false') {
         $value = false;
     }
     settype($value, $type);
     $currentValue = $environment->getProperty($property, false);
     if ($currentValue === $value) {
         $this->stdErr->writeln("Property <info>{$property}</info> already set as: " . $this->formatter->format($environment->getProperty($property, false), $property));
         return 0;
     }
     $result = $environment->update([$property => $value]);
     $this->stdErr->writeln("Property <info>{$property}</info> set to: " . $this->formatter->format($environment->{$property}, $property));
     $this->api()->clearEnvironmentsCache($environment->project);
     $rebuildProperties = ['enable_smtp', 'restrict_robots'];
     $success = true;
     if ($result->countActivities() && !$noWait) {
         $success = ActivityUtil::waitMultiple($result->getActivities(), $this->stdErr, $this->getSelectedProject());
     } elseif (!$result->countActivities() && in_array($property, $rebuildProperties)) {
         $this->rebuildWarning();
     }
     return $success ? 0 : 1;
 }
 /**
  * @param string  $property
  * @param string  $value
  * @param Project $project
  * @param bool    $noWait
  *
  * @return int
  */
 protected function setProperty($property, $value, Project $project, $noWait)
 {
     if (!$this->validateValue($property, $value)) {
         return 1;
     }
     $type = $this->getType($property);
     if ($type === 'boolean' && $value === 'false') {
         $value = false;
     }
     settype($value, $type);
     $currentValue = $project->getProperty($property);
     if ($currentValue === $value) {
         $this->stdErr->writeln("Property <info>{$property}</info> already set as: " . $this->formatter->format($value, $property));
         return 0;
     }
     $project->ensureFull();
     $result = $project->update([$property => $value]);
     $this->stdErr->writeln("Property <info>{$property}</info> set to: " . $this->formatter->format($value, $property));
     $this->api()->clearProjectsCache();
     $success = true;
     if (!$noWait) {
         $success = ActivityUtil::waitMultiple($result->getActivities(), $this->stdErr, $project);
     }
     return $success ? 0 : 1;
 }
 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;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $project = $this->getSelectedProject();
     $domainName = $input->getArgument('name');
     if (empty($domainName)) {
         if (!$input->isInteractive()) {
             $this->stdErr->writeln('The domain name is required.');
             return 1;
         }
         $domains = $project->getDomains();
         $options = [];
         foreach ($domains as $domain) {
             $options[$domain->name] = $domain->name;
         }
         /** @var QuestionHelper $questionHelper */
         $questionHelper = $this->getHelper('question');
         $domainName = $questionHelper->choose($options, 'Enter a number to choose a domain:');
     }
     $domain = $project->getDomain($domainName);
     if (!$domain) {
         $this->stdErr->writeln('Domain not found: <error>' . $domainName . '</error>');
         return 1;
     }
     $propertyFormatter = new PropertyFormatter($input);
     if ($property = $input->getOption('property')) {
         $value = $this->api()->getNestedProperty($domain, $property);
         $output->writeln($propertyFormatter->format($value, $property));
         return 0;
     }
     $values = [];
     $properties = [];
     foreach ($domain->getProperties() as $name => $value) {
         // Hide the deprecated (irrelevant) property 'wildcard'.
         if ($name === 'wildcard') {
             continue;
         }
         $properties[] = $name;
         $values[] = $propertyFormatter->format($value, $name);
     }
     $table = new Table($input, $output);
     $table->renderSimple($values, $properties);
     $this->stdErr->writeln('');
     $this->stdErr->writeln('To update a domain, run: <info>' . self::$config->get('application.executable') . ' domain:update [domain-name]</info>');
     $this->stdErr->writeln('To delete a domain, run: <info>' . self::$config->get('application.executable') . ' domain:delete [domain-name]</info>');
     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;
 }
 /**
  * @param string          $property
  * @param string          $value
  * @param Project         $project
  *
  * @return int
  */
 protected function setProperty($property, $value, Project $project)
 {
     if (!$this->validateValue($property, $value)) {
         return 1;
     }
     $type = $this->getType($property);
     if ($type === 'boolean' && $value === 'false') {
         $value = false;
     }
     settype($value, $type);
     $currentValue = $project->getProperty($property);
     if ($currentValue === $value) {
         $this->stdErr->writeln("Property <info>{$property}</info> already set as: " . $this->formatter->format($value, $property));
         return 0;
     }
     $project->ensureFull();
     $project->update(array($property => $value));
     $this->stdErr->writeln("Property <info>{$property}</info> set to: " . $this->formatter->format($value, $property));
     $this->getProjects(true);
     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 execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $auth = $input->getOption('auth');
     $access = $input->getOption('access');
     $accessOpts = [];
     $enabled = $input->getOption('enabled');
     if ($enabled !== null) {
         $accessOpts['is_enabled'] = !in_array($enabled, ['0', 'false']);
     }
     if ($access) {
         $accessOpts['addresses'] = [];
         foreach (array_filter($access) as $access) {
             $accessOpts["addresses"][] = $this->parseAccess($access);
         }
     }
     if ($auth) {
         $accessOpts['basic_auth'] = [];
         foreach (array_filter($auth) as $auth) {
             $parsed = $this->parseAuth($auth);
             $accessOpts["basic_auth"][$parsed["username"]] = $parsed["password"];
         }
     }
     // Ensure the environment is refreshed.
     $selectedEnvironment = $this->getSelectedEnvironment();
     $selectedEnvironment->ensureFull();
     $environmentId = $selectedEnvironment->id;
     $formatter = new PropertyFormatter();
     if (!empty($accessOpts)) {
         $current = (array) $selectedEnvironment->getProperty('http_access');
         // Merge existing settings. Not using a reference here, as that
         // would affect the comparison with $current later.
         foreach ($current as $key => $value) {
             if (!isset($accessOpts[$key])) {
                 $accessOpts[$key] = $value;
             }
         }
         if ($current != $accessOpts) {
             // The API only accepts {} for an empty "basic_auth" value,
             // rather than [].
             if (isset($accessOpts['basic_auth']) && $accessOpts['basic_auth'] === []) {
                 $accessOpts['basic_auth'] = (object) [];
             }
             // Patch the environment with the changes.
             $result = $selectedEnvironment->update(['http_access' => $accessOpts]);
             $this->clearEnvironmentsCache();
             $this->stdErr->writeln("Updated HTTP access settings for the environment <info>{$environmentId}</info>:");
             $output->writeln($formatter->format($selectedEnvironment->getProperty('http_access'), 'http_access'));
             $success = true;
             if (!$result->countActivities()) {
                 $this->rebuildWarning();
             } elseif (!$input->getOption('no-wait')) {
                 $success = ActivityUtil::waitMultiple($result->getActivities(), $this->stdErr);
             }
             return $success ? 0 : 1;
         }
     }
     $this->stdErr->writeln("HTTP access settings for the environment <info>{$environmentId}</info>:");
     $output->writeln($formatter->format($selectedEnvironment->getProperty('http_access'), 'http_access'));
     return 0;
 }