Resolves the reference and returns its value.

@param string            $reference A reference.
@param array|ArrayAccess $values    A list of values.

@return mixed The referenced value.

@throws InvalidReferenceException If the reference is not valid.
482139
public function resolveReference($reference, $values)
    {
        foreach (explode('.', $reference) as $leaf) {
            if ((!is_array($values) && !($values instanceof ArrayAccess))
                || (is_array($values) && !array_key_exists($leaf, $values))
                || (($values instanceof ArrayAccess) && !$values->offsetExists($leaf))) {
                throw InvalidReferenceException::format(
                    'The reference "%s" could not be resolved (failed at "%s").',
                    "%$reference%",
                    $leaf
                );
            }

            $values = $values[$leaf];
        }

        return $values;
    }
1293807
protected function unsetNullRecursively($data, $reference = null)
    {
        if (is_null($reference)) {
            $reference = $data;
        }

        $this->loop($reference, function ($key, $value) use (&$data) {
            if (is_array($data)) {
                if (is_null($value)) {
                    unset($data[$key]);
                } else {
                    $data[$key] = $this->unsetNullRecursively($value);
                }
            }

            if (is_object($data)) {
                if (is_null($value)) {
                    unset($data->$key);
                } else {
                    $data->$key = $this->unsetNullRecursively($value);
                }
            }
        });

        return $data;
    }
268887
protected function getReferenceValidator($values)
    {
        return function ($val) use ($values) {
            $type = $values['type'];

            $validators = array(
                'hg' => array(
                    'regex' => '/^(https?):\/\//',
                    'message' => Lang::get('error_mercurial')
                ),
                'remote' => array(
                    'regex' => '/^(git|https?):\/\//',
                    'message' => Lang::get('error_remote')
                ),
                'gitlab' => array(
                    'regex' => '`^(.*)@(.*):(.*)/(.*)\.git`',
                    'message' => Lang::get('error_gitlab')
                ),
                'github' => array(
                    'regex' => '/^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-\.]+$/',
                    'message' => Lang::get('error_github')
                ),
                'bitbucket' => array(
                    'regex' => '/^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-\.]+$/',
                    'message' => Lang::get('error_bitbucket')
                ),
            );

            if (in_array($type, $validators) && !preg_match($validators[$type]['regex'], $val)) {
                throw new \Exception($validators[$type]['message']);
            } elseif ($type == 'local' && !is_dir($val)) {
                throw new \Exception(Lang::get('error_path'));
            }

            return true;
        };
    }
971520
protected function resolveExternal(
        UriInterface $referenceUri,
        Value\ReferenceValue $reference
    ) {
        try {
            $value = $this->reader()->read(
                $this->uriFactory()->create(
                    $referenceUri->toString()
                ),
                $reference->mimeType()
            );
        } catch (ReadException $e) {
            throw new Exception\UndefinedReferenceException(
                $reference,
                $this->currentBaseUri(),
                $e
            );
        }

        $this->pushScopeMap(
            $this->scopeMapFactory()->create($referenceUri, $value)
        );
        $value = $value->accept($this);
        $this->popScopeMap();

        $referencePointer = $this->pointerFactory()->createFromUri(
            $referenceUri
        );
        if ($referencePointer->hasAtoms()) {
            $value = $this->pointerResolver()->resolve(
                $referencePointer,
                $value
            );

            if (null === $value) {
                throw new Exception\UndefinedReferenceException(
                    $reference,
                    $this->currentBaseUri()
                );
            }
        }

        return $value;
    }
1211883
public function offsetExists($reference)
    {
        $reference = $this->mapReference($reference);

        return array_key_exists($reference, $this->container);
    }
115544
public static function trimReference($reference)
    {
        if (substr($reference, -1) == '.' || substr($reference, -1) == '-') {
            $reference = trim(substr($reference, 0, -1));
        }
        while (preg_match('/(\.0+)$/', $reference, $matches)) {
            $reference = substr($reference, 0, strlen($matches[1]) * -1);
        }
        return $reference;
    }
335226
public function readRef($fieldName)
    {
        $oRef = $this->readNestedAttribute($fieldName);
        if (!\MongoDBRef::isRef($oRef)) {
            throw new InvalidReferenceException();
        }
        if (isset($this->dbRefs) && isset($this->dbRefs[$fieldName])) {
            $modelInstance = $this->instantiateModel($this->dbRefs[$fieldName]);
        } else if ($this->getDI()->has('mongoMapper')) {
            $modelInstance = $this->getDI()->get('mongoMapper')->resolveModel($oRef['$ref']);
        } else {
            return $oRef;
        }
        return forward_static_call(array($modelInstance, 'findById'), $oRef['$id']);
    }
220792
public function hasReference( $reference, &$referenceDetail = null )
    {

        $referenceDetail = null;

        foreach( $this->__get('references') as $name => $detail ) {

            if( $name == $reference or $detail[0] == $reference ) {
                $referenceDetail = $detail;
                return $name;
            }

        }

        return null;

    }
1296993
public static function convertToPhp($value)
    {
        if (is_array($value) && isset($value['$ref'], $value['$id'])) {
            return ExtReference::create($value['$ref'], $value['$id']);
        } elseif (is_object($value) && isset($value->{'$ref'}, $value->{'$id'})) {
            return ExtReference::create($value->{'$ref'}, $value->{'$id'});
        } else {
            return null;
        }
    }
56736
protected function _reference($reference)
    {
        if (!is_string($reference)) {
            return $reference;
        }

        $pos = strrpos($reference, '\\');
        if ($pos !== false) {
            $namespace = substr($reference, 0, $pos);
            $basename = substr($reference, $pos + 1);
        } else {
            $namespace = null;
            $basename = $reference;
        }
        $substitute = null;
        $reference = Monkey::patched($namespace, $basename, false, $substitute);

        return $substitute ?: $reference;
    }
553356
public function resolve($reference)
    {
        $reference = substr($reference, 7);
        $method = $this->getMethod($reference);
        $callback = [
            $this->container->resolve($method->getOwner()),
            $method->getName()
        ];

        if ($method->hasArguments()) {
            return function () use($callback, $method)
            {
                return call_user_func_array($callback, $method->extractArguments($this->container, new ArrayResolver()));
            };
        }

        return is_array($callback) ? function () use ($callback) {
            return call_user_func_array($callback, func_get_args());
        } : $callback;
    }
381291
public function valuesArray($values) {
		if ($values instanceof \ArrayObject)
			$this->value = $values->getArrayCopy();
		elseif (is_object($values))
			$this->value = get_object_vars($values);
		elseif (is_array($values))
			$this->value = $values;
		else
			throw new \InvalidArgumentException("Method 'valuesArray' expected an object or array value");
		
		if (is_numeric(key($this->value))) {
			$this->valueList = $this->value;
			$this->value = null;
		}
		
		return $this;
	}
111198
protected function resolveInline(
        UriInterface $referenceUri,
        Value\ReferenceValue $reference
    ) {
        $scopeMap = $pointer = null;
        foreach (array_reverse($this->scopeMapStack()) as $scopeMap) {
            $pointer = $scopeMap->pointerByUri($referenceUri);
            if (null !== $pointer) {
                break;
            }
        }
        if (null === $pointer) {
            return null;
        }

        $this->pushScopeMap($scopeMap);
        $value = $scopeMap->value()->accept($this);
        $this->popScopeMap();

        $value = $this->pointerResolver()->resolve($pointer, $value);
        if (null === $value) {
            throw new Exception\UndefinedReferenceException(
                $reference,
                $this->currentBaseUri()
            );
        }

        return $value;
    }
1098912
private function parseRefAsCommit($reference): ?string
    {
        if (preg_match(self::REGEX_COMMIT, $reference, $matches) !== 1) {
            return null;
        }

        return $matches[0];
    }
589379
public function getInvoiceByReference(string $reference)
    {
        $invoiceRow = $this->_createInvoiceQuery()
            ->where(['reference' => $reference])
            ->one();

        if ($invoiceRow) {
            return new Invoice($invoiceRow);
        }

        return null;
    }
980430
public function setReference($reference = null)
    {
        $reference === null && $reference = PaymentHelper::generateReference($this->getTransactionId());
        $this->params['reference'] = $reference;
        return $this;
    }
862156
public function getByReference($reference, $type)
    {
        if (!isset($this->store[$type])) {
            return false;
        }

        $count = count($this->store[$type]);

        if ($reference >= $count) {
            throw new DeserializationException('Invalid ' . $type . ' reference: ' . $reference);
        }

        if (!$count) {
            return false;
        }

        return $this->store[$type][$reference];
    }