Drupal investigation

CutStub.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\Caster;
  11. use Symfony\Component\VarDumper\Cloner\Stub;
  12. /**
  13. * Represents the main properties of a PHP variable, pre-casted by a caster.
  14. *
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class CutStub extends Stub
  18. {
  19. public function __construct($value)
  20. {
  21. $this->value = $value;
  22. switch (gettype($value)) {
  23. case 'object':
  24. $this->type = self::TYPE_OBJECT;
  25. $this->class = get_class($value);
  26. $this->cut = -1;
  27. break;
  28. case 'array':
  29. $this->type = self::TYPE_ARRAY;
  30. $this->class = self::ARRAY_ASSOC;
  31. $this->cut = $this->value = count($value);
  32. break;
  33. case 'resource':
  34. case 'unknown type':
  35. case 'resource (closed)':
  36. $this->type = self::TYPE_RESOURCE;
  37. $this->handle = (int) $value;
  38. if ('Unknown' === $this->class = @get_resource_type($value)) {
  39. $this->class = 'Closed';
  40. }
  41. $this->cut = -1;
  42. break;
  43. case 'string':
  44. $this->type = self::TYPE_STRING;
  45. $this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
  46. $this->cut = self::STRING_BINARY === $this->class ? strlen($value) : mb_strlen($value, 'UTF-8');
  47. $this->value = '';
  48. break;
  49. }
  50. }
  51. }