PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / sebastian / comparator / src / Factory.php
kubio / vendor / sebastian / comparator / src Last commit date
exceptions 1 year ago ArrayComparator.php 1 year ago Comparator.php 1 year ago ComparisonFailure.php 1 year ago DOMNodeComparator.php 1 year ago DateTimeComparator.php 1 year ago DoubleComparator.php 1 year ago ExceptionComparator.php 1 year ago Factory.php 1 year ago MockObjectComparator.php 1 year ago NumericComparator.php 1 year ago ObjectComparator.php 1 year ago ResourceComparator.php 1 year ago ScalarComparator.php 1 year ago SplObjectStorageComparator.php 1 year ago TypeComparator.php 1 year ago
Factory.php
142 lines
1 <?php declare(strict_types=1);
2 /*
3 * This file is part of sebastian/comparator.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10 namespace SebastianBergmann\Comparator;
11
12 use function array_unshift;
13
14 /**
15 * Factory for comparators which compare values for equality.
16 */
17 class Factory
18 {
19 /**
20 * @var Factory
21 */
22 private static $instance;
23
24 /**
25 * @var Comparator[]
26 */
27 private $customComparators = [];
28
29 /**
30 * @var Comparator[]
31 */
32 private $defaultComparators = [];
33
34 /**
35 * @return Factory
36 */
37 public static function getInstance()
38 {
39 if (self::$instance === null) {
40 self::$instance = new self; // @codeCoverageIgnore
41 }
42
43 return self::$instance;
44 }
45
46 /**
47 * Constructs a new factory.
48 */
49 public function __construct()
50 {
51 $this->registerDefaultComparators();
52 }
53
54 /**
55 * Returns the correct comparator for comparing two values.
56 *
57 * @param mixed $expected The first value to compare
58 * @param mixed $actual The second value to compare
59 *
60 * @return Comparator
61 */
62 public function getComparatorFor($expected, $actual)
63 {
64 foreach ($this->customComparators as $comparator) {
65 if ($comparator->accepts($expected, $actual)) {
66 return $comparator;
67 }
68 }
69
70 foreach ($this->defaultComparators as $comparator) {
71 if ($comparator->accepts($expected, $actual)) {
72 return $comparator;
73 }
74 }
75
76 throw new RuntimeException('No suitable Comparator implementation found');
77 }
78
79 /**
80 * Registers a new comparator.
81 *
82 * This comparator will be returned by getComparatorFor() if its accept() method
83 * returns TRUE for the compared values. It has higher priority than the
84 * existing comparators, meaning that its accept() method will be invoked
85 * before those of the other comparators.
86 *
87 * @param Comparator $comparator The comparator to be registered
88 */
89 public function register(Comparator $comparator)/*: void*/
90 {
91 array_unshift($this->customComparators, $comparator);
92
93 $comparator->setFactory($this);
94 }
95
96 /**
97 * Unregisters a comparator.
98 *
99 * This comparator will no longer be considered by getComparatorFor().
100 *
101 * @param Comparator $comparator The comparator to be unregistered
102 */
103 public function unregister(Comparator $comparator)/*: void*/
104 {
105 foreach ($this->customComparators as $key => $_comparator) {
106 if ($comparator === $_comparator) {
107 unset($this->customComparators[$key]);
108 }
109 }
110 }
111
112 /**
113 * Unregisters all non-default comparators.
114 */
115 public function reset()/*: void*/
116 {
117 $this->customComparators = [];
118 }
119
120 private function registerDefaultComparators(): void
121 {
122 $this->registerDefaultComparator(new MockObjectComparator);
123 $this->registerDefaultComparator(new DateTimeComparator);
124 $this->registerDefaultComparator(new DOMNodeComparator);
125 $this->registerDefaultComparator(new SplObjectStorageComparator);
126 $this->registerDefaultComparator(new ExceptionComparator);
127 $this->registerDefaultComparator(new ObjectComparator);
128 $this->registerDefaultComparator(new ResourceComparator);
129 $this->registerDefaultComparator(new ArrayComparator);
130 $this->registerDefaultComparator(new NumericComparator);
131 $this->registerDefaultComparator(new ScalarComparator);
132 $this->registerDefaultComparator(new TypeComparator);
133 }
134
135 private function registerDefaultComparator(Comparator $comparator): void
136 {
137 $this->defaultComparators[] = $comparator;
138
139 $comparator->setFactory($this);
140 }
141 }
142