From f2c6ce738512e7f780245b4ad04be020ededed79 Mon Sep 17 00:00:00 2001
From: Jaeger <JaegerCode@gmail.com>
Date: Mon, 9 Oct 2017 01:48:56 +0800
Subject: [PATCH] add comments

---
 src/Config.php       | 19 +++++++++++++++
 src/Dom/Elements.php | 22 +++++++++++++++++
 src/Dom/Query.php    | 57 +++++++++++++++++++++++++++++++++++++++++---
 src/QueryList.php    | 19 +++++++++++++++
 4 files changed, 114 insertions(+), 3 deletions(-)

diff --git a/src/Config.php b/src/Config.php
index 09c9fd9..5a59ad1 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -25,12 +25,24 @@ class Config
     }
 
 
+    /**
+     * Get the Config instance
+     *
+     * @return null|Config
+     */
     public static function getInstance()
     {
         self::$instance || self::$instance = new self();
         return self::$instance;
     }
 
+    /**
+     * Global installation plugin
+     *
+     * @param $plugins
+     * @param array ...$opt
+     * @return $this
+     */
     public function use($plugins,...$opt)
     {
         if(is_string($plugins)){
@@ -41,6 +53,13 @@ class Config
         return $this;
     }
 
+    /**
+     * Global binding custom method
+     *
+     * @param string $name
+     * @param Closure $provider
+     * @return $this
+     */
     public function bind(string $name, Closure $provider)
     {
         $this->binds[$name] = $provider;
diff --git a/src/Dom/Elements.php b/src/Dom/Elements.php
index 8ba893b..5bdb705 100644
--- a/src/Dom/Elements.php
+++ b/src/Dom/Elements.php
@@ -167,6 +167,12 @@ class Elements
         return $obj;
     }
 
+    /**
+     * Iterating elements
+     *
+     * @param $callback
+     * @return \Illuminate\Support\Collection
+     */
     public function map($callback)
     {
         $collection = collect();
@@ -176,6 +182,12 @@ class Elements
         return $collection;
     }
 
+    /**
+     * Gets the attributes of all the elements
+     *
+     * @param $attr HTML attribute name
+     * @return \Illuminate\Support\Collection
+     */
     public function attrs($attr)
     {
         return $this->map(function($item) use($attr){
@@ -183,6 +195,11 @@ class Elements
         });
     }
 
+    /**
+     * Gets the text of all the elements
+     *
+     * @return \Illuminate\Support\Collection
+     */
     public function texts()
     {
         return $this->map(function($item){
@@ -190,6 +207,11 @@ class Elements
         });
     }
 
+    /**
+     * Gets the html of all the elements
+     *
+     * @return \Illuminate\Support\Collection
+     */
     public function htmls()
     {
         return $this->map(function($item){
diff --git a/src/Dom/Query.php b/src/Dom/Query.php
index 2a75110..9823206 100644
--- a/src/Dom/Query.php
+++ b/src/Dom/Query.php
@@ -30,12 +30,19 @@ class Query
         $this->ql = $ql;
     }
 
-
+    /**
+     * @return mixed
+     */
     public function getHtml()
     {
         return $this->html;
     }
 
+    /**
+     * @param $html
+     * @param null $charset
+     * @return QueryList
+     */
     public function setHtml($html, $charset = null)
     {
         $this->html = value($html);
@@ -43,22 +50,49 @@ class Query
         return $this->ql;
     }
 
+    /**
+     * Get crawl results
+     *
+     * @param Closure|null $callback
+     * @return Collection|static
+     */
     public function getData(Closure $callback = null)
     {
         return  is_null($callback) ? $this->data : $this->data->map($callback);
     }
 
+    /**
+     * @param Collection $data
+     */
     public function setData(Collection $data)
     {
         $this->data = $data;
     }
 
 
+    /**
+     * Searches for all elements that match the specified expression.
+     *
+     * @param $selector A string containing a selector expression to match elements against.
+     * @return Elements
+     */
     public function find($selector)
     {
         return (new Dom($this->document))->find($selector);
     }
 
+    /**
+     * Set crawl rule
+     *
+     * $rules = [
+     *    'rule_name1' => ['selector','HTML attribute | text | html','Tag filter list','callback'],
+     *    'rule_name2' => ['selector','HTML attribute | text | html','Tag filter list','callback'],
+     *    // ...
+     *  ]
+     *
+     * @param array $rules
+     * @return QueryList
+     */
     public function rules(array $rules)
     {
         $this->rules = $rules;
@@ -66,12 +100,23 @@ class Query
     }
 
 
-    public function range($range)
+    /**
+     * Set the slice area for crawl list
+     *
+     * @param $selector
+     * @return QueryList
+     */
+    public function range($selector)
     {
-        $this->range = $range;
+        $this->range = $selector;
         return $this->ql;
     }
 
+    /**
+     * Remove HTML head,try to solve the garbled
+     *
+     * @return QueryList
+     */
     public function removeHead()
     {
         $html = preg_replace('/<head.+?>.+<\/head>/is','<head></head>',$this->html);
@@ -79,6 +124,12 @@ class Query
         return $this->ql;
     }
 
+    /**
+     * Execute the query rule
+     *
+     * @param Closure|null $callback
+     * @return QueryList
+     */
     public function query(Closure $callback = null)
     {
         $this->data = $this->getList();
diff --git a/src/QueryList.php b/src/QueryList.php
index cc24529..994a053 100644
--- a/src/QueryList.php
+++ b/src/QueryList.php
@@ -73,22 +73,41 @@ class QueryList
         $this->destruct();
     }
 
+    /**
+     * Get the QueryList instance
+     *
+     * @return QueryList
+     */
     public static function getInstance()
     {
         $instance = new self();
         return $instance;
     }
 
+    /**
+     * Get the Config instance
+     * @return null|Config
+     */
     public static function config()
     {
         return Config::getInstance();
     }
 
+    /**
+     * Destruction of resources
+     */
     public function destruct()
     {
         phpQuery::$documents = [];
     }
 
+    /**
+     * Bind a custom method to the QueryList object
+     *
+     * @param string $name Invoking the name
+     * @param Closure $provide Called method
+     * @return $this
+     */
     public function bind(string $name,Closure $provide)
     {
         $this->kernel->bind($name,$provide);