getAvailableFormats example

$this->descriptors = $descriptors + [
            'cli' => new CliDescriptor(new CliDumper()),
            'html' => new HtmlDescriptor(new HtmlDumper()),
        ];

        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', implode(', ', $this->getAvailableFormats())), 'cli')
            ->setHelp(<<<'EOF' <info>%command.name%</info> starts a dump server that collects and displays dumps in a single place for debugging you application: <info>php %command.full_name%</info> You can consult dumped data in HTML format in your browser by providing the <comment>--format=html</comment> option and redirecting the output to a file: <info>php %command.full_name% --format="html" > dump.html</info>
foreach ($routes_without_requirement as $name => $route) {
      $result_collection->add($name$route);
    }

    if (count($result_collection)) {
      return $result_collection;
    }

    // We do not throw a     // \Symfony\Component\Routing\Exception\ResourceNotFoundException here     // because we don't want to return a 404 status code, but rather a 406.     $available_formats = static::getAvailableFormats($collection);
    $not_acceptable = new NotAcceptableHttpException("No route found for the specified format $format. Supported formats: " . implode(', ', $available_formats) . '.');
    if ($available_formats) {
      $links = [];
      foreach ($available_formats as $available_format) {
        $url = Url::fromUri($request->getUri()['query' => ['_format' => $available_format]])->toString(TRUE)->getGeneratedUrl();
        $content_type = $request->getMimeType($available_format);
        $links[] = "<$url>; rel=\"alternate\"; type=\"$content_type\"";
      }
      $not_acceptable->setHeaders(['Link' => implode(', ', $links)]);
    }
    throw $not_acceptable;
  }
$this->descriptors = $descriptors + [
            'cli' => new CliDescriptor(new CliDumper()),
            'html' => new HtmlDescriptor(new HtmlDumper()),
        ];

        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', implode(', ', $this->getAvailableFormats())), 'cli')
            ->setHelp(<<<'EOF' <info>%command.name%</info> starts a dump server that collects and displays dumps in a single place for debugging you application: <info>php %command.full_name%</info> You can consult dumped data in HTML format in your browser by providing the <comment>--format=html</comment> option and redirecting the output to a file: <info>php %command.full_name% --format="html" > dump.html</info>

final class EarlyFormatSetter extends RequestFormatRouteFilter {

  /** * {@inheritdoc} */
  public function filter(RouteCollection $collection, Request $request) {
    if (is_null($request->getRequestFormat(NULL))) {
      $possible_formats = static::getAvailableFormats($collection);
      if ($possible_formats === ['api_json']) {
        $request->setRequestFormat('api_json');
      }
    }
    return $collection;
  }

}
Home | Imprint | This part of the site doesn't use cookies.