Stub.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\VarDumper\Cloner;
  11. use Symfony\Component\VarDumper\Cloner\Internal\NoDefault;
  12. /**
  13. * Represents the main properties of a PHP variable.
  14. *
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class Stub
  18. {
  19. public const TYPE_REF = 1;
  20. public const TYPE_STRING = 2;
  21. public const TYPE_ARRAY = 3;
  22. public const TYPE_OBJECT = 4;
  23. public const TYPE_RESOURCE = 5;
  24. public const TYPE_SCALAR = 6;
  25. public const STRING_BINARY = 1;
  26. public const STRING_UTF8 = 2;
  27. public const ARRAY_ASSOC = 1;
  28. public const ARRAY_INDEXED = 2;
  29. public int $type = self::TYPE_REF;
  30. public string|int|null $class = '';
  31. public mixed $value = null;
  32. public int $cut = 0;
  33. public int $handle = 0;
  34. public int $refCount = 0;
  35. public int $position = 0;
  36. public array $attr = [];
  37. private static array $defaultProperties = [];
  38. /**
  39. * @internal
  40. */
  41. public function __sleep(): array
  42. {
  43. $properties = [];
  44. if (!isset(self::$defaultProperties[$c = static::class])) {
  45. $reflection = new \ReflectionClass($c);
  46. self::$defaultProperties[$c] = [];
  47. foreach ($reflection->getProperties() as $p) {
  48. if ($p->isStatic()) {
  49. continue;
  50. }
  51. self::$defaultProperties[$c][$p->name] = $p->hasDefaultValue() ? $p->getDefaultValue() : ($p->hasType() ? NoDefault::NoDefault : null);
  52. }
  53. }
  54. foreach (self::$defaultProperties[$c] as $k => $v) {
  55. if (NoDefault::NoDefault === $v || $this->$k !== $v) {
  56. $properties[] = $k;
  57. }
  58. }
  59. return $properties;
  60. }
  61. }