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

View File

@ -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"

View File

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

View File

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

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

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

View File

@ -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
{ {

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