public function addResource(string $name, $resource): self
    {
        if ($resource instanceof StreamInterface) {
            $in = $resource;
        } elseif (\is_resource($resource)) {
            $in = new ResourceInputStream($resource);
        } else {
            $resource = (string) $resource;
            
            if (\preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $resource)) {
                $in = ResourceInputStream::fromUrl($resource);
            } else {
                $in = new StringStream($resource);
            }
        }
        
        $this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $in;
        
        return $this;
    }