Debug HTTP interactions

@param Client          $client
@param OutputInterface $output
344371
protected function logHttp(Client $client, OutputInterface $output)
    {
        $guzzle = $client->getHttpClient();
        if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
            $logger = function ($message) use ($output) {
                $finfo = new \finfo(FILEINFO_MIME);
                $msg = ('text' == substr($finfo->buffer($message), 0, 4)) ? $message : '(binary string)';
                $output->writeln('<info>Guzzle</info> ' . $msg);
            };
            $logAdapter = new ClosureLogAdapter($logger);
            $logPlugin = new LogPlugin($logAdapter, MessageFormatter::DEBUG_FORMAT);
            $guzzle->addSubscriber($logPlugin);
        }
    }
415281
public function runTransient(InputInterface $input=null,
        OutputInterface $output=null
    ) {
        foreach ($this->getEnvironmentMessages() as $message => $style) {
            $this->printLn($message, $style);
        }
    }
526380
public static function register($client = null)
    {
        $handler = new static($client instanceof Client ? $client : Client::make($client));

        $handler->registerBugsnagHandlers(false); // don't preserve previous handlers

        return $handler;
    }
1348281
private function assert(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response, string $method, string $body = null)
    {
        $client->sendRequest($request)->shouldBeCalled()->willReturn($response);
        $this->mockFactory($requestFactory, $request, strtoupper($method), $body);

        $this->$method(self::$requestData['uri'], self::$requestData['headers'], self::$requestData['body'])->shouldReturnAnInstanceOf(ResponseInterface::class);
    }
1082923
public function refreshSpaceCache(Client $client): void
    {
        $spacePath = $this->getSpaceCachePath($client);
        $this->fileSystem->dumpFile($spacePath . '/space.json', (string) json_encode($client->getSpace()));
    }
1165065
private function debug(
        HttpAdapterInterface $httpAdapter,
        InternalRequestInterface $request,
        ResponseInterface $response
    ) {
        $request = $this->getTimer()->stop($request);

        $this->logger->debug(
            sprintf(
                'Send "%s %s" in %.2f ms.',
                $request->getMethod(),
                (string) $request->getUri(),
                $request->getParameter(TimerInterface::TIME)
            ),
            [
                'adapter'  => $httpAdapter->getName(),
                'request'  => $this->getFormatter()->formatRequest($request),
                'response' => $this->getFormatter()->formatResponse($response),
            ]
        );

        return $request;
    }
1305824
public function execute(InputInterface $input, OutputInterface $output)
    {
        chdir('public');

        /*
         * check for user supplied hostname option
         */
        if ($input->hasOption('hostname') && $input->getOption('hostname') != null) {
            $this->hostname = $input->getOption('hostname');
        }

        /*
         * check for user supplied port option
         */
        if ($input->hasOption('port') && $input->getOption('port') != null) {
            $this->port = $input->getOption('port');
        }

        /*
         * check for user supplied a path option
         */
        if ($input->hasOption('path') && $input->getOption('path') != null) {
            $this->phpexec = $input->getOption('path');
        }

        $output->writeln('<info>Legato development server started</info>');
        $output->writeln("<info>Open your browser and navigate to: </info> <http://{$this->hostname}:{$this->port}>");
        $output->writeln('<info>CTRL C to quit </info>');
        passthru($this->startPHP());
    }
515278
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
        $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
        $errOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL);

        $interval = NumberUtils::bound($input->getOption('interval'), 1, 60);
        $context = json_decode($input->getOption('context') ?: '{}', true);
        $context['tenant_id'] = (string)$input->getOption('tenant-id');
        $streamId = StreamId::fromString($input->getArgument('stream-id'));

        $eventStore = $this->getPbjx()->getEventStore();
        $since = Microtime::create();

        while (true) {
            $event = null;
            $slice = $eventStore->getStreamSlice($streamId, $since, 25, true, false, $context);

            foreach ($slice as $event) {
                try {
                    echo json_encode($event) . PHP_EOL;
                } catch (\Throwable $e) {
                    $errOutput->writeln($e->getMessage());
                }
            }

            if ($event instanceof Event) {
                $since = $event->get('occurred_at');
            }

            sleep($interval);
        }
    }
168860
private function validate_client($client)
    {
        if (!isset($client->{"name"}))
            throw new \Exception("'client' has no 'name'!");
        if (!isset($client->{"queues"}))
            throw new \Exception("'client' has no 'queues'!");
        if (!isset($client->{"queues"}->{'input'}))
            throw new \Exception("'client' has no 'input' queue!");
        if (!isset($client->{"queues"}->{'output'}))
            throw new \Exception("'client' has no 'output' queue !");
    }
1157482
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Start generating...');
        $generated = $this->getFacade()->generateDataProvider();

        if ($output->isVerbose()) {
            foreach ($generated as $provider) {
                $output->writeln($provider . ' generated');
            }
        }
    }
22943
protected function interact(InputInterface $input, OutputInterface $output)
    {
        parent::interact($input, $output);

        // Fill up questions
        if (Context::get('information-collector')->hasMissingInformation()) {
            $questions = Context::get('information-collector')->getInteractiveQuestions();
            $this->getOutput()->writeSmallTitle('Information collect ('.count($questions).' questions)');
            $this->getOutput()->indent();
            $count = 1;
            foreach ($questions as $name => $question) {
                $answer = $this->getOutput()->askQuestion($question, $count++, $this->input);
                Context::get('information-collector')->setValueFor($name, $answer);
                $this->getOutput()->writeEmptyLine();
            }
            $this->getOutput()->unIndent();
        }
    }
854520
public function setOutput(OutputInterface $output)
    {
        $this->output = $output;
        $this->stdErr = $output instanceof ConsoleOutputInterface
            ? $output->getErrorOutput()
            : $output;
    }
871054
public function refreshContentTypeCache(Client $client): void
    {
        $spacePath = $this->getSpaceCachePath($client);
        $contentTypes = $client->getContentTypes();
        foreach ($contentTypes as $contentType) {
            $this->fileSystem->dumpFile($spacePath . '/ct-' . $contentType->getId() . '.json', (string) json_encode($contentType));
        }
    }
400343
public function refresh(Client $client)
    {
        $clientId = $client->getId();
        $this->clients[$clientId] = $client;
        $this->removeClientForRequest($clientId, $client->getPreviousRequest());

        $requestId = $client->getRequest();
        if ($requestId  !== null) {
            if (!isset($this->requests[$requestId])) {
                $this->requests[$requestId] = array();
            }
            $this->requests[$requestId][$clientId] = $client;
            $this->clientRequest[$clientId] = $requestId;
        }

        return $this;
    }
342961
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->cacheService->system()->clear();
        $this->cacheService->user()->clear();
        $output->writeln('Done!');
        return null;
    }
189224
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!$this->apiHelper->restore($this->getHelper('question'), $input, $output)) {
            return;
        }

        $output->writeln(\sprintf('Checking for URL: <info>%s</info>', $this->getUrl()).PHP_EOL);

        /** @var QuestionHelper $asker */
        $asker = $this->getHelper('question');
        $user = $this->apiHelper->currentUser();

        $enabled = $this->getCallbackStatus($user);
        $question = new ConfirmationQuestion(
            sprintf(
                '%s [y/N]: ',
                $enabled
                    ? 'The callback is currently <info>ACTIVE</info>, would you like to disable?'
                    : 'The callback is currently <info>INACTIVE</info>, would you like to enable?'
            ),
            false
        );

        if (!$asker->ask($input, $output, $question)) {
            return;
        }

        try {
            if ($enabled) {
                $this->disableCallback($user);
            } else {
                $this->enableCallback($user);
            }

            $output->writeln('<info>New status successfully applied.</info>');
        } catch (BunqException $exception) {
            $output->writeln('<error>An error occured while applying new status: '.$exception->getMessage().'</error>');
        }
    }
1170854
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $verbosity = PhpVersions::VERBOSITY_NORMAL;
        $verbosity = $input->getOption('verbose') == 2 ? PhpVersions::VERBOSITY_VERBOSE : $verbosity;
        $verbosity = $input->getOption('verbose') == 3 ? PhpVersions::VERBOSITY_DEBUG : $verbosity;
        $verbosity = $input->getOption('quiet') ? PhpVersions::VERBOSITY_SILENT : $verbosity;
        $phpVersions = new PhpVersions(null, $verbosity);

        $versions = $input->getArgument('php');
        $version = array_shift($versions);
        if (empty($version)) {
            $version = 'latest';
        }

        $info = $phpVersions->getInfo($version);

        $output->write($info['version']);
    }