Dumps the directive respecting a server syntax.

@param ServerInterface $server a server instance
@param int             $spaces the indentation spaces

@return string the dumped directive
354428
public function dump(ServerInterface $server, $spaces = 0)
    {
        $config = '';

        foreach ($this->directives as $directive) {
            $config .= $directive->dump($server, $spaces + ($this->isMainContext() ? 0 : 4));
        }

        return $this->dumpBlock($server->getDumperStartDirective(), $spaces).
            $config.
            $this->dumpBlock($server->getDumperEndDirective(), $spaces);
    }
386522
public function server(array $server)
    {
        foreach ((array) $server as $key => $value)
        {
            $string = strtolower(substr($key, 5));

            $key = str_replace('_', '-', $string);

            if (strpos($key, 'HTTP_') === 0)
            {
                $this->headers[$key] = $value;
            }
        }
    }
359140
public function execute(Server $server)
    {
        $cursor = $server->executeCommand($this->databaseName, $this->command, $this->createOptions());

        if (isset($this->options['typeMap'])) {
            $cursor->setTypeMap($this->options['typeMap']);
        }

        return $cursor;
    }
1074834
public function dump(int $tab = 0): string
    {
        $declarations = implode(', ', array_keys($this->declarations));
        $usages = implode(', ', $this->usages);

        $self = sprintf("%s : {D : %s} {U : %s} \n", $name ?? 'noname', $declarations, $usages);

        $children = "";

        foreach ($this->children as $child) {
            $children .= str_repeat(" ", $tab) . $child->dump($tab + 4) . "\n";
        }

        return $self . $children;
    }
1168905
private function dumpParameter($name)
    {
        if ($this->container->isCompiled() && $this->container->hasParameter($name)) {
            $value = $this->container->getParameter($name);
            $dumpedValue = $this->dumpValue($value, false);

            if (!$value || !is_array($value)) {
                return $dumpedValue;
            }

            if (!preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $dumpedValue)) {
                return sprintf("\$this->parameters['%s']", $name);
            }
        }

        return sprintf("\$this->getParameter('%s')", $name);
    }
538602
private static function runShellCommand($commandString): string
    {
        $shellCommand = new Command();
        $shellCommand->setCommand($commandString);

        if ($shellCommand->execute()) {
            $result = $shellCommand->getOutput();
        } else {
            $result = $shellCommand->getError();
        }

        return $result;
    }
139545
public static function getMethod(array $server): string
    {
        $method = $server['REQUEST_METHOD'] ?? 'GET';
        if ($method === 'POST' &&
            isset(
                $server['HTTP_X_HTTP_METHOD_OVERRIDE'],
                self::$methods[$server['HTTP_X_HTTP_METHOD_OVERRIDE']]
            )
        ) {
            $method = $server['HTTP_X_HTTP_METHOD_OVERRIDE'];
        }

        return $method;
    }
1188529
protected function _parseContent($content) {
        $output = array();
        $matches = array();
        $paramsString = implode('|', $this->_deployParams);
        $pattern = '/:?(?P<paramName>' . $paramsString
            . ')[,:]? [\'"](?P<paramValue>[^\'"]*)[\'"]/';

        if (!preg_match_all($pattern, $content, $matches)) {
            throw new Exception(
                "Could not extract deploy parameters from "
                . self::GENERIC_CONFIG_PATH
            );
        }

        foreach ($this->_deployParams as $p) {
            $indices = array_keys(
                array_filter(
                    $matches['paramName'], function ($pn) use ($p) {
                        return $pn === $p;
                    }
                )
            );
            if (!count($indices)) {
                continue;
            }
            $output[$p] = array_values(array_get_subset($matches['paramValue'], $indices));

            // For now: only treat the server param as array (since it's common for it to be an
            // array, in the case of a multi-server setup)
            if ($p !== 'server') {
                $output[$p] = $output[$p][0];
            }
        }

        // explode server into user and server parts
        if (!empty($output['server'])) {
            $output['server'] = array_map(
                function ($serverConfig) {
                    $bits = explode('@', $serverConfig, 2);
                    return array(
                    'user' => $bits[0],
                    'server' => $bits[1]
                    );
                }, $output['server']
            );
        }

        return $output;
    }
321780
protected function deploy($server, $deployer, OutputInterface $output)
    {
        $plum    = $this->getContainer()->get('madalynn.plum');
        $options = $plum->getOptions($server);

        $dryrun = '';
        if (isset($options['dry_run']) && $options['dry_run']) {
            $dryrun = '<comment>(dry run mode)</comment>';
        }

        $output->writeln(sprintf('Starting %s to <info>%s</info> %s', $deployer, $server, $dryrun));

        // Let's go!
        $plum->deploy($server, $deployer, $options);

        $output->writeln(sprintf('Successfully %s to <info>%s</info>', $deployer, $server));
    }
1317711
protected function dumpContext($context)
    {
        $export = '';
        foreach ($context as $key => $value) {
            $export .= "{$key}: ";
            $export .= preg_replace(array(
                '/=>\s+([a-zA-Z])/im',
                '/array\(\s+\)/im',
                '/^  |\G  /m',
            ), array(
                '=> $1',
                'array()',
                '    ',
            ), str_replace('array (', 'array(', var_export($value, true)));
            $export .= PHP_EOL;
        }

        return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
    }
93296
private function executeAggregate(Server $server)
    {
        /* If we've already captured an operation time or the server does not
         * support returning an operation time (e.g. MongoDB 3.6), execute the
         * aggregation directly and return its cursor. */
        if ($this->operationTime !== null || ! \MongoDB\server_supports_feature($server, self::$wireVersionForOperationTime)) {
            return $this->aggregate->execute($server);
        }

        /* Otherwise, execute the aggregation using command monitoring so that
         * we can capture its operation time with commandSucceeded(). */
        \MongoDB\Driver\Monitoring\addSubscriber($this);

        try {
            return $this->aggregate->execute($server);
        } finally {
            \MongoDB\Driver\Monitoring\removeSubscriber($this);
        }
    }
496439
private function withHost(UriInterface $uri, array $server) : UriInterface {
		if (isset($server['HTTP_HOST'])) {
			$server['HTTP_HOST'] = preg_replace('/:[0-9]+$/', '', $server['HTTP_HOST']);
			return $uri->withHost($server['HTTP_HOST']);
		} elseif (isset($server['SERVER_NAME'])) {
			return $uri->withHost($server['SERVER_NAME']);
		}

		return $uri;
	}
278917
public function dump(Config $config)
    {
        $ignored = [
            'commands',
        ];

        $ignored = array_fill_keys($ignored, true);

        $output = '';

        $a = [];
        foreach ($config as $key => $value) {
            if (isset($ignored[$key])) {
                continue;
            }

            if ('uses' === $key) {
                $value = array_keys($value);
                $key = 'extensions';
            }

            $a[$key] = $value;
        }

        ksort($a);

        foreach ($a as $key => $value) {
            if ('_' === $key{0}) {
                continue;
            }
            $output .= sprintf(
                'export %s="%s"%s',
                $this->formatEnvironmentVariableName($key),
                $this->formatEnvironmentVariableValue($value),
                PHP_EOL
            );
        }

        return $output;
    }
1143430
protected function doParseResponse(Server $server)
    {

        try {
            // @codeCoverageIgnoreStart
            // We want to save this server's response to a file (useful for unit testing)
            if (!is_null($this->capture_packets_file)) {
                file_put_contents(
                    $this->capture_packets_file,
                    implode(PHP_EOL . '||' . PHP_EOL, $server->protocol()->packetResponse())
                );
            }
            // @codeCoverageIgnoreEnd

            // Get the server response
            $results = $server->protocol()->processResponse();

            // Check for online before we do anything else
            $results['gq_online'] = (count($results) > 0);
        } catch (ProtocolException $e) {
            // Check to see if we are in debug, if so bubble up the exception
            if ($this->debug) {
                throw new \Exception($e->getMessage(), $e->getCode(), $e);
            }

            // We ignore this server
            $results = [
                'gq_online' => false,
            ];
        }

        // Now add some default stuff
        $results['gq_address'] = (isset($results['gq_address'])) ? $results['gq_address'] : $server->ip();
        $results['gq_port_client'] = $server->portClient();
        $results['gq_port_query'] = (isset($results['gq_port_query'])) ? $results['gq_port_query'] : $server->portQuery();
        $results['gq_protocol'] = $server->protocol()->getProtocol();
        $results['gq_type'] = (string)$server->protocol();
        $results['gq_name'] = $server->protocol()->nameLong();
        $results['gq_transport'] = $server->protocol()->transport();

        // Process the join link
        if (!isset($results['gq_joinlink']) || empty($results['gq_joinlink'])) {
            $results['gq_joinlink'] = $server->getJoinLink();
        }

        return $results;
    }
854793
public function dump(InputInterface $input, OutputInterface $output) {
    $this->input = $input;
    $this->output = $output;
    $formatter_style = new OutputFormatterStyle('black', 'cyan', []);
    $this->output->getFormatter()->setStyle('title', $formatter_style);

    $interactive = $input->isInteractive();

    // NULL means we should ask user for confirmation.
    if ($this->replace !== NULL) {
      $input->setInteractive(FALSE);
    }

    /** @var \DrupalCodeGenerator\Command\GeneratorInterface $command */
    $command = $this->getHelperSet()->getCommand();

    $dumped_files = $this->doDump($command->getAssets(), $command->getDirectory());

    $input->setInteractive($interactive);
    return $dumped_files;
  }
273949
public static function objectToMarkup($object, $key, $spaces = 0, $indent = 2)
    {
        $spacesStr = str_repeat(' ', $spaces);
        $markup = $spacesStr . self::DIV_START_NOTRANSLATE;
        $markup .= self::toHtml(
            $object,
            SerializationHelper::toSnakeCase($key),
            $spaces + $indent,
            $indent,
            self::STYLE_DISPLAY_NONE
        );
        $markup .= $spacesStr . self::DIV_END;
        return $markup;
    }
614028
public static function dumpVars(...$args): string
    {
        \ob_start();
        \var_dump(...$args);
        $string = \ob_get_clean();

        return \preg_replace("/=>\n\s+/", '=> ', $string);
    }