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('/