setMaxItems example


            'Level 1 Item 0',
            [
                // Test setMaxString:                 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                'SHORT',
            ],
        ];

        $cloner = new VarCloner();
        $cloner->setMinDepth(2);
        $cloner->setMaxItems(5);
        $cloner->setMaxString(20);
        $clone = $cloner->cloneVar($data);

        $expected = <<<EOTXT Symfony\Component\VarDumper\Cloner\Data Object ( [data:Symfony\Component\VarDumper\Cloner\Data:private] => Array ( [0] => Array ( [0] => Array ( [2] => 1 ) ) [1] => Array ( [0] => Array ( [2] => 2 ) [1] => Array ( [2] => 3 ) [2] => Array ( [2] => 4 ) [3] => Level 1 Item 0 [4] => Array ( [2] => 5 ) ) [2] => Array ( [0] => Array ( [2] => 6 ) [1] => Array ( [0] => 2 [1] => 7 ) [2] => Array ( [0] => 1 [2] => 0 ) ) [3] => Array ( [0] => Array ( [0] => 1 [2] => 0 ) [1] => Level 2 Item 0 ) [4] => Array ( [0] => Level 2 Item 1 ) [5] => Array ( [0] => Symfony\Component\VarDumper\Cloner\Stub Object ( [type] => 2 [class] => 2 [value] => ABCDEFGHIJKLMNOPQRST [cut] => 6 [handle] => 0 [refCount] => 0 [position] => 0 [attr] => Array ( ) ) [1] => SHORT ) [6] => Array ( [0] => Level 3 Item 0 [1] => Level 3 Item 1 [2] => Level 3 Item 2 [3] => Level 3 Item 3 ) [7] => Array ( [999] => Level 3 Item 4 ) ) [position:Symfony\Component\VarDumper\Cloner\Data:private] => 0 [key:Symfony\Component\VarDumper\Cloner\Data:private] => 0 [maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20 [maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1 [useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1 [context:Symfony\Component\VarDumper\Cloner\Data:private] => Array ( ) )
use Symfony\Component\VarDumper\VarDumper;

$componentRoot = $_SERVER['COMPONENT_ROOT'];

if (!is_file($file = $componentRoot.'/vendor/autoload.php')) {
    $file = $componentRoot.'/../../../../vendor/autoload.php';
}

require $file;

$cloner = new VarCloner();
$cloner->setMaxItems(-1);

$dumper = new CliDumper(null, null, CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_STRING_LENGTH);
$dumper->setColors(false);

VarDumper::setHandler(function D$var) use ($cloner$dumper) {
    $data = $cloner->cloneVar($var)->withRefHandles(false);
    $dumper->dump($data);
});

$server = new DumpServer(getenv('VAR_DUMPER_SERVER'));

public function testHtmlDump()
    {
        if (\ini_get('xdebug.file_link_format') || get_cfg_var('xdebug.file_link_format')) {
            $this->markTestSkipped('A custom file_link_format is defined.');
        }

        $e = $this->getTestException(1);
        ExceptionCaster::$srcContext = -1;

        $cloner = new VarCloner();
        $cloner->setMaxItems(1);
        $dumper = new HtmlDumper();
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $dump = $dumper->dump($cloner->cloneVar($e)->withRefHandles(false), true);

        $expectedDump = <<<'EODUMP' <foo></foo><bar><span class=sf-dump-note>Exception</span> {<samp data-depth=1 class=sf-dump-expanded> #<span class=sf-dump-protected title="Protected property">message</span>: "<span class=sf-dump-str>1</span>" #<span class=sf-dump-protected title="Protected property">code</span>: <span class=sf-dump-num>0</span> #<span class=sf-dump-protected title="Protected property">file</span>: "<span class=sf-dump-str title="%sExceptionCasterTest.php %d characters"><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%e</span>Tests%eCaster%eExceptionCasterTest.php</span>" #<span class=sf-dump-protected title="Protected property">line</span>: <span class=sf-dump-num>%d</span> <span class=sf-dump-meta>trace</span>: {<samp data-depth=2 class=sf-dump-compact> <span class=sf-dump-meta title="%sExceptionCasterTest.php Stack level %d."><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%e</span>Tests%eCaster%eExceptionCasterTest.php</span>:<span class=sf-dump-num>%d</span> &#8230;%d </samp>} </samp>} </bar>
protected function getDump(mixed $data, string|int $key = null, int $filter = 0): ?string
    {
        if (null === $flags = $this->varDumperConfig['flags']) {
            $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
            $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
            $flags |= getenv('DUMP_COMMA_SEPARATOR') ? CliDumper::DUMP_COMMA_SEPARATOR : 0;
        }

        $cloner = new VarCloner();
        $cloner->addCasters($this->varDumperConfig['casters']);
        $cloner->setMaxItems(-1);
        $dumper = new CliDumper(null, null, $flags);
        $dumper->setColors(false);
        $data = $cloner->cloneVar($data$filter)->withRefHandles(false);
        if (null !== $key && null === $data = $data->seek($key)) {
            return null;
        }

        return rtrim($dumper->dump($data, true));
    }

    private function prepareExpectation(mixed $expected, int $filter): string
    {

final class RequestContextProvider implements ContextProviderInterface
{
    private RequestStack $requestStack;
    private VarCloner $cloner;

    public function __construct(RequestStack $requestStack)
    {
        $this->requestStack = $requestStack;
        $this->cloner = new VarCloner();
        $this->cloner->setMaxItems(0);
        $this->cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
    }

    public function getContext(): ?array
    {
        if (null === $request = $this->requestStack->getCurrentRequest()) {
            return null;
        }

        $controller = $request->attributes->get('_controller');

        

    protected function cloneVar(mixed $var): Data
    {
        if ($var instanceof Data) {
            return $var;
        }
        if (!isset($this->cloner)) {
            $this->cloner = new VarCloner();
            $this->cloner->setMaxItems(-1);
            $this->cloner->addCasters($this->getCasters());
        }

        return $this->cloner->cloneVar($var);
    }

    /** * @return callable[] The casters to add to the cloner */
    protected function getCasters()
    {
        
protected function getDump(mixed $data, string|int $key = null, int $filter = 0): ?string
    {
        if (null === $flags = $this->varDumperConfig['flags']) {
            $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
            $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
            $flags |= getenv('DUMP_COMMA_SEPARATOR') ? CliDumper::DUMP_COMMA_SEPARATOR : 0;
        }

        $cloner = new VarCloner();
        $cloner->addCasters($this->varDumperConfig['casters']);
        $cloner->setMaxItems(-1);
        $dumper = new CliDumper(null, null, $flags);
        $dumper->setColors(false);
        $data = $cloner->cloneVar($data$filter)->withRefHandles(false);
        if (null !== $key && null === $data = $data->seek($key)) {
            return null;
        }

        return rtrim($dumper->dump($data, true));
    }

    private function prepareExpectation(mixed $expected, int $filter): string
    {

    protected function cloneVar(mixed $var): Data
    {
        if ($var instanceof Data) {
            return $var;
        }
        if (!isset($this->cloner)) {
            $this->cloner = new VarCloner();
            $this->cloner->setMaxItems(-1);
            $this->cloner->addCasters($this->getCasters());
        }

        return $this->cloner->cloneVar($var);
    }

    /** * @return callable[] The casters to add to the cloner */
    protected function getCasters()
    {
        

final class RequestContextProvider implements ContextProviderInterface
{
    private RequestStack $requestStack;
    private VarCloner $cloner;

    public function __construct(RequestStack $requestStack)
    {
        $this->requestStack = $requestStack;
        $this->cloner = new VarCloner();
        $this->cloner->setMaxItems(0);
        $this->cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
    }

    public function getContext(): ?array
    {
        if (null === $request = $this->requestStack->getCurrentRequest()) {
            return null;
        }

        $controller = $request->attributes->get('_controller');

        
Home | Imprint | This part of the site doesn't use cookies.