feature #32683 [VarDumper] added support for Imagine/Image (lyrixx)
This PR was merged into the 4.4 branch.
Discussion
----------
[VarDumper] added support for Imagine/Image
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
---
![image](https://user-images.githubusercontent.com/408368/61811135-19c5a000-ae41-11e9-88f1-9f5823e9ca80.png)
Commits
-------
c8d420ddff
[VarDumper] added support for Imagine/Image
This commit is contained in:
commit
65f0d6f6a2
@ -6,6 +6,7 @@ CHANGELOG
|
||||
|
||||
* added `VarDumperTestTrait::setUpVarDumper()` and `VarDumperTestTrait::tearDownVarDumper()`
|
||||
to configure casters & flags to use in tests
|
||||
* added `ImagineCaster` and infrastructure to dump images
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
37
src/Symfony/Component/VarDumper/Caster/ImagineCaster.php
Normal file
37
src/Symfony/Component/VarDumper/Caster/ImagineCaster.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Caster;
|
||||
|
||||
use Imagine\Image\ImageInterface;
|
||||
use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
|
||||
/**
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*/
|
||||
class ImagineCaster
|
||||
{
|
||||
public static function castImage(ImageInterface $c, array $a, Stub $stub, $isNested)
|
||||
{
|
||||
$imgData = $c->get('png');
|
||||
if (\strlen($imgData) > 1 * 1000 * 1000) {
|
||||
$a += [
|
||||
Caster::PREFIX_VIRTUAL.'image' => new ConstStub($c->getSize()),
|
||||
];
|
||||
} else {
|
||||
$a += [
|
||||
Caster::PREFIX_VIRTUAL.'image' => new ImgStub($imgData, 'image/png', $c->getSize()),
|
||||
];
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
}
|
26
src/Symfony/Component/VarDumper/Caster/ImgStub.php
Normal file
26
src/Symfony/Component/VarDumper/Caster/ImgStub.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Caster;
|
||||
|
||||
/**
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*/
|
||||
class ImgStub extends ConstStub
|
||||
{
|
||||
public function __construct(string $data, string $contentType, string $size)
|
||||
{
|
||||
$this->value = '';
|
||||
$this->attr['img-data'] = $data;
|
||||
$this->attr['img-size'] = $size;
|
||||
$this->attr['content-type'] = $contentType;
|
||||
}
|
||||
}
|
@ -87,6 +87,8 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
'Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||
'Symfony\Component\ErrorHandler\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
|
||||
|
||||
'Imagine\Image\ImageInterface' => ['Symfony\Component\VarDumper\Caster\ImagineCaster', 'castImage'],
|
||||
|
||||
'ProxyManager\Proxy\ProxyInterface' => ['Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'],
|
||||
'PHPUnit_Framework_MockObject_MockObject' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||
'Prophecy\Prophecy\ProphecySubjectInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||
|
@ -682,6 +682,13 @@ pre.sf-dump a {
|
||||
outline: none;
|
||||
color: inherit;
|
||||
}
|
||||
pre.sf-dump img {
|
||||
max-width: 50em;
|
||||
max-height: 50em;
|
||||
margin: .5em 0 0 0;
|
||||
padding: 0;
|
||||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAHUlEQVQY02O8zAABilCaiQEN0EeA8QuUcX9g3QEAAjcC5piyhyEAAAAASUVORK5CYII=) #D3D3D3;
|
||||
}
|
||||
pre.sf-dump .sf-dump-ellipsis {
|
||||
display: inline-block;
|
||||
overflow: visible;
|
||||
@ -792,6 +799,23 @@ EOHTML
|
||||
return $this->dumpHeader = preg_replace('/\s+/', ' ', $line).'</style>'.$this->dumpHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dumpString(Cursor $cursor, $str, $bin, $cut)
|
||||
{
|
||||
if ('' === $str && isset($cursor->attr['img-data'], $cursor->attr['content-type'])) {
|
||||
$this->dumpKey($cursor);
|
||||
$this->line .= $this->style('default', $cursor->attr['img-size'] ?? '', []).' <samp>';
|
||||
$this->endValue($cursor);
|
||||
$this->line .= $this->indentPad;
|
||||
$this->line .= sprintf('<img src="data:%s;base64,%s" /></samp>', $cursor->attr['content-type'], base64_encode($cursor->attr['img-data']));
|
||||
$this->endValue($cursor);
|
||||
} else {
|
||||
parent::dumpString($cursor, $str, $bin, $cut);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user