-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WordPress Playground compatibility (#31)
This PR makes the Blueprints PHP library work in Playground: https://playground.wordpress.net/demos/php-blueprints.html The main change is the addition of `PlaygroundFetchSource` to download data using browser's `fetch()` (Playground support added in WordPress/wordpress-playground#1070). The rest is cosmetics. Related Playground PR WordPress/wordpress-playground#1051
- Loading branch information
Showing
12 changed files
with
172 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace WordPress\DataSource; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
use Symfony\Component\HttpClient\Response\StreamWrapper; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
use WordPress\Streams\StreamPeeker; | ||
use WordPress\Streams\StreamPeekerContext; | ||
|
||
class PlaygroundFetchSource extends BaseDataSource { | ||
|
||
public $proc_handles = []; | ||
|
||
public function stream( $resourceIdentifier ) { | ||
$url = $resourceIdentifier; | ||
$proc_handle = proc_open( | ||
[ 'fetch', $url, ], | ||
[ 1 => [ 'pipe', 'w' ], 2 => [ 'pipe', 'w' ] ], | ||
$pipes | ||
); | ||
// This prevents the process handle from getting garbage collected and | ||
// breaking the stdout pipe. However, how the program never terminates. | ||
// Presumably we need to peek() on the resource handle and close the | ||
// process handle when it's done. | ||
// Without this line, we get the following error: | ||
// PHP Fatal error: Uncaught TypeError: stream_copy_to_stream(): supplied resource is not a valid stream resource i | ||
// var_dump()–ing first says | ||
// resource(457) of type (stream) | ||
// but then it says | ||
// resource(457) of type (Unknown) | ||
$this->proc_handles[] = $proc_handle; | ||
|
||
return $pipes[1]; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.