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;
    }