QueryList/src/QueryList.php

82 lines
1.9 KiB
PHP
Raw Normal View History

2017-09-19 02:33:38 +08:00
<?php
/**
* QueryList
*
* 一个基于phpQuery的通用列表采集类
*
* @author Jaeger
* @email JaegerCode@gmail.com
* @link https://github.com/jae-jae/QueryList
* @version 4.0.0
*
*/
2017-09-22 01:51:46 +08:00
namespace QL;
use phpQuery;
use QL\Dom\Query;
/**
* Class QueryList
* @package QL
*
* @method QueryList getHtml()
* @method QueryList setHtml($html)
2017-09-22 02:38:46 +08:00
* @method QueryList html($html)
2017-09-22 01:51:46 +08:00
* @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)
2017-09-22 02:38:46 +08:00
* @method QueryList get($url,$args = null,$otherArgs = [])
* @method QueryList post($url,$args = null,$otherArgs = [])
2017-09-22 01:51:46 +08:00
*/
2017-09-19 02:33:38 +08:00
class QueryList
{
2017-09-22 01:51:46 +08:00
protected $query;
2017-09-21 02:20:28 +08:00
protected $kernel;
2017-09-19 02:33:38 +08:00
/**
* QueryList constructor.
*/
public function __construct()
{
2017-09-22 01:51:46 +08:00
$this->query = new Query($this);
2017-09-21 13:12:20 +08:00
$this->kernel = (new Kernel($this))->bootstrap();
2017-09-19 02:33:38 +08:00
}
2017-09-21 13:12:20 +08:00
public function __call($name, $arguments)
{
2017-09-22 01:51:46 +08:00
if(method_exists($this->query,$name)){
$result = $this->query->$name(...$arguments);
}else{
$result = $this->kernel->getService($name)->call($this,...$arguments);
}
return $result;
2017-09-19 19:06:16 +08:00
}
2017-09-22 01:51:46 +08:00
public static function __callStatic($name, $arguments)
2017-09-19 19:06:16 +08:00
{
2017-09-22 01:51:46 +08:00
$instance = self::getInstance();
return $instance->$name(...$arguments);
2017-09-19 19:06:16 +08:00
}
2017-09-22 01:51:46 +08:00
public function __destruct()
2017-09-19 19:06:16 +08:00
{
2017-09-22 01:51:46 +08:00
$this->destruct();
2017-09-19 19:06:16 +08:00
}
2017-09-22 01:51:46 +08:00
public static function getInstance()
2017-09-19 19:06:16 +08:00
{
2017-09-22 01:51:46 +08:00
$instance = new self();
return $instance;
2017-09-19 19:06:16 +08:00
}
2017-09-22 01:51:46 +08:00
public function destruct()
2017-09-19 19:06:16 +08:00
{
2017-09-22 01:51:46 +08:00
phpQuery::$documents = [];
2017-09-19 19:06:16 +08:00
}
2017-09-19 02:33:38 +08:00
}