1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
<?php
namespace ICanBoogie\Facets\Criterion;
use ICanBoogie\Facets\CriterionValue\SetCriterionValue;
trait HumanizePairsTrait
{
abstract protected function get_humanize_pairs();
public function humanize($value)
{
$pairs = $this->get_humanize_pairs();
if ($value instanceof SetCriterionValue)
{
$humanized = [];
foreach ($value->to_array() as $value)
{
if (empty($pairs[$value]))
{
continue;
}
$humanized[] = $pairs[$value];
}
return $humanized;
}
return empty($pairs[$value]) ? null : $pairs[$value];
}
}