ICanBoogie/Facets v0.3.1
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Facets
      • RecordCollection

Classes

  • BooleanCriterion
  • Criterion
  • CriterionList
  • CriterionNotDefined
  • CriterionValue
  • Fetcher
  • IntervalCriterionValue
  • QueryString
  • QueryStringWord
  • RecordCollection
  • SetCriterionValue

Interfaces

  • CriterionInterface
  • FetcherInterface

Traits

  • CriterionTrait
  • FetcherTrait
  • HumanizePairsTrait
  • ParseQueryStringTrait
 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 
<?php

/*
 * This file is part of the ICanBoogie package.
 *
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ICanBoogie\Facets;

/**
 * A trait that implements `humanize()` and can be provided with pairs of key/value where key is
 * the machine name and value is the human name.
 */
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];
    }
}
ICanBoogie/Facets v0.3.1 API documentation generated by ApiGen