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

        $content = @file_get_contents(...$file_args);
        if (false === $content) {
            throw new SyntaxError(sprintf('`%s` failed to open stream: No such file or directory', $path));
        }

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

        $content = @file_get_contents(...$file_args);
        if (false === $content) {
            throw new SyntaxError(sprintf('`%s` failed to open stream: No such file or directory', $path));
        }

        return new self(
            str_replace(' ', '', (new finfo(FILEINFO_MIME))->file(...$mime_args))
            .';base64,'.base64_encode($content)
        );
    }
public static function createFromPath ( string $ path , $ context = null ) : self { $ file_args = [ $ path , false ] ; $ mime_args = [ $ path , FILEINFO_MIME ] ; if ( null !== $ context ) { $ file_args [ ] = $ context ; $ mime_args [ ] = $ context ; } $ content = @ file_get_contents ( ... $ file_args ) ; if ( false === $ content ) { throw new SyntaxError ( sprintf ( '`%s` failed to open stream: No such file or directory' , $ path ) ) ; } return new self ( str_replace ( ' ' , '' , ( new finfo ( FILEINFO_MIME ) ) -> file ( ... $ mime_args ) ) . ';base64,' . base64_encode ( $ content ) ) ; }
Create a new instance from a file path.

@param null|resource $context

@throws SyntaxError If the File is not readable
Create a new instance from a file path .