add Dom
This commit is contained in:
parent
e3576ce407
commit
fe749f08c2
@ -5,7 +5,8 @@
|
||||
"homepage": "http://querylist.cc",
|
||||
"require": {
|
||||
"PHP":">=5.6.0",
|
||||
"jaeger/phpquery-single": "^0.9"
|
||||
"jaeger/phpquery-single": "^0.9",
|
||||
"illuminate/support": "^5.5"
|
||||
},
|
||||
"suggest":{
|
||||
"monolog/monolog":"Log support"
|
||||
|
15
src/Dom.php
15
src/Dom.php
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: iamhj
|
||||
* Date: 2017/9/19
|
||||
* Time: 2:00
|
||||
*/
|
||||
|
||||
namespace QL;
|
||||
|
||||
|
||||
class Dom
|
||||
{
|
||||
|
||||
}
|
30
src/Dom/Dom.php
Normal file
30
src/Dom/Dom.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Jaeger <JaegerCode@gmail.com>
|
||||
* Date: 2017/9/19
|
||||
*/
|
||||
|
||||
namespace QL\Dom;
|
||||
|
||||
use phpQueryObject;
|
||||
|
||||
class Dom
|
||||
{
|
||||
|
||||
protected $document;
|
||||
|
||||
/**
|
||||
* Dom constructor.
|
||||
*/
|
||||
public function __construct(phpQueryObject $document)
|
||||
{
|
||||
$this->document = $document;
|
||||
}
|
||||
|
||||
public function find($selector)
|
||||
{
|
||||
$elements = $this->document->find($selector);
|
||||
return new Elements($elements);
|
||||
}
|
||||
}
|
53
src/Dom/Elements.php
Normal file
53
src/Dom/Elements.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Jaeger <JaegerCode@gmail.com>
|
||||
* Date: 2017/9/19
|
||||
*/
|
||||
|
||||
namespace QL\Dom;
|
||||
|
||||
use phpQueryObject;
|
||||
|
||||
class Elements
|
||||
{
|
||||
protected $elements;
|
||||
|
||||
/**
|
||||
* Elements constructor.
|
||||
* @param $elements
|
||||
*/
|
||||
public function __construct(phpQueryObject $elements)
|
||||
{
|
||||
$this->elements = $elements;
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
return property_exists($this->elements,$name)?$this->elements->$name:$this->elements->attr($name);
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
$obj = call_user_func_array([$this->elements,$name],$arguments);
|
||||
return $obj instanceof phpQueryObject?(new self($obj)):$obj;
|
||||
}
|
||||
|
||||
public function map($callback)
|
||||
{
|
||||
$collection = collect();
|
||||
$this->elements->each(function($dom) use(& $collection,$callback){
|
||||
$collection->push($callback(new self(pq($dom))));
|
||||
});
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function attrs($attr)
|
||||
{
|
||||
return $this->map(function($item) use($attr){
|
||||
return $item->attr($attr);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace QL;
|
||||
use phpQuery;
|
||||
use QL\Dom\Dom;
|
||||
|
||||
/**
|
||||
* QueryList
|
||||
@ -36,7 +37,8 @@ class QueryList
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $html
|
||||
* @param $html
|
||||
* @return $this
|
||||
*/
|
||||
public function setHtml($html)
|
||||
{
|
||||
@ -47,7 +49,7 @@ class QueryList
|
||||
|
||||
public function find($selector)
|
||||
{
|
||||
return pq($this->document)->find($selector);
|
||||
return (new Dom($this->document))->find($selector);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user