Skip to content

Commit 4338636

Browse files
committed
Split classes, tweak vardumper css
1 parent 1fd5af2 commit 4338636

File tree

4 files changed

+124
-113
lines changed

4 files changed

+124
-113
lines changed

src/DebugBar/DataFormatter/DebugBarVarDumper.php

Lines changed: 3 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
namespace DebugBar\DataFormatter;
44

55
use DebugBar\DataCollector\AssetProvider;
6-
use Symfony\Component\VarDumper\Caster\Caster;
7-
use Symfony\Component\VarDumper\Cloner\Cursor;
6+
use DebugBar\DataFormatter\VarDumper\DebugBarHtmlDumper;
7+
use DebugBar\DataFormatter\VarDumper\SeekingData;
88
use Symfony\Component\VarDumper\Cloner\Data;
9-
use Symfony\Component\VarDumper\Cloner\DumperInterface;
10-
use Symfony\Component\VarDumper\Cloner\Stub;
119
use Symfony\Component\VarDumper\Cloner\VarCloner;
12-
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
1310

1411
/**
1512
* Clones and renders variables in HTML format using the Symfony VarDumper component.
@@ -48,7 +45,7 @@ class DebugBarVarDumper implements AssetProvider
4845
/** @var VarCloner */
4946
protected $cloner;
5047

51-
/** @var DebugBarHtmlDumper */
48+
/** @var Debu */
5249
protected $dumper;
5350

5451
/**
@@ -316,110 +313,3 @@ protected function dump(Data $data)
316313
return $result;
317314
}
318315
}
319-
320-
/**
321-
* We have to extend the base HtmlDumper class in order to get access to the protected-only
322-
* getDumpHeader function.
323-
*/
324-
class DebugBarHtmlDumper extends HtmlDumper
325-
{
326-
public function getDumpHeaderByDebugBar() {
327-
// getDumpHeader is protected:
328-
return $this->getDumpHeader();
329-
}
330-
}
331-
332-
/**
333-
* This class backports the seek() function from Symfony 3.2 to older versions - up to v2.6. The
334-
* class should not be used with newer Symfony versions that provide the seek function, as it relies
335-
* on a lot of undocumented functionality.
336-
*/
337-
class SeekingData extends Data
338-
{
339-
// Because the class copies/pastes the seek() implementation from Symfony 3.2, we reproduce its
340-
// copyright here; this class is subject to the following additional copyright:
341-
342-
/*
343-
* Copyright (c) 2014-2017 Fabien Potencier
344-
*
345-
* Permission is hereby granted, free of charge, to any person obtaining a copy
346-
* of this software and associated documentation files (the "Software"), to deal
347-
* in the Software without restriction, including without limitation the rights
348-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
349-
* copies of the Software, and to permit persons to whom the Software is furnished
350-
* to do so, subject to the following conditions:
351-
*
352-
* The above copyright notice and this permission notice shall be included in all
353-
* copies or substantial portions of the Software.
354-
*
355-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
356-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
357-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
358-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
359-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
360-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
361-
* THE SOFTWARE.
362-
*/
363-
private $position = 0;
364-
private $key = 0;
365-
366-
/**
367-
* Seeks to a specific key in nested data structures.
368-
*
369-
* @param string|int $key The key to seek to
370-
*
371-
* @return self|null A clone of $this of null if the key is not set
372-
*/
373-
public function seek($key)
374-
{
375-
$thisData = $this->getRawData();
376-
$item = $thisData[$this->position][$this->key];
377-
378-
if (!$item instanceof Stub || !$item->position) {
379-
return;
380-
}
381-
$keys = array($key);
382-
383-
switch ($item->type) {
384-
case Stub::TYPE_OBJECT:
385-
$keys[] = "\0+\0".$key;
386-
$keys[] = "\0*\0".$key;
387-
$keys[] = "\0~\0".$key;
388-
$keys[] = "\0$item->class\0$key";
389-
case Stub::TYPE_ARRAY:
390-
case Stub::TYPE_RESOURCE:
391-
break;
392-
default:
393-
return;
394-
}
395-
396-
$data = null;
397-
$children = $thisData[$item->position];
398-
399-
foreach ($keys as $key) {
400-
if (isset($children[$key]) || array_key_exists($key, $children)) {
401-
$data = clone $this;
402-
$data->key = $key;
403-
$data->position = $item->position;
404-
break;
405-
}
406-
}
407-
408-
return $data;
409-
}
410-
411-
/**
412-
* {@inheritdoc}
413-
*/
414-
public function dump(DumperInterface $dumper)
415-
{
416-
// Override the base class dump to use the position and key
417-
$refs = array(0);
418-
$class = new \ReflectionClass($this);
419-
$dumpItem = $class->getMethod('dumpItem');
420-
$dumpItem->setAccessible(true);
421-
$data = $this->getRawData();
422-
$args = array($dumper, new Cursor(), &$refs, $data[$this->position][$this->key]);
423-
$dumpItem->invokeArgs($this, $args);
424-
}
425-
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace DebugBar\DataFormatter\VarDumper;
4+
5+
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
6+
7+
/**
8+
* We have to extend the base HtmlDumper class in order to get access to the protected-only
9+
* getDumpHeader function.
10+
*/
11+
class DebugBarHtmlDumper extends HtmlDumper
12+
{
13+
public function getDumpHeaderByDebugBar() {
14+
// getDumpHeader is protected:
15+
return str_replace('pre.sf-dump', '.debugbar pre.sf-dump', $this->getDumpHeader());
16+
}
17+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace DebugBar\DataFormatter\VarDumper;
4+
5+
use Symfony\Component\VarDumper\Cloner\Cursor;
6+
use Symfony\Component\VarDumper\Cloner\Data;
7+
use Symfony\Component\VarDumper\Cloner\DumperInterface;
8+
use Symfony\Component\VarDumper\Cloner\Stub;
9+
10+
/**
11+
* This class backports the seek() function from Symfony 3.2 to older versions - up to v2.6. The
12+
* class should not be used with newer Symfony versions that provide the seek function, as it relies
13+
* on a lot of undocumented functionality.
14+
*/
15+
class SeekingData extends Data
16+
{
17+
// Because the class copies/pastes the seek() implementation from Symfony 3.2, we reproduce its
18+
// copyright here; this class is subject to the following additional copyright:
19+
20+
/*
21+
* Copyright (c) 2014-2017 Fabien Potencier
22+
*
23+
* Permission is hereby granted, free of charge, to any person obtaining a copy
24+
* of this software and associated documentation files (the "Software"), to deal
25+
* in the Software without restriction, including without limitation the rights
26+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27+
* copies of the Software, and to permit persons to whom the Software is furnished
28+
* to do so, subject to the following conditions:
29+
*
30+
* The above copyright notice and this permission notice shall be included in all
31+
* copies or substantial portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39+
* THE SOFTWARE.
40+
*/
41+
private $position = 0;
42+
private $key = 0;
43+
44+
/**
45+
* Seeks to a specific key in nested data structures.
46+
*
47+
* @param string|int $key The key to seek to
48+
*
49+
* @return self|null A clone of $this of null if the key is not set
50+
*/
51+
public function seek($key)
52+
{
53+
$thisData = $this->getRawData();
54+
$item = $thisData[$this->position][$this->key];
55+
56+
if (!$item instanceof Stub || !$item->position) {
57+
return;
58+
}
59+
$keys = array($key);
60+
61+
switch ($item->type) {
62+
case Stub::TYPE_OBJECT:
63+
$keys[] = "\0+\0".$key;
64+
$keys[] = "\0*\0".$key;
65+
$keys[] = "\0~\0".$key;
66+
$keys[] = "\0$item->class\0$key";
67+
case Stub::TYPE_ARRAY:
68+
case Stub::TYPE_RESOURCE:
69+
break;
70+
default:
71+
return;
72+
}
73+
74+
$data = null;
75+
$children = $thisData[$item->position];
76+
77+
foreach ($keys as $key) {
78+
if (isset($children[$key]) || array_key_exists($key, $children)) {
79+
$data = clone $this;
80+
$data->key = $key;
81+
$data->position = $item->position;
82+
break;
83+
}
84+
}
85+
86+
return $data;
87+
}
88+
89+
/**
90+
* {@inheritdoc}
91+
*/
92+
public function dump(DumperInterface $dumper)
93+
{
94+
// Override the base class dump to use the position and key
95+
$refs = array(0);
96+
$class = new \ReflectionClass($this);
97+
$dumpItem = $class->getMethod('dumpItem');
98+
$dumpItem->setAccessible(true);
99+
$data = $this->getRawData();
100+
$args = array($dumper, new Cursor(), &$refs, $data[$this->position][$this->key]);
101+
$dumpItem->invokeArgs($this, $args);
102+
}
103+
}

src/DebugBar/Resources/debugbar.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ div.phpdebugbar code, div.phpdebugbar pre {
8989

9090
div.phpdebugbar pre.sf-dump {
9191
color: #a0a000;
92+
outline: 0;
9293
}
9394

9495
a.phpdebugbar-restore-btn {

0 commit comments

Comments
 (0)