Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

AcceptHeaderVisitorDispatcher.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\View;
8
9 use Symfony\Component\HttpFoundation\Request;
10 use eZ\Publish\Core\REST\Common\Output\Visitor as OutputVisitor;
11 use Symfony\Component\HttpFoundation\Response;
12 use RuntimeException;
13
17 class AcceptHeaderVisitorDispatcher
18 {
25 protected $mapping = [];
26
33 public function addVisitor($regexp, OutputVisitor $visitor)
34 {
35 $this->mapping[$regexp] = $visitor;
36 }
37
48 public function dispatch(Request $request, $result)
49 {
50 foreach ($request->getAcceptableContentTypes() as $mimeType) {
52 foreach ($this->mapping as $regexp => $visitor) {
53 if (preg_match($regexp, $mimeType)) {
54 return $visitor->visit($result);
55 }
56 }
57 }
58
59 throw new RuntimeException('No view mapping found.');
60 }
61 }
eZ\Publish\Core\REST\Common\Output\Visitor
Visits a value object into an HTTP Response.
Definition: Visitor.php:15
eZ\Publish\Core\REST\Server\View\AcceptHeaderVisitorDispatcher
Dispatcher for various visitors depending on the mime-type accept header.
Definition: AcceptHeaderVisitorDispatcher.php:18
eZ\Publish\Core\REST\Server\View\AcceptHeaderVisitorDispatcher\addVisitor
addVisitor($regexp, OutputVisitor $visitor)
Adds view handler.
Definition: AcceptHeaderVisitorDispatcher.php:33
eZ\Publish\Core\REST\Server\View\AcceptHeaderVisitorDispatcher\$mapping
$mapping
Definition: AcceptHeaderVisitorDispatcher.php:25
eZ\Publish\Core\REST\Server\View
Definition: AcceptHeaderVisitorDispatcher.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.