| 148 |
lars |
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(mixed $value)
|
|
|
24 |
{
|
|
|
25 |
$this->value = $value;
|
|
|
26 |
|
|
|
27 |
switch (\gettype($value)) {
|
|
|
28 |
case 'object':
|
|
|
29 |
$this->type = self::TYPE_OBJECT;
|
|
|
30 |
$this->class = $value::class;
|
|
|
31 |
|
|
|
32 |
if ($value instanceof \Closure) {
|
|
|
33 |
ReflectionCaster::castClosure($value, [], $this, true, Caster::EXCLUDE_VERBOSE);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
$this->cut = -1;
|
|
|
37 |
break;
|
|
|
38 |
|
|
|
39 |
case 'array':
|
|
|
40 |
$this->type = self::TYPE_ARRAY;
|
|
|
41 |
$this->class = self::ARRAY_ASSOC;
|
|
|
42 |
$this->cut = $this->value = \count($value);
|
|
|
43 |
break;
|
|
|
44 |
|
|
|
45 |
case 'resource':
|
|
|
46 |
case 'unknown type':
|
|
|
47 |
case 'resource (closed)':
|
|
|
48 |
$this->type = self::TYPE_RESOURCE;
|
|
|
49 |
$this->handle = (int) $value;
|
|
|
50 |
if ('Unknown' === $this->class = @get_resource_type($value)) {
|
|
|
51 |
$this->class = 'Closed';
|
|
|
52 |
}
|
|
|
53 |
$this->cut = -1;
|
|
|
54 |
break;
|
|
|
55 |
|
|
|
56 |
case 'string':
|
|
|
57 |
$this->type = self::TYPE_STRING;
|
|
|
58 |
$this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
|
|
|
59 |
$this->cut = self::STRING_BINARY === $this->class ? \strlen($value) : mb_strlen($value, 'UTF-8');
|
|
|
60 |
$this->value = '';
|
|
|
61 |
break;
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
}
|