private function accessKey($mixed, $key, $givenKey = null)
    {
        // Handle callable keys, just pass in the mixed and return the result.
        if (is_callable($key)) {
            return $key($mixed, $givenKey);
        }

        // If it's a string, an array, or accessible through []
        if (is_string($mixed) || is_array($mixed) || $mixed instanceof ArrayAccess) {
            return $mixed[$key];
        }

        // If it's an object
        if (is_object($mixed)) {
            return $mixed->{$key};
        }

        // Give up
        throw new InvalidArgumentException('Invalid object type provided, cannot access key.');
    }