Skip to content

Commit

Permalink
Use full namespaces in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Sep 30, 2021
1 parent fafa71f commit 70e2174
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
11 changes: 3 additions & 8 deletions examples/01-http.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

use Clue\React\Mq\Queue;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;
use React\Http\Browser;

require __DIR__ . '/../vendor/autoload.php';

// list of all URLs you want to download
Expand All @@ -17,17 +12,17 @@
'http://www.google.com/',
);

$browser = new Browser();
$browser = new React\Http\Browser();

// each job should use the browser to GET a certain URL
// limit number of concurrent jobs here to avoid using excessive network resources
$queue = new Queue(3, null, function ($url) use ($browser) {
$queue = new Clue\React\Mq\Queue(3, null, function ($url) use ($browser) {
return $browser->get($url);
});

foreach ($urls as $url) {
$queue($url)->then(
function (ResponseInterface $response) use ($url) {
function (Psr\Http\Message\ResponseInterface $response) use ($url) {
echo $url . ' has ' . $response->getBody()->getSize() . ' bytes' . PHP_EOL;
},
function (Exception $e) use ($url) {
Expand Down
11 changes: 3 additions & 8 deletions examples/02-http-all.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

use Clue\React\Mq\Queue;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;
use React\Http\Browser;

require __DIR__ . '/../vendor/autoload.php';

// list of all URLs you want to download
Expand All @@ -17,17 +12,17 @@
//'http://httpbin.org/delay/2',
);

$browser = new Browser();
$browser = new React\Http\Browser();

// each job should use the browser to GET a certain URL
// limit number of concurrent jobs here to avoid using excessive network resources
$promise = Queue::all(3, array_combine($urls, $urls), function ($url) use ($browser) {
$promise = Clue\React\Mq\Queue::all(3, array_combine($urls, $urls), function ($url) use ($browser) {
return $browser->get($url);
});

$promise->then(
function ($responses) {
/* @var $responses ResponseInterface[] */
/* @var $responses Psr\Http\Message\ResponseInterface[] */
echo 'All URLs succeeded!' . PHP_EOL;
foreach ($responses as $url => $response) {
echo $url . ' has ' . $response->getBody()->getSize() . ' bytes' . PHP_EOL;
Expand Down
11 changes: 3 additions & 8 deletions examples/03-http-any.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

use Clue\React\Mq\Queue;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;
use React\Http\Browser;

require __DIR__ . '/../vendor/autoload.php';

// list of all URLs you want to try
Expand All @@ -18,13 +13,13 @@
'http://www.google.com/invalid',
);

$browser = new Browser();
$browser = new React\Http\Browser();

// each job should use the browser to GET a certain URL
// limit number of concurrent jobs here to avoid using excessive network resources
$promise = Queue::any(2, $urls, function ($url) use ($browser) {
$promise = Clue\React\Mq\Queue::any(2, $urls, function ($url) use ($browser) {
return $browser->get($url)->then(
function (ResponseInterface $response) use ($url) {
function (Psr\Http\Message\ResponseInterface $response) use ($url) {
// return only the URL for the first successful response
return $url;
}
Expand Down
10 changes: 3 additions & 7 deletions examples/11-http-blocking.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?php

use Clue\React\Block;
use Clue\React\Mq\Queue;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;
use React\Http\Browser;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -20,12 +16,12 @@

function download(array $urls)
{
$browser = new Browser();
$browser = new React\Http\Browser();

$urls = array_combine($urls, $urls);
$promise = Queue::all(3, $urls, function ($url) use ($browser) {
$promise = Clue\React\Mq\Queue::all(3, $urls, function ($url) use ($browser) {
return $browser->get($url)->then(
function (ResponseInterface $response) {
function (Psr\Http\Message\ResponseInterface $response) {
// return only the body for successful responses
return $response->getBody();
},
Expand Down

0 comments on commit 70e2174

Please sign in to comment.