add MultiRequest
This commit is contained in:
parent
c32736bd9e
commit
a779ef71f3
@ -7,7 +7,7 @@
|
||||
|
||||
namespace QL\Dom;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
use phpQuery;
|
||||
use QL\QueryList;
|
||||
use Closure;
|
||||
|
@ -11,6 +11,7 @@ namespace QL\Providers;
|
||||
use QL\Contracts\ServiceProviderContract;
|
||||
use QL\Kernel;
|
||||
use QL\Services\HttpService;
|
||||
use QL\Services\MultiRequestService;
|
||||
|
||||
class HttpServiceProvider implements ServiceProviderContract
|
||||
{
|
||||
@ -27,5 +28,9 @@ class HttpServiceProvider implements ServiceProviderContract
|
||||
$kernel->bind('postJson',function (...$args){
|
||||
return HttpService::postJson($this,...$args);
|
||||
});
|
||||
|
||||
$kernel->bind('multiRequest',function (...$args){
|
||||
return new MultiRequestService($this,...$args);
|
||||
});
|
||||
}
|
||||
}
|
@ -14,8 +14,10 @@
|
||||
namespace QL;
|
||||
use phpQuery;
|
||||
use QL\Dom\Query;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
use Closure;
|
||||
use QL\Services\MultiRequestService;
|
||||
|
||||
|
||||
/**
|
||||
* Class QueryList
|
||||
@ -36,6 +38,7 @@ use Closure;
|
||||
* @method QueryList get($url,$args = null,$otherArgs = [])
|
||||
* @method QueryList post($url,$args = null,$otherArgs = [])
|
||||
* @method QueryList postJson($url,$args = null,$otherArgs = [])
|
||||
* @method MultiRequestService multiRequest($urls)
|
||||
* @method QueryList use($plugins,...$opt)
|
||||
* @method QueryList pipe(Closure $callback = null)
|
||||
*/
|
||||
|
44
src/Services/MultiRequestService.php
Normal file
44
src/Services/MultiRequestService.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Jaeger <JaegerCode@gmail.com>
|
||||
* Date: 18/12/10
|
||||
* Time: 下午7:05
|
||||
*/
|
||||
|
||||
namespace QL\Services;
|
||||
|
||||
|
||||
use Jaeger\GHttp;
|
||||
use Closure;
|
||||
|
||||
class MultiRequestService
|
||||
{
|
||||
protected $ql;
|
||||
protected $multiRequest;
|
||||
public function __construct($ql,$urls)
|
||||
{
|
||||
$this->ql = $ql;
|
||||
$this->multiRequest = GHttp::multiRequest($urls);
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
return $this->multiRequest->$name(...$arguments);
|
||||
}
|
||||
|
||||
public function success(Closure $success)
|
||||
{
|
||||
return $this->multiRequest->success(function($response, $index) use($success){
|
||||
$this->ql->setHtml((String)$response->getBody());
|
||||
$success($this->ql,$response, $index);
|
||||
});
|
||||
}
|
||||
|
||||
public function error(Closure $error)
|
||||
{
|
||||
return $this->multiRequest->error(function($reason, $index) use($error){
|
||||
$error($this->ql,$reason, $index);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user