4 * This file is part of the Symfony CMF package.
6 * (c) 2011-2015 Symfony CMF
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Cmf\Component\Routing\Enhancer;
14 use Symfony\Component\HttpFoundation\Request;
17 * This enhancer can fill one field with the result of a hashmap lookup of
18 * another field. If the target field is already set, it does nothing.
20 * @author David Buchmann
22 class FieldMapEnhancer implements RouteEnhancerInterface
25 * @var string field for key in hashmap lookup
29 * @var string field to write hashmap lookup result into
33 * @var array containing the mapping between the source field value and target field value
38 * @param string $source the field to read
39 * @param string $target the field to write the result of the lookup into
40 * @param array $hashmap for looking up value from source and get value for target
42 public function __construct($source, $target, array $hashmap)
44 $this->source = $source;
45 $this->target = $target;
46 $this->hashmap = $hashmap;
50 * If the target field is not set but the source field is, map the field.
54 public function enhance(array $defaults, Request $request)
56 if (isset($defaults[$this->target])) {
59 if (!isset($defaults[$this->source])) {
62 if (!isset($this->hashmap[$defaults[$this->source]])) {
66 $defaults[$this->target] = $this->hashmap[$defaults[$this->source]];