Skip to content

Commit

Permalink
Change $dom to $document (DOMDocument) or $fd (FluentDOM::Query)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWeinert committed Jun 28, 2017
1 parent cda9ca8 commit bb675a3
Show file tree
Hide file tree
Showing 76 changed files with 1,128 additions and 1,121 deletions.
8 changes: 4 additions & 4 deletions examples/Creator/Tutorial/06.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<?php
require(__DIR__.'/../../../vendor/autoload.php');

$dom = new FluentDOM\Document();
$dom->loadHtml(
$document = new FluentDOM\Document();
$document->loadHtml(
'<!DOCTYPE html>
<html><body><div id="navigation"/></body></html>'
);

$_ = FluentDOM::create();
$dom
$document
->getElementById('navigation')
->append(
$_(
Expand All @@ -22,4 +22,4 @@
)
);

echo $dom->saveHtml();
echo $document->saveHtml();
6 changes: 3 additions & 3 deletions examples/Creator/Tutorial/08.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
require('../../../vendor/autoload.php');

$dom = new FluentDOM\Document();
$dom->loadXml(
$document = new FluentDOM\Document();
$document->loadXml(
'<div>
<ul>
<li><a href="http://fluentdom.org">FluentDOM</a></li>
Expand All @@ -14,4 +14,4 @@
$_ = FluentDOM::create();
$_->formatOutput = TRUE;

echo $_('p', $dom('//a'));
echo $_('p', $document('//a'));
10 changes: 5 additions & 5 deletions examples/Extended DOM/ArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
* Otherwise it will return the attribute value.
*/

$dom = new FluentDOM\Document();
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($xml);
$dom->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
$document = new FluentDOM\Document();
$document->preserveWhiteSpace = FALSE;
$document->loadXML($xml);
$document->registerNamespace('atom', 'http://www.w3.org/2005/Atom');

foreach ($dom->evaluate('//atom:entry/atom:link') as $entry) {
foreach ($document->evaluate('//atom:entry/atom:link') as $entry) {
echo $entry['href'], "\n";
}
12 changes: 6 additions & 6 deletions examples/Extended DOM/Xpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* from a location path. It allows you to fetch a single node
* result as a node (or null).
*/
$dom = new FluentDOM\Document();
$dom->loadXml('<xml>Hello World</xml>');
$xpath = new FluentDOM\Xpath($dom);
$document = new FluentDOM\Document();
$document->loadXml('<xml>Hello World</xml>');
$xpath = new FluentDOM\Xpath($document);
echo $xpath->firstOf('//xml');

/*
Expand All @@ -17,9 +17,9 @@
* the string contains both types of quote characters.
*/
$value = "World";
$dom = new FluentDOM\Document();
$dom->loadXml('<xml>Hello World</xml>');
$xpath = new FluentDOM\Xpath($dom);
$document = new FluentDOM\Document();
$document->loadXml('<xml>Hello World</xml>');
$xpath = new FluentDOM\Xpath($document);
echo $xpath->evaluate(
'string(//xml[contains(., '.$xpath->quote($value).')])'
);
24 changes: 12 additions & 12 deletions examples/Extended DOM/__toString.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
* of the node classes, allowing for implicit and explict string casts.
*/

$dom = new FluentDOM\Document();
$dom->loadXml('<xml>Hello World!</xml>');
echo $dom->documentElement->firstChild;
$document = new FluentDOM\Document();
$document->loadXml('<xml>Hello World!</xml>');
echo $document->documentElement->firstChild;

$dom = new FluentDOM\Document();
$dom->loadXml('<xml><![CDATA[Hello World!]]></xml>');
echo $dom->documentElement->firstChild;
$document = new FluentDOM\Document();
$document->loadXml('<xml><![CDATA[Hello World!]]></xml>');
echo $document->documentElement->firstChild;

$dom = new FluentDOM\Document();
$dom->loadXml('<xml attr="Hello World!"/>');
echo $dom->documentElement->getAttributeNode('attr');
$document = new FluentDOM\Document();
$document->loadXml('<xml attr="Hello World!"/>');
echo $document->documentElement->getAttributeNode('attr');

$dom = new FluentDOM\Document();
$dom->loadXml('<xml><!--Hello World!--></xml>');
echo $dom->documentElement->firstChild;
$document = new FluentDOM\Document();
$document->loadXml('<xml><!--Hello World!--></xml>');
echo $document->documentElement->firstChild;
26 changes: 13 additions & 13 deletions examples/Loader/IniLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public function load($source, $contentType = 'text/ini', $options = []) {
throw new InvalidArgumentException('File not found: '. $source);
}
if ($iniFile = parse_ini_file($source)) {
$dom = new FluentDOM\Document();
$root = $dom->appendChild($dom->createElement('ini'));
$this->_arrayToNodes($dom, $root, $iniFile);
return $dom;
$document = new FluentDOM\Document();
$root = $document->appendChild($document->createElement('ini'));
$this->_arrayToNodes($document, $root, $iniFile);
return $document;
}
}
return FALSE;
Expand All @@ -25,32 +25,32 @@ public function loadFragment($source, $contentType = 'text/ini', $options = [])
throw new \FluentDOM\Exceptions\InvalidFragmentLoader(self::class);
}

private function _arrayToNodes(FluentDOM\Document $dom, DOMNode $node, $data) {
private function _arrayToNodes(FluentDOM\Document $document, DOMNode $node, $data) {
if (is_array($data)) {
foreach ($data as $key => $val) {
if (preg_match('(^\d+$)', $key)) {
$nodeName = $node->nodeName;
if (substr($nodeName, -1) == 's') {
$nodeName = substr($nodeName, 0, -1);
}
$childNode = $dom->createElement($nodeName);
$this->_arrayToNodes($dom, $childNode, $val);
$childNode = $document->createElement($nodeName);
$this->_arrayToNodes($document, $childNode, $val);
$node->appendChild($childNode);
} elseif (is_array($val)) {
$childNode = $dom->createElement($key);
$this->_arrayToNodes($dom, $childNode, $val);
$childNode = $document->createElement($key);
$this->_arrayToNodes($document, $childNode, $val);
$node->appendChild($childNode);
} elseif (preg_match('([\r\n\t])', $val)) {
$childNode = $dom->createElement($key);
$textNode = $dom->createTextNode($val);
$childNode = $document->createElement($key);
$textNode = $document->createTextNode($val);
$childNode->appendChild($textNode);
$node->appendChild($childNode);
} else {
$node->appendChild($dom->createElement($key, $val));
$node->appendChild($document->createElement($key, $val));
}
}
} elseif (!empty($data)) {
$textNode = $dom->createTextNode($data);
$textNode = $document->createTextNode($data);
$node->appendChild($textNode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/Query/Interfaces/ArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

require_once('../../../vendor/autoload.php');

$dom = FluentDOM($xml)->find('//p');
echo $dom[0], ' ', $dom[2];
$fd = FluentDOM($xml)->find('//p');
echo $fd[0], ' ', $fd[2];
14 changes: 7 additions & 7 deletions examples/Query/Tasks/replaceMarkup.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require('../../vendor/autoload.php');
require('../../../vendor/autoload.php');
$markup = new FluentDOMMarkupReplacer();

$html = <<<HTML
Expand Down Expand Up @@ -124,14 +124,14 @@ public function replaceNode(DOMText $node) {
/**
* Create nodes for the given string
*
* @param DOMDocument $dom
* @param DOMDocument $document
* @param string $string
* @return DOMElement
* @return DOMElement|DOMText
*/
private function createNodes($dom, $string) {
private function createNodes($document, $string) {
foreach ($this->_replacements as $pattern => $replacement) {
if (preg_match($pattern, $string)) {
$node = $dom->createElement($replacement[0]);
$node = $document->createElement($replacement[0]);
foreach ($replacement[1] as $attributeName => $attributePattern) {
$node->setAttribute(
$attributeName,
Expand All @@ -140,7 +140,7 @@ private function createNodes($dom, $string) {
)
);
}
$text = $dom->createTextNode(
$text = $document->createTextNode(
preg_replace(
$pattern, $replacement[2], $string
)
Expand All @@ -149,7 +149,7 @@ private function createNodes($dom, $string) {
return $node;
}
}
return $dom->createTextNode(
return $document->createTextNode(
strtr($string, $this->_escapings)
);
}
Expand Down
20 changes: 10 additions & 10 deletions examples/Query/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@
XML;

require('../../vendor/autoload.php');
$dom = FluentDOM($xml);
echo $dom
$fd = FluentDOM($xml);
echo $fd
->find('//p')
->add('//p/b')
->toggleClass('inB');

echo "\n\n";

$dom = FluentDOM($xml);
echo $dom
$fd = FluentDOM($xml);
echo $fd
->find('//p')
->add(
$dom->find('//div')
$fd->find('//div')
)
->toggleClass('inB');

echo "\n\n";

$dom = FluentDOM($xml);
echo $dom
$fd = FluentDOM($xml);
echo $fd
->add(
$dom->find('//div')
$fd->find('//div')
)
->toggleClass('inB');

echo "\n\n";

$dom = FluentDOM($xml);
echo $dom
$fd = FluentDOM($xml);
echo $fd
->add('//div')
->toggleClass('inB');
10 changes: 5 additions & 5 deletions examples/Query/addBack.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
XML;

require('../../vendor/autoload.php');
$dom = FluentDOM($xml);
echo $dom
$fd = FluentDOM($xml);
echo $fd
->find('//p')
->find('.//b')
->addBack()
->toggleClass('inB');

echo "\n\n";

$dom = FluentDOM($xml);
echo $dom
$fd = FluentDOM($xml);
echo $fd
->find('//p')
->find(
$dom->find('//div')
$fd->find('//div')
)
->addBack()
->toggleClass('inB');
Expand Down
6 changes: 3 additions & 3 deletions examples/Query/append.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

echo "\n\n";

$dom = FluentDOM($html);
$items = $dom->find('//group/item');
echo $dom
$fd = FluentDOM($html);
$items = $fd->find('//group/item');
echo $fd
->find('//html/div')
->append($items)
->formatOutput();
6 changes: 3 additions & 3 deletions examples/Query/attr.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


echo "Example for function 'attr' using XML namespaces:\n\n";
$dom = FluentDOM($xml);
$dom->registerNamespace('h', 'http://www.w3.org/1999/xhtml');
echo $dom
$fd = FluentDOM($xml);
$fd->registerNamespace('h', 'http://www.w3.org/1999/xhtml');
echo $fd
->find('//h:a')
->attr('href');
4 changes: 2 additions & 2 deletions examples/Query/closest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
</html>
HTML;

$dom = FluentDOM($xml, 'text/html');
echo $dom
$fd = FluentDOM($xml, 'text/html');
echo $fd
->find('//u')
->closest('self::li')
->addClass('foundIt');
4 changes: 2 additions & 2 deletions examples/Query/is.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
</html>
HTML;

$dom = FluentDOM($html, 'text/html');
$fd = FluentDOM($html, 'text/html');
var_dump(
$dom
$fd
->find('//input[@type = "checkbox"]')
->parent()
->is('name() = "form"')
Expand Down
6 changes: 3 additions & 3 deletions examples/Query/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

require_once('../../vendor/autoload.php');

$dom = new DOMDocument();
$dom->loadXML('<message>Hello World!</message>');
$document = new DOMDocument();
$document->loadXML('<message>Hello World!</message>');
$fd = new FluentDOM\Nodes();
$fd->load($dom);
$fd->load($document);

foreach ($fd->find('//message') as $message) {
echo $message->nodeValue;
Expand Down
6 changes: 3 additions & 3 deletions examples/Query/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
</html>
HTML;

$dom = FluentDOM($html);
echo $dom
$fd = FluentDOM($html);
echo $fd
->find('//p')
->append(
implode(
', ',
$dom
$fd
->find('//input')
->map(
function($node, $index) {
Expand Down
Loading

0 comments on commit bb675a3

Please sign in to comment.