add getData

This commit is contained in:
Jaeger 2017-09-24 15:11:44 +08:00
parent b6c21b653a
commit 042993311f
2 changed files with 24 additions and 8 deletions

View File

@ -7,8 +7,10 @@
namespace QL\Dom;
use Illuminate\Support\Collection;
use phpQuery;
use QL\QueryList;
use Closure;
class Query
{
@ -17,6 +19,10 @@ class Query
protected $rules;
protected $range = null;
protected $ql;
/**
* @var Collection
*/
protected $data;
public function __construct(QueryList $ql)
@ -25,9 +31,6 @@ class Query
}
/**
* @return mixed
*/
public function getHtml()
{
return $this->html;
@ -40,6 +43,17 @@ class Query
return $this->ql;
}
public function getData(Closure $callback = null)
{
return is_null($callback) ? $this->data : $this->data->map($callback);
}
protected function setData(Collection $data)
{
$this->data = $data;
}
public function find($selector)
{
return (new Dom($this->document))->find($selector);
@ -65,10 +79,11 @@ class Query
return $this->ql;
}
public function query($callback = null)
public function query(Closure $callback = null)
{
$data = $this->getList();
return is_null($callback)?$data:$data->map($callback);
$this->data = $this->getList();
$callback && $this->data = $this->data->map($callback);
return $this;
}
protected function getList()

View File

@ -14,7 +14,7 @@
namespace QL;
use phpQuery;
use QL\Dom\Query;
use Illuminate\Support\Collection;
/**
* Class QueryList
@ -27,7 +27,8 @@ use QL\Dom\Query;
* @method QueryList rules(array $rules)
* @method QueryList range($range)
* @method QueryList removeHead()
* @method \Illuminate\Support\Collection query($callback = null)
* @method QueryList query($callback = null)
* @method Collection getData($callback = null)
* @method QueryList encoding(string $outputEncoding,string $inputEncoding = null)
* @method QueryList get($url,$args = null,$otherArgs = [])
* @method QueryList post($url,$args = null,$otherArgs = [])