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

ValueObjectVisitorDispatcher.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Common\Output;
8
12 class ValueObjectVisitorDispatcher
13 {
15 private $visitors;
16
18 private $outputVisitor;
19
21 private $outputGenerator;
22
23 public function setOutputVisitor(Visitor $outputVisitor)
24 {
25 $this->outputVisitor = $outputVisitor;
26 }
27
28 public function setOutputGenerator(Generator $outputGenerator)
29 {
30 $this->outputGenerator = $outputGenerator;
31 }
32
37 public function addVisitor($visitedClassName, ValueObjectVisitor $visitor)
38 {
39 $this->visitors[$visitedClassName] = $visitor;
40 }
41
50 public function visit($data)
51 {
52 if (!is_object($data)) {
53 throw new Exceptions\InvalidTypeException($data);
54 }
55 $checkedClassNames = [];
56
57 $className = get_class($data);
58 do {
59 $checkedClassNames[] = $className;
60 if (isset($this->visitors[$className])) {
61 return $this->visitors[$className]->visit($this->outputVisitor, $this->outputGenerator, $data);
62 }
63 } while ($className = get_parent_class($className));
64
65 throw new Exceptions\NoVisitorFoundException($checkedClassNames);
66 }
67 }
eZ\Publish\Core\REST\Common\Output\Exceptions\InvalidTypeException
Output visiting invalid type exception.
Definition: InvalidTypeException.php:15
eZ\Publish\Core\REST\Common\Output\Exceptions\NoVisitorFoundException
No output visitor found exception.
Definition: NoVisitorFoundException.php:15
eZ\Publish\Core\REST\Common\Output\Generator
Output generator.
Definition: REST/Common/Output/Generator.php:13
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher
Dispatches value objects to a visitor depending on the class name.
Definition: ValueObjectVisitorDispatcher.php:13
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher\$outputVisitor
$outputVisitor
Definition: ValueObjectVisitorDispatcher.php:18
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher\addVisitor
addVisitor($visitedClassName, ValueObjectVisitor $visitor)
Definition: ValueObjectVisitorDispatcher.php:37
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher\visit
visit($data)
Definition: ValueObjectVisitorDispatcher.php:50
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher\setOutputGenerator
setOutputGenerator(Generator $outputGenerator)
Definition: ValueObjectVisitorDispatcher.php:28
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher\$outputGenerator
$outputGenerator
Definition: ValueObjectVisitorDispatcher.php:21
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher\$visitors
$visitors
Definition: ValueObjectVisitorDispatcher.php:15
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher\setOutputVisitor
setOutputVisitor(Visitor $outputVisitor)
Definition: ValueObjectVisitorDispatcher.php:23
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
Basic ValueObjectVisitor.
Definition: ValueObjectVisitor.php:18
eZ\Publish\Core\REST\Common\Output\Visitor
Visits a value object into an HTTP Response.
Definition: Visitor.php:15
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.