public static function createFromDataPath(string $path, $context = null): self
    {
        $file_args = [$path, false];
        $mime_args = [$path, FILEINFO_MIME];
        if (null !== $context) {
            $file_args[] = $context;
            $mime_args[] = $context;
        }

        $raw = @file_get_contents(...$file_args);
        if (false === $raw) {
            throw new SyntaxError(sprintf('The file `%s` does not exist or is not readable', $path));
        }

        return Uri::createFromComponents([
            'scheme' => 'data',
            'path' => str_replace(' ', '', (new finfo(FILEINFO_MIME))->file(...$mime_args)).';base64,'.base64_encode($raw),
        ]);
    }
public static function createFromDataPath(string $path, $context = null): self
    {
        $file_args = [$path, false];
        $mime_args = [$path, FILEINFO_MIME];
        if (null !== $context) {
            $file_args[] = $context;
            $mime_args[] = $context;
        }

        $raw = @file_get_contents(...$file_args);
        if (false === $raw) {
            throw new SyntaxError(sprintf('The file `%s` does not exist or is not readable', $path));
        }

        return Uri::createFromComponents([
            'scheme' => 'data',
            'path' => str_replace(' ', '', (new finfo(FILEINFO_MIME))->file(...$mime_args)).';base64,'.base64_encode($raw),
        ]);
    }
public static function createFromDataPath ( string $ path , $ context = null ) : self { $ file_args = [ $ path , false ] ; $ mime_args = [ $ path , FILEINFO_MIME ] ; if ( null !== $ context ) { $ file_args [ ] = $ context ; $ mime_args [ ] = $ context ; } $ raw = @ file_get_contents ( ... $ file_args ) ; if ( false === $ raw ) { throw new SyntaxError ( sprintf ( 'The file `%s` does not exist or is not readable' , $ path ) ) ; } return Uri :: createFromComponents ( [ 'scheme' => 'data' , 'path' => str_replace ( ' ' , '' , ( new finfo ( FILEINFO_MIME ) ) -> file ( ... $ mime_args ) ) . ';base64,' . base64_encode ( $ raw ) , ] ) ; }
Create a new instance from a data file path.

@param resource|null $context

@throws SyntaxError If the file does not exist or is not readable
Create a new instance from a data file path .