Chris@0: source = $source; Chris@0: $this->target = $target; Chris@0: $this->map = $map; Chris@0: } Chris@0: Chris@0: /** Chris@0: * If the source field is instance of one of the entries in the map, Chris@0: * target is set to the value of that map entry. Chris@0: * Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function enhance(array $defaults, Request $request) Chris@0: { Chris@0: if (isset($defaults[$this->target])) { Chris@0: // no need to do anything Chris@0: return $defaults; Chris@0: } Chris@0: Chris@0: if (!isset($defaults[$this->source])) { Chris@0: return $defaults; Chris@0: } Chris@0: Chris@0: // we need to loop over the array and do instanceof in case the content Chris@0: // class extends the specified class Chris@0: // i.e. phpcr-odm generates proxy class for the content. Chris@0: foreach ($this->map as $class => $value) { Chris@0: if ($defaults[$this->source] instanceof $class) { Chris@0: // found a matching entry in the map Chris@0: $defaults[$this->target] = $value; Chris@0: Chris@0: return $defaults; Chris@0: } Chris@0: } Chris@0: Chris@0: return $defaults; Chris@0: } Chris@0: }