Skip to content

Commit 288df62

Browse files
committed
Issue #89: Numerous calls to qp() replaced.
There were many cases in the source where calls to qp() should have been replaced with QueryPath::with(). This is necessary because we are no longer requiring the function qp().
1 parent 4c7665c commit 288df62

File tree

8 files changed

+40
-32
lines changed

8 files changed

+40
-32
lines changed

src/QueryPath.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,21 @@ class QueryPath {
152152
</html>';
153153

154154

155-
public static function with($document, $selector = NULL, $options = array()) {
155+
public static function with($document = NULL, $selector = NULL, $options = array()) {
156156
$qpClass = isset($options['QueryPath_class']) ? $options['QueryPath_class'] : '\QueryPath\DOMQuery';
157157

158158
$qp = new $qpClass($document, $selector, $options);
159159
return $qp;
160160
}
161161

162-
public static function withXML($source, $selector = NULL, $options = array()) {
162+
public static function withXML($source = NULL, $selector = NULL, $options = array()) {
163163
$options += array(
164164
'use_parser' => 'xml',
165165
);
166166
return self::with($source, $selector, $options);
167167
}
168168

169-
public static function withHTML($source, $selector = NULL, $options = array()) {
169+
public static function withHTML($source = NULL, $selector = NULL, $options = array()) {
170170
// Need a way to force an HTML parse instead of an XML parse when the
171171
// doctype is XHTML, since many XHTML documents are not valid XML
172172
// (because of coding errors, not by design).

src/QueryPath/DOMQuery.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace QueryPath;
1515

1616
use \QueryPath\CSS\QueryPathEventHandler;
17+
use \QueryPath;
1718

1819

1920
/**
@@ -764,7 +765,7 @@ public function is($selector) {
764765
*/
765766
public function filter($selector) {
766767
$found = new \SplObjectStorage();
767-
foreach ($this->matches as $m) if (qp($m, NULL, $this->options)->is($selector)) $found->attach($m);
768+
foreach ($this->matches as $m) if (QueryPath::with($m, NULL, $this->options)->is($selector)) $found->attach($m);
768769
$this->setMatches($found);
769770
return $this;
770771
}
@@ -1009,7 +1010,7 @@ public function not($selector) {
10091010
foreach ($this->matches as $m) if ($selector->contains($m)) $found->attach($m);
10101011
}
10111012
else {
1012-
foreach ($this->matches as $m) if (!qp($m, NULL, $this->options)->is($selector)) $found->attach($m);
1013+
foreach ($this->matches as $m) if (!QueryPath::with($m, NULL, $this->options)->is($selector)) $found->attach($m);
10131014
}
10141015
$this->setMatches($found);
10151016
return $this;
@@ -1863,7 +1864,7 @@ public function replaceAll($selector, \DOMDocument $document) {
18631864
$node = $document->importNode($node);
18641865
$item->parentNode->replaceChild($node, $item);
18651866
}
1866-
return qp($document, NULL, $this->options);
1867+
return QueryPath::with($document, NULL, $this->options);
18671868
}
18681869
/**
18691870
* Add more elements to the current set of matches.
@@ -1886,8 +1887,9 @@ public function add($selector) {
18861887
// This is destructive, so we need to set $last:
18871888
$this->last = $this->matches;
18881889

1889-
foreach (qp($this->document, $selector, $this->options)->get() as $item)
1890+
foreach (QueryPath::with($this->document, $selector, $this->options)->get() as $item) {
18901891
$this->matches->attach($item);
1892+
}
18911893
return $this;
18921894
}
18931895
/**
@@ -2097,14 +2099,14 @@ public function closest($selector) {
20972099
$found = new \SplObjectStorage();
20982100
foreach ($this->matches as $m) {
20992101

2100-
if (qp($m, NULL, $this->options)->is($selector) > 0) {
2102+
if (QueryPath::with($m, NULL, $this->options)->is($selector) > 0) {
21012103
$found->attach($m);
21022104
}
21032105
else {
21042106
while ($m->parentNode->nodeType !== XML_DOCUMENT_NODE) {
21052107
$m = $m->parentNode;
21062108
// Is there any case where parent node is not an element?
2107-
if ($m->nodeType === XML_ELEMENT_NODE && qp($m, NULL, $this->options)->is($selector) > 0) {
2109+
if ($m->nodeType === XML_ELEMENT_NODE && QueryPath::with($m, NULL, $this->options)->is($selector) > 0) {
21082110
$found->attach($m);
21092111
break;
21102112
}
@@ -2137,7 +2139,7 @@ public function parent($selector = NULL) {
21372139
// Is there any case where parent node is not an element?
21382140
if ($m->nodeType === XML_ELEMENT_NODE) {
21392141
if (!empty($selector)) {
2140-
if (qp($m, NULL, $this->options)->is($selector) > 0) {
2142+
if (QueryPath::with($m, NULL, $this->options)->is($selector) > 0) {
21412143
$found->attach($m);
21422144
break;
21432145
}
@@ -2173,7 +2175,7 @@ public function parents($selector = NULL) {
21732175
// Is there any case where parent node is not an element?
21742176
if ($m->nodeType === XML_ELEMENT_NODE) {
21752177
if (!empty($selector)) {
2176-
if (qp($m, NULL, $this->options)->is($selector) > 0)
2178+
if (QueryPath::with($m, NULL, $this->options)->is($selector) > 0)
21772179
$found->attach($m);
21782180
}
21792181
else
@@ -2775,7 +2777,7 @@ public function next($selector = NULL) {
27752777
$m = $m->nextSibling;
27762778
if ($m->nodeType === XML_ELEMENT_NODE) {
27772779
if (!empty($selector)) {
2778-
if (qp($m, NULL, $this->options)->is($selector) > 0) {
2780+
if (QueryPath::with($m, NULL, $this->options)->is($selector) > 0) {
27792781
$found->attach($m);
27802782
break;
27812783
}
@@ -2813,7 +2815,7 @@ public function nextAll($selector = NULL) {
28132815
$m = $m->nextSibling;
28142816
if ($m->nodeType === XML_ELEMENT_NODE) {
28152817
if (!empty($selector)) {
2816-
if (qp($m, NULL, $this->options)->is($selector) > 0) {
2818+
if (QueryPath::with($m, NULL, $this->options)->is($selector) > 0) {
28172819
$found->attach($m);
28182820
}
28192821
}
@@ -2850,7 +2852,7 @@ public function prev($selector = NULL) {
28502852
$m = $m->previousSibling;
28512853
if ($m->nodeType === XML_ELEMENT_NODE) {
28522854
if (!empty($selector)) {
2853-
if (qp($m, NULL, $this->options)->is($selector)) {
2855+
if (QueryPath::with($m, NULL, $this->options)->is($selector)) {
28542856
$found->attach($m);
28552857
break;
28562858
}
@@ -2888,7 +2890,7 @@ public function prevAll($selector = NULL) {
28882890
$m = $m->previousSibling;
28892891
if ($m->nodeType === XML_ELEMENT_NODE) {
28902892
if (!empty($selector)) {
2891-
if (qp($m, NULL, $this->options)->is($selector)) {
2893+
if (QueryPath::with($m, NULL, $this->options)->is($selector)) {
28922894
$found->attach($m);
28932895
}
28942896
}
@@ -2910,7 +2912,7 @@ public function peers($selector = NULL) {
29102912
foreach ($m->parentNode->childNodes as $kid) {
29112913
if ($kid->nodeType == XML_ELEMENT_NODE && $m !== $kid) {
29122914
if (!empty($selector)) {
2913-
if (qp($kid, NULL, $this->options)->is($selector)) {
2915+
if (QueryPath::with($kid, NULL, $this->options)->is($selector)) {
29142916
$found->attach($kid);
29152917
}
29162918
}
@@ -3458,7 +3460,7 @@ public function nextUntil($selector = NULL) {
34583460
$m = $m->nextSibling;
34593461
if ($m->nodeType === XML_ELEMENT_NODE) {
34603462
if (!empty($selector)) {
3461-
if (qp($m, NULL, $this->options)->is($selector) > 0) {
3463+
if (QueryPath::with($m, NULL, $this->options)->is($selector) > 0) {
34623464
break;
34633465
}
34643466
else {
@@ -3500,7 +3502,7 @@ public function prevUntil($selector = NULL) {
35003502
while (isset($m->previousSibling)) {
35013503
$m = $m->previousSibling;
35023504
if ($m->nodeType === XML_ELEMENT_NODE) {
3503-
if (!empty($selector) && qp($m, NULL, $this->options)->is($selector))
3505+
if (!empty($selector) && QueryPath::with($m, NULL, $this->options)->is($selector))
35043506
break;
35053507
else
35063508
$found->attach($m);
@@ -3534,7 +3536,7 @@ public function parentsUntil($selector = NULL) {
35343536
// Is there any case where parent node is not an element?
35353537
if ($m->nodeType === XML_ELEMENT_NODE) {
35363538
if (!empty($selector)) {
3537-
if (qp($m, NULL, $this->options)->is($selector) > 0)
3539+
if (QueryPath::with($m, NULL, $this->options)->is($selector) > 0)
35383540
break;
35393541
else
35403542
$found->attach($m);

src/QueryPath/Extension/QPDB.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@
109109
*/
110110

111111
namespace QueryPath\Extension;
112+
112113
use \PDO;
114+
use \QueryPath;
113115

114116
/**
115117
* Provide DB access to a QueryPath object.
@@ -586,7 +588,7 @@ protected function addData($columnName, $qpFunc = 'append', $wrap = NULL) {
586588
if (isset($row[$col])) {
587589
$data = $row[$col];
588590
if ($hasWrap)
589-
$data = qp()->append($wrap)->deepest()->append($data)->top();
591+
$data = QueryPath::with()->append($wrap)->deepest()->append($data)->top();
590592
$this->qp->$qpFunc($data);
591593
}
592594
}
@@ -600,7 +602,7 @@ protected function addData($columnName, $qpFunc = 'append', $wrap = NULL) {
600602
if (isset($this->row[$col])) {
601603
$data = $this->row[$col];
602604
if ($hasWrap)
603-
$data = qp()->append($wrap)->deepest()->append($data)->top();
605+
$data = QueryPath::with()->append($wrap)->deepest()->append($data)->top();
604606
$this->qp->$qpFunc($data);
605607
}
606608
}

src/QueryPath/Extension/QPList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function appendTable($items, $options = array()) {
3636
</tbody>
3737
</table>';
3838

39-
$qp = qp($base, 'table')->addClass($opts['table class'])->find('tr');
39+
$qp = \QueryPath::with($base, 'table')->addClass($opts['table class'])->find('tr');
4040
if ($items instanceof TableAble) {
4141
$headers = $items->getHeaders();
4242
$rows = $items->getRows();
@@ -90,7 +90,7 @@ public function appendList($items, $type = self::UL, $options = array()) {
9090
'list class' => 'qplist',
9191
);
9292
if ($type == self::DL) {
93-
$q = qp('<?xml version="1.0"?><dl></dl>', 'dl')->addClass($opts['list class']);
93+
$q = \QueryPath::with('<?xml version="1.0"?><dl></dl>', 'dl')->addClass($opts['list class']);
9494
foreach ($items as $dt => $dd) {
9595
$q->append('<dt>' . $dt . '</dt><dd>' . $dd . '</dd>');
9696
}
@@ -110,7 +110,7 @@ public function appendList($items, $type = self::UL, $options = array()) {
110110
protected function listImpl($items, $type, $opts, $q = NULL) {
111111
$ele = '<' . $type . '/>';
112112
if (!isset($q))
113-
$q = qp()->append($ele)->addClass($opts['list class']);
113+
$q = \QueryPath::with()->append($ele)->addClass($opts['list class']);
114114

115115
foreach ($items as $li) {
116116
if ($li instanceof QueryPath) {

src/QueryPath/Extension/QPTPL.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
namespace QueryPath\Extension;
7+
8+
use \QueryPath;
79
/**
810
* QPTPL is a template library for QueryPath.
911
*
@@ -75,7 +77,7 @@ public function tpl($template, $object, $options = array()) {
7577
// Handle default options here.
7678

7779
//$tqp = ($template instanceof QueryPath) ? clone $template: qp($template);
78-
$tqp = qp($template);
80+
$tqp = QueryPath::with($template);
7981

8082
if (is_array($object) || $object instanceof \Traversable) {
8183
$this->tplArrayR($tqp, $object, $options);
@@ -106,7 +108,7 @@ public function tpl($template, $object, $options = array()) {
106108
* Returns the QueryPath object.
107109
*/
108110
public function tplAll($template, $objects, $options = array()) {
109-
$tqp = qp($template, ':root');
111+
$tqp = QueryPath::with($template, ':root');
110112
foreach ($objects as $object) {
111113
if (is_array($object))
112114
$tqp = $this->tplArrayR($tqp, $object, $options);
@@ -262,7 +264,7 @@ public function tplArrayR($qp, $array, $options = NULL) {
262264
$dom_tpl[] = $element->cloneNode(true);
263265
}
264266
//populate the copy via recursion
265-
$tpl = $this->tplArrayR(htmlqp($dom_tpl), $v, $options);
267+
$tpl = $this->tplArrayR(QueryPath::withHTML($dom_tpl), $v, $options);
266268
//insert the copy into the document
267269
$qp->before($tpl);
268270
}

src/QueryPath/Extension/QPXML.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* XML extensions. See QPXML.
44
*/
55
namespace QueryPath\Extension;
6+
7+
use \QueryPath;
68
/**
79
* Provide QueryPath with additional XML tools.
810
*
@@ -185,7 +187,7 @@ public function createElement($text, $nsUri = null) {
185187
} else {
186188
$node = $element->ownerDocument->createElement($text);
187189
}
188-
return qp($node);
190+
return QueryPath::with($node);
189191
}
190192
}
191193
return;
@@ -201,7 +203,7 @@ public function appendElement($text) {
201203
if (isset ($text)) {
202204
foreach ($this->qp->get() as $element) {
203205
$node = $this->qp->createElement($text);
204-
qp($element)->append($node);
206+
QueryPath::with($element)->append($node);
205207
}
206208
}
207209
return $this->qp;

src/QueryPath/Extension/QPXSL.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public function __construct(\QueryPath\Query $qp) {
6565
*/
6666
public function xslt($style) {
6767
if (!($style instanceof QueryPath)) {
68-
$style = qp($style);
68+
$style = \QueryPath::with($style);
6969
}
7070
$sourceDoc = $this->src->top()->get(0)->ownerDocument;
7171
$styleDoc = $style->get(0)->ownerDocument;
7272
$processor = new \XSLTProcessor();
7373
$processor->importStylesheet($styleDoc);
74-
return qp($processor->transformToDoc($sourceDoc));
74+
return \QueryPath::with($processor->transformToDoc($sourceDoc));
7575
}
7676
}

src/QueryPath/QueryPathIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class QueryPathIterator extends \IteratorIterator {
2121

2222
public function current() {
2323
if (!isset($this->qp)) {
24-
$this->qp = qp(parent::current(), NULL, $this->options);
24+
$this->qp = \QueryPath::with(parent::current(), NULL, $this->options);
2525
}
2626
else {
2727
$splos = new \SplObjectStorage();

0 commit comments

Comments
 (0)