comparison vendor/symfony/var-dumper/Caster/CutStub.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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
12 namespace Symfony\Component\VarDumper\Caster;
13
14 use Symfony\Component\VarDumper\Cloner\Stub;
15
16 /**
17 * Represents the main properties of a PHP variable, pre-casted by a caster.
18 *
19 * @author Nicolas Grekas <p@tchwork.com>
20 */
21 class CutStub extends Stub
22 {
23 public function __construct($value)
24 {
25 $this->value = $value;
26
27 switch (gettype($value)) {
28 case 'object':
29 $this->type = self::TYPE_OBJECT;
30 $this->class = get_class($value);
31 $this->cut = -1;
32 break;
33
34 case 'array':
35 $this->type = self::TYPE_ARRAY;
36 $this->class = self::ARRAY_ASSOC;
37 $this->cut = $this->value = count($value);
38 break;
39
40 case 'resource':
41 case 'unknown type':
42 case 'resource (closed)':
43 $this->type = self::TYPE_RESOURCE;
44 $this->handle = (int) $value;
45 if ('Unknown' === $this->class = @get_resource_type($value)) {
46 $this->class = 'Closed';
47 }
48 $this->cut = -1;
49 break;
50
51 case 'string':
52 $this->type = self::TYPE_STRING;
53 $this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
54 $this->cut = self::STRING_BINARY === $this->class ? strlen($value) : mb_strlen($value, 'UTF-8');
55 $this->value = '';
56 break;
57 }
58 }
59 }