From 042993311f911ea581655fc2693dffd2f319c717 Mon Sep 17 00:00:00 2001
From: Jaeger <JaegerCode@gmail.com>
Date: Sun, 24 Sep 2017 15:11:44 +0800
Subject: [PATCH] add getData

---
 src/Dom/Query.php | 27 +++++++++++++++++++++------
 src/QueryList.php |  5 +++--
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/Dom/Query.php b/src/Dom/Query.php
index f245eed..dbe914c 100644
--- a/src/Dom/Query.php
+++ b/src/Dom/Query.php
@@ -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()
diff --git a/src/QueryList.php b/src/QueryList.php
index 766fed8..2504d83 100644
--- a/src/QueryList.php
+++ b/src/QueryList.php
@@ -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 = [])