PHP code example of ksuzuki2016 / laravel-http-client
1. Go to this page and download the library: Download ksuzuki2016/laravel-http-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ksuzuki2016 / laravel-http-client example snippets
php
use KSuzuki2016\HttpClient\DriverManager ;
$manager = app(KSuzuki2016\HttpClient\DriverManager::class) ;
$manager->driver('dusk')
->responseObserver( new ResponseLogObserver )
->responseObserver( new ResponseObserver )
->get('URL') ;
php
namespace KSuzuki2016\HttpClient\Logging;
use KSuzuki2016\HttpClient\Contracts\ResponseObserver;
use KSuzuki2016\HttpClient\Http\Client\HttpClientResponse;
class ResponseLogObserver extends ResponseObserver
{
public function successful(HttpClientResponse $response)
{
// 処理を書く
}
public function failed(HttpClientResponse $response)
{
// ResponseObserverを継承していれば
// 以降の処理を止める場合にbreakObservationを呼び出して停止可能
$this->breakObservation();
}
}
php
public function successful(HttpClientResponse $response)
{
$stacks = array_merge( $response->stacks() , $response->json() ) ;
$response->setStacks( $stacks ) ;
}
php
public function successful(HttpClientResponse $response)
{
return $response->setJson( 'key' , 'new value' ) ;
}