| | private mixed $handle; |
| | private bool $temporary; |
| | + private bool $owned; |
| | |
| | - private function __construct( mixed $handle, bool $temporary ) { |
| | + private function __construct( mixed $handle, bool $temporary, bool $owned = true ) { |
| | $this->handle = $handle; |
| | $this->temporary = $temporary; |
| | + $this->owned = $owned; |
| | } |
| | |
| | public static function open( string $path ): self { |
| | return new self( @fopen( $path, 'rb' ), false ); |
| | } |
| | |
| | public static function createTemp(): self { |
| | return new self( @tmpfile(), true ); |
| | + } |
| | + |
| | + public static function wrap( mixed $handle ): self { |
| | + return new self( $handle, false, false ); |
| | } |
| | |
| | public function isOpen(): bool { |
| | return is_resource( $this->handle ); |
| | } |
| | |
| | public function __destruct() { |
| | - $this->isOpen() ? fclose( $this->handle ) : null; |
| | + $this->owned && $this->isOpen() ? fclose( $this->handle ) : null; |
| | } |
| | |