8000 [ValueExporter] added ExpandedFormatterInterface · symfony/symfony@d62d280 · GitHub
[go: up one dir, main page]

Skip to content

Commit d62d280

Browse files
committed
[ValueExporter] added ExpandedFormatterInterface
1 parent 3a1d99b commit d62d280

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Symfony/Component/ValueExporter/Exporter/AbstractValueExporter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\ValueExporter\Exception\InvalidFormatterException;
1515
use Symfony\Component\ValueExporter\Exporter;
16+
use Symfony\Component\ValueExporter\Formatter\ExpandedFormatterInterface;
1617
use Symfony\Component\ValueExporter\Formatter\FormatterInterface;
1718

1819
/**
@@ -55,12 +56,18 @@ final public function addFormatters(array $appends, array $prepends = array())
5556
if (!$append instanceof $this->formatterInterface) {
5657
throw new InvalidFormatterException(get_class($append), self::class, $this->formatterInterface);
5758
}
59+
if ($append instanceof ExpandedFormatterInterface) {
60+
$append->setExporter($this);
61+
}
5862
$this->formatters[] = $append;
5963
}
6064
foreach (array_reverse($prepends) as $prepend) {
6165
if (!$prepend instanceof $this->formatterInterface) {
6266
throw new InvalidFormatterException(get_class($prepend), self::class, $this->formatterInterface);
6367
}
68+
if ($prepend instanceof ExpandedFormatterInterface) {
69+
$prepend->setExporter($this);
70+
}
6471
array_unshift($this->formatters, $prepend);
6572
}
6673
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\ValueExporter\Formatter;
13+
14+
use Symfony\Component\ValueExporter\Exporter\ValueExporterInterface;
15+
16+
/**
17+
* ExpandedFormatterInterface.
18+
*
19+
* Needs the {@link ValueExporterInterface} to export nested values.
20+
*
21+
* @author Jules Pietri <jules@heahprod.com>
22+
*/
23+
interface ExpandedFormatterInterface
24+
{
25+
/**
26+
* Sets the exporter to call on nested values.
27+
*
28+
* @param ValueExporterInterface $exporter The exporter
29+
*/
30+
public function setExporter(ValueExporterInterface $exporter);
31+
}

0 commit comments

Comments
 (0)
0