예제 #1
0
 public function __invoke(Request\RequestInterface $request)
 {
     if ($request instanceof Request\HttpInterface) {
         if (isset($this->types[$type = $request->getUri()->getSuffix()])) {
             $renderer = $this->types[$type];
         } elseif (isset($this->types[$type = $request->accepts(array_keys($this->types))])) {
             $renderer = $this->types[$type];
         }
     }
     if (!isset($renderer)) {
         $renderer = $this->fallback;
     }
     if (!isset($renderer)) {
         throw new Exception\NotNegotiable(['request' => $request]);
     }
     return $renderer;
 }
예제 #2
0
 public function __invoke(RequestInterface $request)
 {
     $view = null;
     // We only negotiate a content type if the request is using Http.
     if ($request instanceof Http) {
         $method = null;
         // Specifying a suffix overrides the Accept header.
         if ($suffix = $request->getUri()->getSuffix()) {
             $method = $this->config->suffixMap[$suffix];
         } elseif ($type = $request->accepts(array_keys($this->config->typeMap->export()))) {
             $method = $this->config->typeMap[$type];
         }
         // Only render a different view if one exists.
         if ($method && method_exists($this, $method)) {
             $view = $this->{$method}($request);
         }
     }
     // Default to using a PHP view.
     if (!$view) {
         $view = $this->resolvePhp($request);
     }
     return $view;
 }