Created
October 11, 2012 23:46
-
-
Save igorw/3876447 to your computer and use it in GitHub Desktop.
React Http Client
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
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use React\Curry\Util as Curry; | |
$projects = array( | |
'react-php/react', | |
'cboden/Ratchet', | |
'nrk/predis-async', | |
'bergie/dnode-php', | |
'umpirsky/wisdom', | |
'igorw/evenement', | |
); | |
$fullRequest = function ($url, $callback) { | |
$callback(file_get_contents($url)); | |
}; | |
$parseResponse = function ($project, $body) { | |
$decoded = json_decode($body, true); | |
$latest = $decoded[0]['commit']; | |
$author = $latest['author']['name']; | |
$date = date('F j, Y', strtotime($latest['author']['date'])); | |
$message = preg_replace('#\n.*$#s', '', $latest['message']); | |
printf("\n"); | |
printf("Latest commit on %s was done by %s on %s\n", $project, $author, $date); | |
printf("%s\n", $message); | |
}; | |
printf("I'm telling you about %s projects.\n", count($projects)); | |
foreach ($projects as $project) { | |
$url = "https://api.github.com/repos/$project/commits"; | |
$fullRequest($url, Curry::bind($parseResponse, $project)); | |
} |
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
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use React\Curry\Util as Curry; | |
$loop = React\EventLoop\Factory::create(); | |
$client = new React\HttpClient\Client($loop); | |
$projects = array( | |
'react-php/react', | |
'cboden/Ratchet', | |
'nrk/predis-async', | |
'bergie/dnode-php', | |
'umpirsky/wisdom', | |
'igorw/evenement', | |
); | |
$fullRequest = function ($url, $callback) use ($client) { | |
$request = $client->request('GET', $url); | |
$request->on('response', function ($response) use ($callback) { | |
$buffer = ''; | |
$response->on('data', function ($data) use (&$buffer) { | |
$buffer .= $data; | |
}); | |
$response->on('end', function () use (&$buffer, $callback) { | |
$callback($buffer); | |
}); | |
}); | |
$request->end(); | |
}; | |
$parseResponse = function ($project, $body) { | |
$decoded = json_decode($body, true); | |
$latest = $decoded[0]['commit']; | |
$author = $latest['author']['name']; | |
$date = date('F j, Y', strtotime($latest['author']['date'])); | |
$message = preg_replace('#\n.*$#s', '', $latest['message']); | |
printf("\n"); | |
printf("Latest commit on %s was done by %s on %s\n", $project, $author, $date); | |
printf("%s\n", $message); | |
}; | |
printf("I'm telling you about %s projects.\n", count($projects)); | |
foreach ($projects as $project) { | |
$url = "https://api.github.com/repos/$project/commits"; | |
$fullRequest($url, Curry::bind($parseResponse, $project)); | |
} | |
$loop->run(); |
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
{ | |
"repositories": [ | |
{ | |
"type": "vcs", | |
"url": "https://github.com/arnaud-lb/react" | |
} | |
], | |
"minimum-stability": "dev", | |
"require": { | |
"react/react": "dev-http-client", | |
"react/curry": "dev-master" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Catchable fatal error: Argument 2 passed to React\HttpClient\Client::__construct() must be an instance of React\HttpClient\ConnectionManagerInterface, none given, called in C:\wamp\www\httpclient\index.php on line 5 and defined in C:\wamp\www\httpclient\vendor\react\react\src\React\HttpClient\Client.php on line 19`
Got the same error.