Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\VarDumper\Caster; Chris@0: Chris@0: use Symfony\Component\VarDumper\Cloner\Stub; Chris@0: Chris@0: /** Chris@0: * Represents the main properties of a PHP variable, pre-casted by a caster. Chris@0: * Chris@0: * @author Nicolas Grekas
Chris@0: */ Chris@0: class CutStub extends Stub Chris@0: { Chris@0: public function __construct($value) Chris@0: { Chris@0: $this->value = $value; Chris@0: Chris@17: switch (\gettype($value)) { Chris@0: case 'object': Chris@0: $this->type = self::TYPE_OBJECT; Chris@17: $this->class = \get_class($value); Chris@0: $this->cut = -1; Chris@0: break; Chris@0: Chris@0: case 'array': Chris@0: $this->type = self::TYPE_ARRAY; Chris@0: $this->class = self::ARRAY_ASSOC; Chris@17: $this->cut = $this->value = \count($value); Chris@0: break; Chris@0: Chris@0: case 'resource': Chris@0: case 'unknown type': Chris@0: case 'resource (closed)': Chris@0: $this->type = self::TYPE_RESOURCE; Chris@0: $this->handle = (int) $value; Chris@0: if ('Unknown' === $this->class = @get_resource_type($value)) { Chris@0: $this->class = 'Closed'; Chris@0: } Chris@0: $this->cut = -1; Chris@0: break; Chris@0: Chris@0: case 'string': Chris@0: $this->type = self::TYPE_STRING; Chris@0: $this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY; Chris@17: $this->cut = self::STRING_BINARY === $this->class ? \strlen($value) : mb_strlen($value, 'UTF-8'); Chris@0: $this->value = ''; Chris@0: break; Chris@0: } Chris@0: } Chris@0: }