for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace FSi\Bundle\AdminBundle\Display;
use FSi\Bundle\AdminBundle\Display\Property\ValueFormatter;
use InvalidArgumentException;
class Property
{
* @var mixed
private $value;
* @var string|null
private $label;
* @param mixed $value
* @param string $label
* @param ValueFormatter[] $valueFormatters
public function __construct($value, ?string $label = null, array $valueFormatters = [])
$this->validateFormatters($valueFormatters);
$this->value = $this->formatValue($value, $valueFormatters);
$this->label = $label;
}
public function getLabel(): ?string
return $this->label;
* @return mixed
public function getValue()
return $this->value;
private function formatValue($value, array $valueFormatters)
foreach ($valueFormatters as $formatter) {
$value = $formatter->format($value);
return $value;
private function validateFormatters(array $valueFormatters): void
if (!$formatter instanceof ValueFormatter) {
throw new InvalidArgumentException(sprintf(
'Expected property formatter to be an instance of'
. ' FSi\Bundle\AdminBundle\Display\Property\ValueFormatter,'
. ' got "%s" instead',
is_object($formatter) ? get_class($formatter) : gettype($formatter)
));