Provide related value given reference. If not found, return the same
reference, treated as a value.

A map array is optional in order to have a normalization guide.

@param string $reference
@param array  $map

@return mixed
968003
public function provide(
        string $reference,
        array $map = []
    ) {
        $request = $this->requestType == self::CURRENT_REQUEST
            ? $this
                ->requestStack
                ->getCurrentRequest()
            : $this
                ->requestStack
                ->getMasterRequest();

        if ($request instanceof Request) {
            foreach ([
                '~' => $request->attributes,
                '#' => $request->request,
                '?' => $request->query,
            ] as $symbol => $parameterBag) {
                $value = $this->resolveValueFromParameterBag(
                    $parameterBag,
                    $symbol,
                    $reference
                );

                if ($value !== $reference) {
                    return is_array($map) && isset($map[$value])
                        ? $map[$value]
                        : $value;
                }
            }
        }

        return $reference;
    }
158679
public function mapField(array $mapping)
    {
        $mapping = parent::mapField($mapping);

        if ($this->reflClass->hasProperty($mapping['fieldName'])) {
            $reflProp = $this->reflClass->getProperty($mapping['fieldName']);
            $reflProp->setAccessible(true);
            $this->reflFields[$mapping['fieldName']] = $reflProp;
        }
    }
753116
public function get($prop)
    {
        $value = isset($this->_data[$prop]) ? $this->_data[$prop] : null;

        // dereference property reference values
        return $value instanceof PropertyReference ? $value->value() : $value;
    }
788544
public function getRef($reference)
	{
		$ref = &self::_getArray();

		if (isset($ref[$reference]))
		{
			return $ref[$reference];
		}
		else
		{
			return false;
		}
	}
312581
public function index (array $array, callable $callable, $reference = false) {
		$indexed = array();

		if ($reference) {
			foreach ($array as $key => &$value) {
				$indexed[$callable($value, $key)] = &$value;
			}
		} else {
			foreach ($array as $key => $value) {
				$indexed[$callable($value, $key)] = $value;
			}
		}

		return $indexed;
	}
172075
public static function map($array, $mapping) {
        $result = array();
        foreach($mapping as $src=>$dest) {
            if(array_key_exists($src, $array)) {
                $result[$dest] = $array[$src];
            }
        }
        return $result;
    }
733185
protected function generateKey($reference)/*# : string */
    {
        if (is_array($reference)) {
            $reference = $this->flatReference($reference);
        }
        $md5 = md5(serialize($reference));
        return sprintf("/%s/%s/%s", $md5[0], $md5[1], $md5);
    }
503522
protected function flatReference(array $reference)/*# : array */
    {
        reset($reference);
        foreach ($reference as $key => $value) {
            if (is_object($value)) {
                $reference[$key] = get_class($value);
            } elseif (is_array($value)) {
                $reference[$key] = $this->flatReference($value);
            }
        }
        ksort($reference);
        return $reference;
    }
841498
public function resolve($reference, $class)
    {
        $result = $reference;

        while ($result instanceof Reference) {
            $result = $result->resolve(function ($data) use($result, $class) {
                return $this->serializer->denormalize($data, $class, 'json', [
                    'document-origin' => (string) $result->getMergedUri()->withFragment('')
                ]);
            });
        }

        return $result;
    }
702197
protected function optimizeLooseMap(array $map)
	{
		foreach ($map as $k => $v)
		{
			if ($k === $v)
			{
				unset($map[$k]);
			}
		}

		return $map;
	}
768134
public function remove($reference)
    {
        $reference = $this->computeKeyFQN($reference);
        $matcher = $this->getMatcher();

        Collection::cast(self::$data)->each(function (&$value, $key) use ($matcher, $reference) {
            if ($matcher->match($reference, $key)) {
                unset(self::$data[$key]);
            }
        });
        return $this;
    }
989287
public function getRawReference($reference)
    {

        $reference = $this->mapReference($reference);

        if (!array_key_exists($reference, $this->container)) {
            throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $reference));
        }

        return $this->container[$reference];
    }
777164
public static function mapKey($origin, $map = [])
    {
        $result = is_array($origin) ? [] : new \stdClass();

        foreach ((array) $origin as $key => $val) {
            $newKey = self::getValue($map, $key);

            if ($newKey) {
                self::setValue($result, $newKey, $val);
            } else {
                self::setValue($result, $key, $val);
            }
        }

        return $result;
    }
277876
protected function doGetDBRef(array $reference)
    {
        $mongoCollection = $this->mongoCollection;
        return $this->retry(function() use ($mongoCollection, $reference) {
            return $mongoCollection->getDBRef($reference);
        });
    }
1126780
public function get($reference, $default = null)
    {
        $reference = $this->computeKeyFQN($reference);

        // first look for exact match
        if (isset(self::$data[$reference])) {
            return self::$data[$reference];
        }

        // otherwise use a matcher to return a
        // collection of matching entries
        $matcher = $this->getMatcher();
        $matches = new Collection();

        Collection::cast(self::$data)->each(function (&$value, $key) use ($matcher, $reference, $matches) {
            if ($matcher->match($reference, $key)) {
                $matches[$key] = $value;
            }
        });

        if (!$matches->isEmpty()) return $matches;

        return $default;
    }
1114445
protected function getRelationData(&$params, array $map = [])
    {
        $operation = $this->model->name;

        if (is_null($this->model->related_data)) {
            return $operation;
        }
        foreach ($this->model->related_data as $relation => $data) {

            if ($relation === 'users') {
                $classname  = get_class(\Antares\Support\Facades\Foundation::make('antares.user'));
                $urlPattern = $this->getUrlPattern($classname);
                $links      = [];
                foreach ($data as $element) {
                    $links[] = $this->link('{id}', $element['id'], $urlPattern, array_get($element, 'firstname') . ' ' . array_get($element, 'lastname'));
                }
                $params[$relation] = implode(', ', $links);
            } elseif ($relation === 'user') {
                continue;
            } elseif (!empty($data)) {
                foreach ($data as $classname => $values) {
                    if (empty($values)) {
                        continue;
                    }
                    if (!class_exists($classname)) {
                        continue;
                    }
                    if (($url = $this->getUrlPattern($classname)) !== '') {
                        $submap    = $this->getReplacementKeys($values);
                        $subValues = array_values($values);
                        $title     = array_get($values, 'name', array_get($values, 'id'));
                        array_set($params, $relation, !$this->urlFillable($url, $map) ? $title : $this->link($submap, $subValues, $url, $title) );
                    } else {
                        $params[$relation] = $this->getTitle(current($data));
                    }
                }
            }
            $operation .= '_' . strtoupper($relation);
        }

        return $operation;
    }
764114
public function addReferenceCache($reference)
    {
        $cache = $this->getMandango()->getCache();

        foreach ($this->getQueryHashes() as $hash) {
            $value = $cache->has($hash) ? $cache->get($hash) : array();
            if (!isset($value['references']) || !in_array($reference, $value['references'])) {
                $value['references'][] = $reference;
                $cache->set($hash, $value);
            }
        }
    }