add Http service

This commit is contained in:
Jaeger 2017-09-22 02:38:46 +08:00
parent 2013e4d2b0
commit 042c10cdea
7 changed files with 87 additions and 2 deletions

@ -6,7 +6,8 @@
"require": {
"PHP":">=7.0",
"jaeger/phpquery-single": "^0.9",
"tightenco/collect": "^5.5"
"tightenco/collect": "^5.5",
"jaeger/g-http": "^1.1"
},
"suggest":{
"monolog/monolog":"Log support"

@ -35,7 +35,7 @@ class Query
public function setHtml($html)
{
$this->html = $html;
$this->html = value($html);
$this->document = phpQuery::newDocumentHTML($this->html);
return $this->ql;
}

@ -11,10 +11,14 @@ use QL\Contracts\ServiceProviderContract;
use QL\Exceptions\ServiceNotFoundException;
use QL\Providers\EncodeServiceProvider;
use Closure;
use QL\Providers\HttpServiceProvider;
use QL\Providers\SystemServiceProvider;
class Kernel
{
protected $providers = [
SystemServiceProvider::class,
HttpServiceProvider::class,
EncodeServiceProvider::class
];

@ -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);
});
}
}

@ -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 setHtml($html)
* @method QueryList html($html)
* @method Dom\Elements find($selector)
* @method QueryList rules(array $rules)
* @method QueryList range($range)
* @method QueryList removeHead()
* @method \Illuminate\Support\Collection query($callback = 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
{

@ -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;
}
}