Skip to content

Commit ef1ee2e

Browse files
committed
Implement stream_cast in StreamWrapper
This allows PHP to extract native file descriptors when passing user-space streams to low-level functions like proc_open(). This resolves compatibility issues with Symfony Process and Laravel's artisan serve command.
1 parent ec4d2bd commit ef1ee2e

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/Command/RunCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ public function execute(array $args, $outputStream = STDOUT, $errorStream = STDE
6464

6565
return 0;
6666
}
67-
}
67+
}

src/Internal/StreamWrapper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ public function stream_stat(): array|false
278278
return fstat($this->handle);
279279
}
280280

281+
/**
282+
* Extracts the underlying native file descriptor for C-level functions like proc_open() or stream_select().
283+
*
284+
* @return resource|false
285+
*/
286+
public function stream_cast(int $cast_as)
287+
{
288+
return $this->handle !== null ? $this->handle : false;
289+
}
290+
281291
public function stream_seek(int $offset, int $whence = SEEK_SET): bool
282292
{
283293
if ($this->handle === null) {

src/Internal/StreamWrapperInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ public function unlink(string $path): bool;
5858
public function rename(string $pathFrom, string $pathTo): bool;
5959

6060
public function stream_metadata(string $path, int $option, mixed $value): bool;
61+
62+
/**
63+
* @return resource|false
64+
*/
65+
public function stream_cast(int $cast_as);
6166
}

0 commit comments

Comments
 (0)