PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / var-dumper / Caster / Caster.php
matomo / app / vendor / prefixed / symfony / var-dumper / Caster Last commit date
AmqpCaster.php 2 years ago ArgsStub.php 1 year ago Caster.php 1 year ago ClassStub.php 1 year ago ConstStub.php 2 years ago CutArrayStub.php 2 years ago CutStub.php 1 year ago DOMCaster.php 1 year ago DateCaster.php 2 years ago DoctrineCaster.php 2 years ago DsCaster.php 2 years ago DsPairStub.php 2 years ago EnumStub.php 1 year ago ExceptionCaster.php 1 year ago FiberCaster.php 2 years ago FrameStub.php 1 year ago GmpCaster.php 2 years ago ImagineCaster.php 2 years ago ImgStub.php 2 years ago IntlCaster.php 2 years ago LinkStub.php 1 year ago MemcachedCaster.php 2 years ago MysqliCaster.php 2 years ago PdoCaster.php 2 years ago PgSqlCaster.php 1 year ago ProxyManagerCaster.php 2 years ago RdKafkaCaster.php 1 year ago RedisCaster.php 2 years ago ReflectionCaster.php 1 year ago ResourceCaster.php 1 year ago SplCaster.php 1 year ago StubCaster.php 2 years ago SymfonyCaster.php 2 years ago TraceStub.php 1 year ago UuidCaster.php 2 years ago XmlReaderCaster.php 1 year ago XmlResourceCaster.php 2 years ago
Caster.php
152 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Matomo\Dependencies\Symfony\Component\VarDumper\Caster;
12
13 use Matomo\Dependencies\Symfony\Component\VarDumper\Cloner\Stub;
14 /**
15 * Helper for filtering out properties in casters.
16 *
17 * @author Nicolas Grekas <p@tchwork.com>
18 *
19 * @final
20 */
21 class Caster
22 {
23 public const EXCLUDE_VERBOSE = 1;
24 public const EXCLUDE_VIRTUAL = 2;
25 public const EXCLUDE_DYNAMIC = 4;
26 public const EXCLUDE_PUBLIC = 8;
27 public const EXCLUDE_PROTECTED = 16;
28 public const EXCLUDE_PRIVATE = 32;
29 public const EXCLUDE_NULL = 64;
30 public const EXCLUDE_EMPTY = 128;
31 public const EXCLUDE_NOT_IMPORTANT = 256;
32 public const EXCLUDE_STRICT = 512;
33 public const PREFIX_VIRTUAL = "\x00~\x00";
34 public const PREFIX_DYNAMIC = "\x00+\x00";
35 public const PREFIX_PROTECTED = "\x00*\x00";
36 /**
37 * Casts objects to arrays and adds the dynamic property prefix.
38 *
39 * @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
40 */
41 public static function castObject(object $obj, string $class, bool $hasDebugInfo = \false, ?string $debugClass = null) : array
42 {
43 if ($hasDebugInfo) {
44 try {
45 $debugInfo = $obj->__debugInfo();
46 } catch (\Throwable $e) {
47 // ignore failing __debugInfo()
48 $hasDebugInfo = \false;
49 }
50 }
51 $a = $obj instanceof \Closure ? [] : (array) $obj;
52 if ($obj instanceof \__PHP_Incomplete_Class) {
53 return $a;
54 }
55 if ($a) {
56 static $publicProperties = [];
57 $debugClass = $debugClass ?? get_debug_type($obj);
58 $i = 0;
59 $prefixedKeys = [];
60 foreach ($a as $k => $v) {
61 if ("\x00" !== ($k[0] ?? '')) {
62 if (!isset($publicProperties[$class])) {
63 foreach ((new \ReflectionClass($class))->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
64 $publicProperties[$class][$prop->name] = \true;
65 }
66 }
67 if (!isset($publicProperties[$class][$k])) {
68 $prefixedKeys[$i] = self::PREFIX_DYNAMIC . $k;
69 }
70 } elseif ($debugClass !== $class && 1 === strpos($k, $class)) {
71 $prefixedKeys[$i] = "\x00" . $debugClass . strrchr($k, "\x00");
72 }
73 ++$i;
74 }
75 if ($prefixedKeys) {
76 $keys = array_keys($a);
77 foreach ($prefixedKeys as $i => $k) {
78 $keys[$i] = $k;
79 }
80 $a = array_combine($keys, $a);
81 }
82 }
83 if ($hasDebugInfo && \is_array($debugInfo)) {
84 foreach ($debugInfo as $k => $v) {
85 if (!isset($k[0]) || "\x00" !== $k[0]) {
86 if (\array_key_exists(self::PREFIX_DYNAMIC . $k, $a)) {
87 continue;
88 }
89 $k = self::PREFIX_VIRTUAL . $k;
90 }
91 unset($a[$k]);
92 $a[$k] = $v;
93 }
94 }
95 return $a;
96 }
97 /**
98 * Filters out the specified properties.
99 *
100 * By default, a single match in the $filter bit field filters properties out, following an "or" logic.
101 * When EXCLUDE_STRICT is set, an "and" logic is applied: all bits must match for a property to be removed.
102 *
103 * @param array $a The array containing the properties to filter
104 * @param int $filter A bit field of Caster::EXCLUDE_* constants specifying which properties to filter out
105 * @param string[] $listedProperties List of properties to exclude when Caster::EXCLUDE_VERBOSE is set, and to preserve when Caster::EXCLUDE_NOT_IMPORTANT is set
106 * @param int|null &$count Set to the number of removed properties
107 */
108 public static function filter(array $a, int $filter, array $listedProperties = [], ?int &$count = 0) : array
109 {
110 $count = 0;
111 foreach ($a as $k => $v) {
112 $type = self::EXCLUDE_STRICT & $filter;
113 if (null === $v) {
114 $type |= self::EXCLUDE_NULL & $filter;
115 $type |= self::EXCLUDE_EMPTY & $filter;
116 } elseif (\false === $v || '' === $v || '0' === $v || 0 === $v || 0.0 === $v || [] === $v) {
117 $type |= self::EXCLUDE_EMPTY & $filter;
118 }
119 if (self::EXCLUDE_NOT_IMPORTANT & $filter && !\in_array($k, $listedProperties, \true)) {
120 $type |= self::EXCLUDE_NOT_IMPORTANT;
121 }
122 if (self::EXCLUDE_VERBOSE & $filter && \in_array($k, $listedProperties, \true)) {
123 $type |= self::EXCLUDE_VERBOSE;
124 }
125 if (!isset($k[1]) || "\x00" !== $k[0]) {
126 $type |= self::EXCLUDE_PUBLIC & $filter;
127 } elseif ('~' === $k[1]) {
128 $type |= self::EXCLUDE_VIRTUAL & $filter;
129 } elseif ('+' === $k[1]) {
130 $type |= self::EXCLUDE_DYNAMIC & $filter;
131 } elseif ('*' === $k[1]) {
132 $type |= self::EXCLUDE_PROTECTED & $filter;
133 } else {
134 $type |= self::EXCLUDE_PRIVATE & $filter;
135 }
136 if (self::EXCLUDE_STRICT & $filter ? $type === $filter : $type) {
137 unset($a[$k]);
138 ++$count;
139 }
140 }
141 return $a;
142 }
143 public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, bool $isNested) : array
144 {
145 if (isset($a['__PHP_Incomplete_Class_Name'])) {
146 $stub->class .= '(' . $a['__PHP_Incomplete_Class_Name'] . ')';
147 unset($a['__PHP_Incomplete_Class_Name']);
148 }
149 return $a;
150 }
151 }
152