| | string $fallback = '' |
| | ): string { |
| | - $computed = $this->withDedicatedHandle( $path, $action ); |
| | + $handle = @fopen( $path, 'rb' ); |
| | + $computed = false; |
| | + |
| | + if( is_resource( $handle ) ) { |
| | + $computed = $action( $handle ); |
| | + |
| | + fclose( $handle ); |
| | + } |
| | |
| | return is_string( $computed ) ? $computed : $fallback; |
| | } |
| | |
| | public function streamGeneratorDedicated( |
| | string $path, |
| | callable $action |
| | ): Generator { |
| | - $resultGenerator = $this->withDedicatedHandle( $path, $action ); |
| | + $handle = @fopen( $path, 'rb' ); |
| | |
| | - if( $resultGenerator instanceof Generator ) { |
| | - yield from $resultGenerator; |
| | + if( is_resource( $handle ) ) { |
| | + try { |
| | + $resultGenerator = $action( $handle ); |
| | + |
| | + if( $resultGenerator instanceof Generator ) { |
| | + yield from $resultGenerator; |
| | + } |
| | + } finally { |
| | + fclose( $handle ); |
| | + } |
| | } |
| | } |
 |
| | if( array_key_exists( $path, $this->handles ) ) { |
| | $result = $action( $this->handles[$path] ); |
| | - } |
| | - |
| | - return $result; |
| | - } |
| | - |
| | - private function withDedicatedHandle( |
| | - string $path, |
| | - callable $action |
| | - ): mixed { |
| | - $handle = @fopen( $path, 'rb' ); |
| | - $result = false; |
| | - |
| | - if( is_resource( $handle ) ) { |
| | - $result = $action( $handle ); |
| | - |
| | - fclose( $handle ); |
| | } |
| | |