/** * Apply Highlight to FluentDOM selection * * @return FluentDOM */ public function highlight(FluentDOM $fd) { $fd->find('descendant-or-self::text()')->each(array($this, 'replace')); return $fd->spawn(); }
<?php require '../../src/FluentDOM.php'; $fd = new FluentDOM(); $fd->contentType = 'html'; $menu = $fd->append('<ul/>'); $menu->append('<li/>')->append('<a/>')->attr('href', '/sample.php')->text('Sample'); $menu->append('<li/>')->append('<a/>')->attr('href', 'http://fluentdom.org')->addClass('externalLink')->text('FluentDOM'); $menu->append('<li/>')->append('<a/>')->attr('id', 'alertSample')->attr('onclick', "alert('Hi');")->text('Alert Sample'); // mark first siblings $fd->find('//li[1]')->addClass('first'); // mark last siblings $fd->find('//li[position() = last()]')->addClass('last'); echo $fd;
<?php require '../../FluentDOM.php'; $xmlFile = 'hello.xml'; // create object $fd = new FluentDOM(); // load file $fd->load($xmlFile); echo $fd->find('/message')->text('Hello World!');
<?php /** * Sample how to use a custom FluentDOMLoader * * @version $Id: iniToXml.php 429 2010-03-29 08:05:32Z subjective $ * @package FluentDOM * @subpackage examples */ require_once dirname(__FILE__) . '/../../FluentDOM.php'; require_once dirname(__FILE__) . '/FluentDOMIniLoader.php'; $iniFile = dirname(__FILE__) . '/sample.ini'; $fd = new FluentDOM(); $fd->setLoaders(array(new FluentDOMIniLoader())); header('Content-type: text/plain'); echo $fd->load($iniFile, 'text/ini')->formatOutput(); echo "\n\n"; echo 'URL: ', $fd->find('//URL')->text();
function getDoc($fullURL, $classname, $method) { $client = new \Artax\Client(); $request = new \Artax\Request(); $client->setOption('transfertimeout', 25); echo "{$fullURL} \n"; $request->setUri($fullURL); $request->setHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'); $request->setHeader('Accept-Encoding', 'gzip,deflate,sdch'); $request->setHeader('Accept-Language', 'en-US,en;q=0.8'); $request->setHeader('Host', 'svn.php.net'); $request->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36'); //Cache-Control:max-age=0 //Connection:keep-alive //Cookie:MYPHPNET=%2C%2CNONE%2C0%2C; uvts=1nfuEIFstwB6CP0; LAST_NEWS=1401284942; COUNTRY=GBR%2C89.242.230.142; LAST_LANG=en //If-Modified-Since:Thu, 12 Jan 2012 05:08:38 GMT //If-None-Match:"322115//phpdoc/en/trunk/reference/imagick/imagick/annotateimage.xml" ///User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 $response = $client->request($request); if ($response->getStatus() != 200) { echo "Failed to read URL"; echo $response->getBody(); return null; } $contentTypeHeaders = $response->getHeader('Content-Type'); if (array_key_exists(0, $contentTypeHeaders) == false) { throw new Exception("Content-type header not set."); } $contentType = $contentTypeHeaders[0]; $colonPosition = strpos($contentType, ';'); if ($colonPosition !== false) { $contentType = substr($contentType, 0, $colonPosition); } // if ($contentType !== 'text/html') { // echo "Unknown content type $contentType"; // return; // } $SR = ['&reftitle.errors' => 'errors', '&example.outputs.similar' => 'similar', '&reftitle.returnvalues' => 'returnvalues', '&reftitle.examples' => 'examples', '&reftitle.seealso' => 'examples', '&reftitle.description' => 'description', '&reftitle.parameters' => 'parameters', '&reftitle.changelog' => 'changelog', '&Version' => 'Version', '&Description' => 'Description', '&true' => 'True', '&false' => 'False', '&return.success' => 'Return success', '&return.void' => 'return void', '&example.outputs' => 'Output', '&float' => 'float', '&reftitle.notes' => 'Notes', '&warn.undocumented.func' => 'Undocumented', '&no.function.parameters' => 'no.function.parameters', '&url.imagemagick.usage.transform.function' => 'transform.function', '&url.imagemagick' => 'ImageMagick URL']; $body = $response->getBody(); $body = str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $GLOBALS['entityBlock'], $body); $body = str_replace(array_keys($SR), array_values($SR), $body); $fluentDOM = new FluentDOM(); $fluentDOM->namespaces(['ref' => 'http://docbook.org/ns/docbook']); $manualEntry = new ManualEntry($classname, $method); //echo $body; $dom = $fluentDOM->load($body, 'text/xml'); $methodParam = function (DOMElement $element) use($manualEntry) { $name = null; $type = null; foreach ($element->childNodes as $childNode) { if ($childNode instanceof DOMElement) { if ($childNode->nodeName === 'type') { $type = $childNode->textContent; } if ($childNode->nodeName === 'parameter') { $name = $childNode->textContent; } } } $manualEntry->addParam(new Parameter($type, $name)); }; $dom->find('//ref:methodparam')->each($methodParam); $description = function (DOMElement $element) use($manualEntry) { $manualEntry->setDescription($element->textContent); }; $dom->find('//ref:refsect1[@role="description"]/ref:para')->each($description); $paramDescriptionBlock = $dom->find('//ref:refsect1[@role="parameters"]/ref:para/ref:variablelist/ref:varlistentry'); foreach ($paramDescriptionBlock as $element) { /** @var DOMElement $element */ //echo "Found entry \n"; $paramName = null; $paramDescription = null; $subDOM = new FluentDOM(); $subDOM->load($element); $subDOM->namespaces(['ref' => 'http://docbook.org/ns/docbook']); $termBlock = $subDOM->find("child::ref:term/ref:parameter"); foreach ($termBlock as $term) { /** @var DOMElement $term */ //echo $term->textContent."\n"; $paramName .= trim($term->textContent); } $descriptionBlock = $subDOM->find("child::ref:listitem/ref:para"); foreach ($descriptionBlock as $description) { /** @var DOMElement $term */ $paramDescription .= trim($description->textContent); } $manualEntry->addParamDescription($paramName, $paramDescription); } $nameBlock = $dom->find('//ref:refnamediv/ref:refname'); if ($nameBlock->count()) { foreach ($nameBlock as $nameElement) { /** @var DOMElement $term */ $manualEntry->setFunctionName($nameElement->textContent); } } if ($nameBlock->count()) { $methodDescriptionBlock = $dom->find('//ref:refnamediv/ref:refpurpose'); foreach ($methodDescriptionBlock as $methodDescriptionElement) { /** @var DOMElement $term */ $manualEntry->setMethodDescription($methodDescriptionElement->textContent); } } $returnTypeBlock = $dom->find('//ref:refsect1[@role="returnvalues"]/ref:para'); foreach ($returnTypeBlock as $returnTypeElement) { /** @var DOMElement $term */ $manualEntry->setReturnType($returnTypeElement->textContent); } $this->manualEntries[] = $manualEntry; return $manualEntry; }
/** * @group Manipulation * @group ManipulationInside * @covers FluentDOM::append */ public function testAppendDomelement() { $fd = new FluentDOM(); $fd->append('<strong>Hello</strong>'); $this->assertEquals('strong', $fd->find('/strong')->item(0)->nodeName); }