comparison vendor/symfony/var-dumper/Caster/Caster.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
47 * @return array The array-cast of the object, with prefixed dynamic properties 47 * @return array The array-cast of the object, with prefixed dynamic properties
48 */ 48 */
49 public static function castObject($obj, $class, $hasDebugInfo = false) 49 public static function castObject($obj, $class, $hasDebugInfo = false)
50 { 50 {
51 if ($class instanceof \ReflectionClass) { 51 if ($class instanceof \ReflectionClass) {
52 @trigger_error(sprintf('Passing a ReflectionClass to %s() is deprecated since Symfony 3.3 and will be unsupported in 4.0. Pass the class name as string instead.', __METHOD__), E_USER_DEPRECATED); 52 @trigger_error(sprintf('Passing a ReflectionClass to "%s()" is deprecated since Symfony 3.3 and will be unsupported in 4.0. Pass the class name as string instead.', __METHOD__), E_USER_DEPRECATED);
53 $hasDebugInfo = $class->hasMethod('__debugInfo'); 53 $hasDebugInfo = $class->hasMethod('__debugInfo');
54 $class = $class->name; 54 $class = $class->name;
55 } 55 }
56 if ($hasDebugInfo) { 56 if ($hasDebugInfo) {
57 $a = $obj->__debugInfo(); 57 $a = $obj->__debugInfo();
58 } elseif ($obj instanceof \Closure) { 58 } elseif ($obj instanceof \Closure) {
59 $a = array(); 59 $a = [];
60 } else { 60 } else {
61 $a = (array) $obj; 61 $a = (array) $obj;
62 } 62 }
63 if ($obj instanceof \__PHP_Incomplete_Class) { 63 if ($obj instanceof \__PHP_Incomplete_Class) {
64 return $a; 64 return $a;
65 } 65 }
66 66
67 if ($a) { 67 if ($a) {
68 static $publicProperties = array(); 68 static $publicProperties = [];
69 69
70 $i = 0; 70 $i = 0;
71 $prefixedKeys = array(); 71 $prefixedKeys = [];
72 foreach ($a as $k => $v) { 72 foreach ($a as $k => $v) {
73 if (isset($k[0]) ? "\0" !== $k[0] : \PHP_VERSION_ID >= 70200) { 73 if (isset($k[0]) ? "\0" !== $k[0] : \PHP_VERSION_ID >= 70200) {
74 if (!isset($publicProperties[$class])) { 74 if (!isset($publicProperties[$class])) {
75 foreach (get_class_vars($class) as $prop => $v) { 75 foreach (get_class_vars($class) as $prop => $v) {
76 $publicProperties[$class][$prop] = true; 76 $publicProperties[$class][$prop] = true;
107 * @param string[] $listedProperties List of properties to exclude when Caster::EXCLUDE_VERBOSE is set, and to preserve when Caster::EXCLUDE_NOT_IMPORTANT is set 107 * @param string[] $listedProperties List of properties to exclude when Caster::EXCLUDE_VERBOSE is set, and to preserve when Caster::EXCLUDE_NOT_IMPORTANT is set
108 * @param int &$count Set to the number of removed properties 108 * @param int &$count Set to the number of removed properties
109 * 109 *
110 * @return array The filtered array 110 * @return array The filtered array
111 */ 111 */
112 public static function filter(array $a, $filter, array $listedProperties = array(), &$count = 0) 112 public static function filter(array $a, $filter, array $listedProperties = [], &$count = 0)
113 { 113 {
114 $count = 0; 114 $count = 0;
115 115
116 foreach ($a as $k => $v) { 116 foreach ($a as $k => $v) {
117 $type = self::EXCLUDE_STRICT & $filter; 117 $type = self::EXCLUDE_STRICT & $filter;
118 118
119 if (null === $v) { 119 if (null === $v) {
120 $type |= self::EXCLUDE_NULL & $filter; 120 $type |= self::EXCLUDE_NULL & $filter;
121 $type |= self::EXCLUDE_EMPTY & $filter; 121 $type |= self::EXCLUDE_EMPTY & $filter;
122 } elseif (false === $v || '' === $v || '0' === $v || 0 === $v || 0.0 === $v || array() === $v) { 122 } elseif (false === $v || '' === $v || '0' === $v || 0 === $v || 0.0 === $v || [] === $v) {
123 $type |= self::EXCLUDE_EMPTY & $filter; 123 $type |= self::EXCLUDE_EMPTY & $filter;
124 } 124 }
125 if ((self::EXCLUDE_NOT_IMPORTANT & $filter) && !in_array($k, $listedProperties, true)) { 125 if ((self::EXCLUDE_NOT_IMPORTANT & $filter) && !\in_array($k, $listedProperties, true)) {
126 $type |= self::EXCLUDE_NOT_IMPORTANT; 126 $type |= self::EXCLUDE_NOT_IMPORTANT;
127 } 127 }
128 if ((self::EXCLUDE_VERBOSE & $filter) && in_array($k, $listedProperties, true)) { 128 if ((self::EXCLUDE_VERBOSE & $filter) && \in_array($k, $listedProperties, true)) {
129 $type |= self::EXCLUDE_VERBOSE; 129 $type |= self::EXCLUDE_VERBOSE;
130 } 130 }
131 131
132 if (!isset($k[1]) || "\0" !== $k[0]) { 132 if (!isset($k[1]) || "\0" !== $k[0]) {
133 $type |= self::EXCLUDE_PUBLIC & $filter; 133 $type |= self::EXCLUDE_PUBLIC & $filter;