add Http service
This commit is contained in:
parent
2013e4d2b0
commit
042c10cdea
@ -6,7 +6,8 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"PHP":">=7.0",
|
"PHP":">=7.0",
|
||||||
"jaeger/phpquery-single": "^0.9",
|
"jaeger/phpquery-single": "^0.9",
|
||||||
"tightenco/collect": "^5.5"
|
"tightenco/collect": "^5.5",
|
||||||
|
"jaeger/g-http": "^1.1"
|
||||||
},
|
},
|
||||||
"suggest":{
|
"suggest":{
|
||||||
"monolog/monolog":"Log support"
|
"monolog/monolog":"Log support"
|
||||||
|
@ -35,7 +35,7 @@ class Query
|
|||||||
|
|
||||||
public function setHtml($html)
|
public function setHtml($html)
|
||||||
{
|
{
|
||||||
$this->html = $html;
|
$this->html = value($html);
|
||||||
$this->document = phpQuery::newDocumentHTML($this->html);
|
$this->document = phpQuery::newDocumentHTML($this->html);
|
||||||
return $this->ql;
|
return $this->ql;
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,14 @@ use QL\Contracts\ServiceProviderContract;
|
|||||||
use QL\Exceptions\ServiceNotFoundException;
|
use QL\Exceptions\ServiceNotFoundException;
|
||||||
use QL\Providers\EncodeServiceProvider;
|
use QL\Providers\EncodeServiceProvider;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use QL\Providers\HttpServiceProvider;
|
||||||
|
use QL\Providers\SystemServiceProvider;
|
||||||
|
|
||||||
class Kernel
|
class Kernel
|
||||||
{
|
{
|
||||||
protected $providers = [
|
protected $providers = [
|
||||||
|
SystemServiceProvider::class,
|
||||||
|
HttpServiceProvider::class,
|
||||||
EncodeServiceProvider::class
|
EncodeServiceProvider::class
|
||||||
];
|
];
|
||||||
|
|
||||||
|
27
src/Providers/HttpServiceProvider.php
Normal file
27
src/Providers/HttpServiceProvider.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Jaeger <JaegerCode@gmail.com>
|
||||||
|
* Date: 2017/9/22
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace QL\Providers;
|
||||||
|
|
||||||
|
|
||||||
|
use QL\Contracts\ServiceProviderContract;
|
||||||
|
use QL\Kernel;
|
||||||
|
use QL\Services\HttpService;
|
||||||
|
|
||||||
|
class HttpServiceProvider implements ServiceProviderContract
|
||||||
|
{
|
||||||
|
public function register(Kernel $kernel)
|
||||||
|
{
|
||||||
|
$kernel->bind('get',function (...$args){
|
||||||
|
return HttpService::get($this,...$args);
|
||||||
|
});
|
||||||
|
|
||||||
|
$kernel->bind('post',function (...$args){
|
||||||
|
return HttpService::post($this,...$args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
22
src/Providers/SystemServiceProvider.php
Normal file
22
src/Providers/SystemServiceProvider.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Jaeger <JaegerCode@gmail.com>
|
||||||
|
* Date: 2017/9/22
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace QL\Providers;
|
||||||
|
|
||||||
|
use QL\Contracts\ServiceProviderContract;
|
||||||
|
use QL\Kernel;
|
||||||
|
|
||||||
|
class SystemServiceProvider implements ServiceProviderContract
|
||||||
|
{
|
||||||
|
public function register(Kernel $kernel)
|
||||||
|
{
|
||||||
|
$kernel->bind('html',function ($html){
|
||||||
|
$this->setHtml($html);
|
||||||
|
return $this;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -22,12 +22,15 @@ use QL\Dom\Query;
|
|||||||
*
|
*
|
||||||
* @method QueryList getHtml()
|
* @method QueryList getHtml()
|
||||||
* @method QueryList setHtml($html)
|
* @method QueryList setHtml($html)
|
||||||
|
* @method QueryList html($html)
|
||||||
* @method Dom\Elements find($selector)
|
* @method Dom\Elements find($selector)
|
||||||
* @method QueryList rules(array $rules)
|
* @method QueryList rules(array $rules)
|
||||||
* @method QueryList range($range)
|
* @method QueryList range($range)
|
||||||
* @method QueryList removeHead()
|
* @method QueryList removeHead()
|
||||||
* @method \Illuminate\Support\Collection query($callback = null)
|
* @method \Illuminate\Support\Collection query($callback = null)
|
||||||
* @method QueryList encoding(string $outputEncoding,string $inputEncoding = null)
|
* @method QueryList encoding(string $outputEncoding,string $inputEncoding = null)
|
||||||
|
* @method QueryList get($url,$args = null,$otherArgs = [])
|
||||||
|
* @method QueryList post($url,$args = null,$otherArgs = [])
|
||||||
*/
|
*/
|
||||||
class QueryList
|
class QueryList
|
||||||
{
|
{
|
||||||
|
28
src/Services/HttpService.php
Normal file
28
src/Services/HttpService.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Jaeger <JaegerCode@gmail.com>
|
||||||
|
* Date: 2017/9/22
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace QL\Services;
|
||||||
|
|
||||||
|
use Jaeger\GHttp;
|
||||||
|
use QL\QueryList;
|
||||||
|
|
||||||
|
class HttpService
|
||||||
|
{
|
||||||
|
public static function get(QueryList $ql,$url,$args = null,$otherArgs = [])
|
||||||
|
{
|
||||||
|
$html = GHttp::get($url,$args,$otherArgs);
|
||||||
|
$ql->setHtml($html);
|
||||||
|
return $ql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function post(QueryList $ql,$url,$args = null,$otherArgs = [])
|
||||||
|
{
|
||||||
|
$html = GHttp::post($url,$args,$otherArgs);
|
||||||
|
$ql->setHtml($html);
|
||||||
|
return $ql;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user