Crummy\Phlack\Bridge\Symfony\HttpFoundation\RequestConverter::convert PHP Method

convert() public method

public convert ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function convert(Request $request)
    {
        try {
            $parameters = $request->request->all();
            if (array_key_exists('command', $parameters)) {
                return new SlashCommand($parameters);
            } elseif (empty($parameters)) {
                $parameters = $request->query->all();
            }
            return new WebHook($parameters);
        } catch (\Exception $exception) {
            throw new UnexpectedValueException('Request could not be converted.', 0, $exception);
        }
    }

Usage Example

Example #1
0
 /**
  * Mediates Request handling between HttpKernelInterface and the Mainframe.
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $command = $this->converter->convert($request);
     $packet = $this->mainframe->execute($command);
     $content = $packet['output'];
     if ($command instanceof SlashCommand && $content instanceof Reply) {
         $content = $content->get('text');
     }
     return new Response($content);
 }
RequestConverter