Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99442ed

Browse files
[VarDumper] Fine tune dumping log messages
1 parentce3ef6a commit99442ed

File tree

12 files changed

+125
-45
lines changed

12 files changed

+125
-45
lines changed

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ table.logs .metadata {
913913
#collector-content .sf-dump-key { color: #789339; }
914914
#collector-content .sf-dump-ref { color: #6E6E6E; }
915915
#collector-content .sf-dump-ellipsis { color: #CC7832; max-width: 100em; }
916+
#collector-content .sf-dump-ellipsis-path { max-width: 5em; }
916917

917918
#collector-content .sf-dump {
918919
margin: 0;

‎src/Symfony/Component/Debug/DebugClassLoader.php‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function loadClass($class)
162162
$name =$refl->getName();
163163

164164
if ($name !==$class &&0 ===strcasecmp($name,$class)) {
165-
thrownew \RuntimeException(sprintf('Case mismatch between loaded and declared class names:%s vs%s',$class,$name));
165+
thrownew \RuntimeException(sprintf('Case mismatch between loaded and declared class names:"%s" vs"%s".',$class,$name));
166166
}
167167

168168
$parent =get_parent_class($class);
@@ -174,7 +174,7 @@ public function loadClass($class)
174174
}
175175

176176
if ($parent &&isset(self::$final[$parent])) {
177-
@trigger_error(sprintf('The%s class is considered final%s. It may change without further notice as of its next major version. You should not extend it from%s.',$parent,self::$final[$parent],$name),E_USER_DEPRECATED);
177+
@trigger_error(sprintf('The"%s" class is considered final%s. It may change without further notice as of its next major version. You should not extend it from"%s".',$parent,self::$final[$parent],$name),E_USER_DEPRECATED);
178178
}
179179

180180
// Inherit @final annotations
@@ -186,7 +186,7 @@ public function loadClass($class)
186186
}
187187

188188
if ($parent &&isset(self::$finalMethods[$parent][$method->name])) {
189-
@trigger_error(sprintf('%s It may change without further notice as of its next major version. You should not extend it from%s.',self::$finalMethods[$parent][$method->name],$name),E_USER_DEPRECATED);
189+
@trigger_error(sprintf('%s It may change without further notice as of its next major version. You should not extend it from"%s".',self::$finalMethods[$parent][$method->name],$name),E_USER_DEPRECATED);
190190
}
191191

192192
$doc =$method->getDocComment();
@@ -196,13 +196,13 @@ public function loadClass($class)
196196

197197
if (preg_match('#\n\s+\* @final(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s',$doc,$notice)) {
198198
$message =isset($notice[1]) ?preg_replace('#\s*\r?\n \* +#','',$notice[1]) :'';
199-
self::$finalMethods[$name][$method->name] =sprintf('The %s::%s() method is considered final%s.',$name,$method->name,$message);
199+
self::$finalMethods[$name][$method->name] =sprintf('The"%s::%s()" method is considered final%s.',$name,$method->name,$message);
200200
}
201201
}
202202
}
203203

204204
if (in_array(strtolower($refl->getShortName()),self::$php7Reserved)) {
205-
@trigger_error(sprintf('%susesa reservedclassname(%s) that will break on PHP 7 and higher',$name,$refl->getShortName()),E_USER_DEPRECATED);
205+
@trigger_error(sprintf('The "%s" classusesthe reserved name"%s", it will break on PHP 7 and higher',$name,$refl->getShortName()),E_USER_DEPRECATED);
206206
}elseif (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s',$refl->getDocComment(),$notice)) {
207207
self::$deprecated[$name] =preg_replace('#\s*\r?\n \* +#','',$notice[1]);
208208
}else {
@@ -223,7 +223,7 @@ public function loadClass($class)
223223

224224
if (!$parent ||strncmp($ns,$parent,$len)) {
225225
if ($parent &&isset(self::$deprecated[$parent]) &&strncmp($ns,$parent,$len)) {
226-
@trigger_error(sprintf('The%s class extends%s that is deprecated %s',$name,$parent,self::$deprecated[$parent]),E_USER_DEPRECATED);
226+
@trigger_error(sprintf('The"%s" class extends"%s" that is deprecated %s',$name,$parent,self::$deprecated[$parent]),E_USER_DEPRECATED);
227227
}
228228

229229
$parentInterfaces =array();
@@ -245,7 +245,7 @@ public function loadClass($class)
245245

246246
foreach ($deprecatedInterfacesas$interface) {
247247
if (!isset($parentInterfaces[$interface])) {
248-
@trigger_error(sprintf('The%s %s%s that is deprecated %s',$name,$refl->isInterface() ?'interface extends' :'class implements',$interface,self::$deprecated[$interface]),E_USER_DEPRECATED);
248+
@trigger_error(sprintf('The"%s" %s"%s" that is deprecated %s',$name,$refl->isInterface() ?'interface extends' :'class implements',$interface,self::$deprecated[$interface]),E_USER_DEPRECATED);
249249
}
250250
}
251251
}
@@ -342,7 +342,7 @@ public function loadClass($class)
342342
if (0 ===substr_compare($real,$tail, -$tailLen,$tailLen,true)
343343
&&0 !==substr_compare($real,$tail, -$tailLen,$tailLen,false)
344344
) {
345-
thrownew \RuntimeException(sprintf('Case mismatch between class and real file names:%s vs%s in%s',substr($tail, -$tailLen +1),substr($real, -$tailLen +1),substr($real,0, -$tailLen +1)));
345+
thrownew \RuntimeException(sprintf('Case mismatch between class and real file names:"%s" vs"%s" in"%s".',substr($tail, -$tailLen +1),substr($real, -$tailLen +1),substr($real,0, -$tailLen +1)));
346346
}
347347
}
348348

‎src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true);
185185

186186
$xError =array(
187187
'type' =>E_USER_DEPRECATED,
188-
'message' =>'The Test\Symfony\Component\Debug\Tests\\'.$class.' class'.$type.' Symfony\Component\Debug\Tests\Fixtures\\'.$super.' that is deprecated but this is a test deprecation notice.',
188+
'message' =>'The"Test\Symfony\Component\Debug\Tests\\'.$class.'" class'.$type.'"Symfony\Component\Debug\Tests\Fixtures\\'.$super.'" that is deprecated but this is a test deprecation notice.',
189189
);
190190

191191
$this->assertSame($xError,$lastError);
@@ -263,7 +263,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\Float', true);
263263

264264
$xError =array(
265265
'type' =>E_USER_DEPRECATED,
266-
'message' =>'Test\Symfony\Component\Debug\Tests\Floatusesa reservedclassname(Float) that will break on PHP 7 and higher',
266+
'message' =>'The "Test\Symfony\Component\Debug\Tests\Float" classusesthe reserved name"Float", it will break on PHP 7 and higher',
267267
);
268268

269269
$this->assertSame($xError,$lastError);
@@ -285,7 +285,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsFinalClass', true);
285285

286286
$xError =array(
287287
'type' =>E_USER_DEPRECATED,
288-
'message' =>'The Symfony\Component\Debug\Tests\Fixtures\FinalClass class is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from Test\Symfony\Component\Debug\Tests\ExtendsFinalClass.',
288+
'message' =>'The"Symfony\Component\Debug\Tests\Fixtures\FinalClass" class is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from"Test\Symfony\Component\Debug\Tests\ExtendsFinalClass".',
289289
);
290290

291291
$this->assertSame($xError,$lastError);
@@ -307,7 +307,7 @@ class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);
307307

308308
$xError =array(
309309
'type' =>E_USER_DEPRECATED,
310-
'message' =>'The Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod() method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod.',
310+
'message' =>'The"Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from"Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
311311
);
312312

313313
$this->assertSame($xError,$lastError);

‎src/Symfony/Component/VarDumper/Caster/ClassStub.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct($identifier, $callable = null)
3030

3131
if (0 <$i =strrpos($identifier,'\\')) {
3232
$this->attr['ellipsis'] =strlen($identifier) -$i;
33+
$this->attr['ellipsis-type'] ='class';
3334
}
3435

3536
try {

‎src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\VarDumper\Caster;
1313

14+
useSymfony\Component\Debug\Exception\SilencedErrorContext;
1415
useSymfony\Component\VarDumper\Exception\ThrowingCasterException;
1516
useSymfony\Component\VarDumper\Cloner\Stub;
1617

@@ -64,20 +65,44 @@ public static function castErrorException(\ErrorException $e, array $a, Stub $st
6465

6566
publicstaticfunctioncastThrowingCasterException(ThrowingCasterException$e,array$a,Stub$stub,$isNested)
6667
{
68+
$trace = Caster::PREFIX_VIRTUAL.'trace';
6769
$prefix = Caster::PREFIX_PROTECTED;
6870
$xPrefix ="\0Exception\0";
6971

70-
if (isset($a[$xPrefix.'previous'],$a[$xPrefix.'trace']) &&$a[$xPrefix.'previous']instanceof \Exception) {
72+
if (isset($a[$xPrefix.'previous'],$a[$trace]) &&$a[$xPrefix.'previous']instanceof \Exception) {
7173
$b = (array)$a[$xPrefix.'previous'];
7274
self::traceUnshift($b[$xPrefix.'trace'],get_class($a[$xPrefix.'previous']),$b[$prefix.'file'],$b[$prefix.'line']);
73-
$a[$xPrefix.'trace'] =newTraceStub($b[$xPrefix.'trace'],false,0, -count($a[$xPrefix.'trace']->value));
75+
$a[$trace] =newTraceStub($b[$xPrefix.'trace'],false,0, -count($a[$trace]->value));
7476
}
7577

7678
unset($a[$xPrefix.'previous'],$a[$prefix.'code'],$a[$prefix.'file'],$a[$prefix.'line']);
7779

7880
return$a;
7981
}
8082

83+
publicstaticfunctioncastSilencedErrorContext(SilencedErrorContext$e,array$a,Stub$stub,$isNested)
84+
{
85+
$sPrefix ="\0".SilencedErrorContext::class."\0";
86+
$xPrefix ="\0Exception\0";
87+
88+
if (!isset($a[$s =$sPrefix.'severity'])) {
89+
return$a;
90+
}
91+
92+
if (isset(self::$errorTypes[$a[$s]])) {
93+
$a[$s] =newConstStub(self::$errorTypes[$a[$s]],$a[$s]);
94+
}
95+
96+
$trace =array(
97+
'file' =>$a[$sPrefix.'file'],
98+
'line' =>$a[$sPrefix.'line'],
99+
);
100+
unset($a[$sPrefix.'file'],$a[$sPrefix.'line']);
101+
$a[Caster::PREFIX_VIRTUAL.'trace'] =newTraceStub(array($trace));
102+
103+
return$a;
104+
}
105+
81106
publicstaticfunctioncastTraceStub(TraceStub$trace,array$a,Stub$stub,$isNested)
82107
{
83108
if (!$isNested) {
@@ -159,8 +184,8 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
159184
$caller =isset($f['function']) ?sprintf('in %s() on line %d', (isset($f['class']) ?$f['class'].$f['type'] :'').$f['function'],$f['line']) :null;
160185
$src =$f['line'];
161186
$srcKey =$f['file'];
162-
$ellipsis =explode(DIRECTORY_SEPARATOR,$srcKey);
163-
$ellipsis =3 <count($ellipsis) ?2 +strlen(implode(array_slice($ellipsis, -2))) :0;
187+
$ellipsis =(newLinkStub($srcKey,0))->attr;
188+
$ellipsis =isset($ellipsis['ellipsis']) ?$ellipsis['ellipsis'] :0;
164189

165190
if (file_exists($f['file']) &&0 <=self::$srcContext) {
166191
if (!empty($f['class']) &&is_subclass_of($f['class'],'Twig_Template') &&method_exists($f['class'],'getDebugInfo')) {
@@ -187,7 +212,7 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
187212
}
188213
}
189214
}
190-
$srcAttr =$ellipsis ?'ellipsis='.$ellipsis :'';
215+
$srcAttr =$ellipsis ?'ellipsis-type=path&ellipsis='.$ellipsis :'';
191216
self::$framesCache[$cacheKey] =$a[$prefix.'src'] =newEnumStub(array("\0~$srcAttr\0$srcKey" =>$src));
192217
}
193218
}
@@ -221,7 +246,7 @@ private static function filterExceptionArray($xClass, array $a, $xPrefix, $filte
221246
if (isset($a[Caster::PREFIX_PROTECTED.'file'],$a[Caster::PREFIX_PROTECTED.'line'])) {
222247
self::traceUnshift($trace,$xClass,$a[Caster::PREFIX_PROTECTED.'file'],$a[Caster::PREFIX_PROTECTED.'line']);
223248
}
224-
$a[$xPrefix.'trace'] =newTraceStub($trace,self::$traceArgs);
249+
$a[Caster::PREFIX_VIRTUAL.'trace'] =newTraceStub($trace,self::$traceArgs);
225250
}
226251
if (empty($a[$xPrefix.'previous'])) {
227252
unset($a[$xPrefix.'previous']);

‎src/Symfony/Component/VarDumper/Caster/LinkStub.php‎

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,82 @@
1818
*/
1919
class LinkStubextends ConstStub
2020
{
21+
privatestatic$vendorRoots;
22+
privatestatic$composerRoots;
23+
2124
publicfunction__construct($label,$line =0,$href =null)
2225
{
2326
$this->value =$label;
2427

2528
if (null ===$href) {
2629
$href =$label;
2730
}
28-
if (is_string($href)) {
29-
if (0 ===strpos($href,'file://')) {
30-
if ($href ===$label) {
31-
$label =substr($label,7);
31+
if (!is_string($href)) {
32+
return;
33+
}
34+
if (0 ===strpos($href,'file://')) {
35+
if ($href ===$label) {
36+
$label =substr($label,7);
37+
}
38+
$href =substr($href,7);
39+
}elseif (false !==strpos($href,'://')) {
40+
$this->attr['href'] =$href;
41+
42+
return;
43+
}
44+
if (!file_exists($href)) {
45+
return;
46+
}
47+
if ($line) {
48+
$this->attr['line'] =$line;
49+
}
50+
if ($label !==$this->attr['file'] =realpath($href) ?:$href) {
51+
return;
52+
}
53+
if ($composerRoot =$this->getComposerRoot($href)) {
54+
$this->attr['ellipsis'] =strlen($href) -strlen($composerRoot) +1;
55+
$this->attr['ellipsis-type'] ='path';
56+
}elseif (3 <count($ellipsis =explode(DIRECTORY_SEPARATOR,$href))) {
57+
$this->attr['ellipsis'] =2 +strlen(implode(array_slice($ellipsis, -2)));
58+
$this->attr['ellipsis-type'] ='path';
59+
}
60+
}
61+
62+
privatefunctiongetComposerRoot($file)
63+
{
64+
if (null ===self::$vendorRoots) {
65+
self::$vendorRoots =array();
66+
67+
foreach (get_declared_classes()as$class) {
68+
if ('C' ===$class[0] &&0 ===strpos($class,'ComposerAutoloaderInit')) {
69+
$r =new \ReflectionClass($class);
70+
$v =dirname(dirname($r->getFileName()));
71+
if (file_exists($v.'/composer/installed.json')) {
72+
self::$vendorRoots[] =$v.DIRECTORY_SEPARATOR;
73+
}
3274
}
33-
$href =substr($href,7);
34-
}elseif (false !==strpos($href,'://')) {
35-
$this->attr['href'] =$href;
75+
}
76+
}
77+
78+
if (isset(self::$composerRoots[$dir =dirname($file)])) {
79+
returnself::$composerRoots[$dir];
80+
}
3681

37-
return;
82+
foreach (self::$vendorRootsas$root) {
83+
if (0 ===strpos($file,$root)) {
84+
return$root;
3885
}
39-
if (file_exists($href)) {
40-
if ($line) {
41-
$this->attr['line'] =$line;
42-
}
43-
$this->attr['file'] =realpath($href) ?:$href;
86+
}
4487

45-
if ($this->attr['file'] ===$label &&3 <count($ellipsis =explode(DIRECTORY_SEPARATOR,$href))) {
46-
$this->attr['ellipsis'] =2 +strlen(implode(array_slice($ellipsis, -2)));
47-
}
88+
$parent =$dir;
89+
while (!file_exists($parent.'/composer.json')) {
90+
if ($parent ===dirname($parent)) {
91+
returnself::$composerRoots[$dir] =false;
4892
}
93+
94+
$parent =dirname($parent);
4995
}
96+
97+
returnself::$composerRoots[$dir] =$parent.DIRECTORY_SEPARATOR;
5098
}
5199
}

‎src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ abstract class AbstractCloner implements ClonerInterface
7979
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' =>array('Symfony\Component\VarDumper\Caster\ExceptionCaster','castThrowingCasterException'),
8080
'Symfony\Component\VarDumper\Caster\TraceStub' =>array('Symfony\Component\VarDumper\Caster\ExceptionCaster','castTraceStub'),
8181
'Symfony\Component\VarDumper\Caster\FrameStub' =>array('Symfony\Component\VarDumper\Caster\ExceptionCaster','castFrameStub'),
82+
'Symfony\Component\Debug\Exception\SilencedErrorContext' =>array('Symfony\Component\VarDumper\Caster\ExceptionCaster','castSilencedErrorContext'),
8283

8384
'PHPUnit_Framework_MockObject_MockObject' =>array('Symfony\Component\VarDumper\Caster\StubCaster','cutInternals'),
8485
'Prophecy\Prophecy\ProphecySubjectInterface' =>array('Symfony\Component\VarDumper\Caster\StubCaster','cutInternals'),

‎src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,13 @@ protected function style($style, $value, $attr = array())
788788
$map =static::$controlCharsMap;
789789

790790
if (isset($attr['ellipsis'])) {
791+
$class ='sf-dump-ellipsis';
792+
if (isset($attr['ellipsis-type'])) {
793+
$class =sprintf('"%s sf-dump-ellipsis-%s"',$class,$attr['ellipsis-type']);
794+
}
791795
$label =esc(substr($value, -$attr['ellipsis']));
792796
$style =str_replace(' title="'," title=\"$v\n",$style);
793-
$v =sprintf('<span class=sf-dump-ellipsis>%s</span>%s',substr($v,0, -strlen($label)),$label);
797+
$v =sprintf('<span class=%s>%s</span>%s',$class,substr($v,0, -strlen($label)),$label);
794798
}
795799

796800
$v ="<span class=sf-dump-{$style}>".preg_replace_callback(static::$controlCharsRx,function ($c)use ($map) {

‎src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testDefaultSettings()
4444
#code: 0
4545
#file: "%sExceptionCasterTest.php"
4646
#line: 27
47-
-trace: {
47+
trace: {
4848
%sExceptionCasterTest.php:27: {
4949
: {
5050
: return new \Exception(''.$msg);
@@ -102,7 +102,7 @@ public function testNoArgs()
102102
#code: 0
103103
#file: "%sExceptionCasterTest.php"
104104
#line: 27
105-
-trace: {
105+
trace: {
106106
%sExceptionCasterTest.php:27: {
107107
: {
108108
: return new \Exception(''.$msg);
@@ -130,7 +130,7 @@ public function testNoSrcContext()
130130
#code: 0
131131
#file: "%sExceptionCasterTest.php"
132132
#line: 27
133-
-trace: {
133+
trace: {
134134
%sExceptionCasterTest.php: 27
135135
%sExceptionCasterTest.php: %d
136136
%A
@@ -156,11 +156,11 @@ public function testHtmlDump()
156156
#<span class=sf-dump-protected title="Protected property">message</span>: "<span class=sf-dump-str>1</span>"
157157
#<span class=sf-dump-protected title="Protected property">code</span>: <span class=sf-dump-num>0</span>
158158
#<span class=sf-dump-protected title="Protected property">file</span>: "<span class=sf-dump-str title="%sExceptionCasterTest.php
159-
%d characters"><span class=sf-dump-ellipsis>%sTests</span>%eCaster%eExceptionCasterTest.php</span>"
159+
%d characters"><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span>%eTests%eCaster%eExceptionCasterTest.php</span>"
160160
#<span class=sf-dump-protected title="Protected property">line</span>: <span class=sf-dump-num>27</span>
161-
-<span class=sf-dump-private title="Private property defined in class:&#10;`Exception`">trace</span>: {<samp>
161+
<span class=sf-dump-meta>trace</span>: {<samp>
162162
<span class=sf-dump-meta title="%sExceptionCasterTest.php
163-
Stack level %d."><span class=sf-dump-ellipsis>%sVarDumper%eTests</span>%eCaster%eExceptionCasterTest.php</span>: <span class=sf-dump-num>27</span>
163+
Stack level %d."><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span>%eTests%eCaster%eExceptionCasterTest.php</span>: <span class=sf-dump-num>27</span>
164164
&hellip;%d
165165
</samp>}
166166
</samp>}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp