public static function readFile($dir, $path)
    {
        if (!pathinfo($path, PATHINFO_EXTENSION)) {
            $path .= '.json';
        }

        if ($path[0] != '/') {
            $path = $dir.DIRECTORY_SEPARATOR.$path;
        }

        if (!is_file($path) || !is_readable($path)) {
            throw new \RuntimeException(sprintf('Unable to load configuration from "%s".', $path));
        }

        $data = json_decode(file_get_contents($path), true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Configuration JSON format is invalid.');
        }

        if (isset($data['$extends']) && is_string($data['$extends'])) {
            $extends = static::readFile($dir, $data['$extends']);
            $data = array_replace_recursive($extends, $data);
            unset($data['$extends']);
        }

        return $data;
    }