当前位置: 首页>>代码示例>>PHP>>正文


PHP FluentDOM函数代码示例

本文整理汇总了PHP中FluentDOM函数的典型用法代码示例。如果您正苦于以下问题:PHP FluentDOM函数的具体用法?PHP FluentDOM怎么用?PHP FluentDOM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FluentDOM函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFunctionWithContent

 /**
  * @group GlobalFunctions
  */
 public function testFunctionWithContent()
 {
     $dom = new DOMDocument();
     $node = $dom->appendChild($dom->createElement('html'));
     $fd = FluentDOM($node);
     $this->assertTrue($fd instanceof FluentDOM);
     $this->assertTag(array('tag' => 'html'), $fd->document);
 }
开发者ID:noels,项目名称:FluentDOM,代码行数:11,代码来源:FluentDOMTest.php

示例2: testCollectionPath

 public function testCollectionPath()
 {
     $feedPath = $this->getFoodieMultilevelPath();
     // id nodes should score 1
     $scorer = new IsUnique();
     $this->assertEquals(1, $scorer->__invoke(FluentDOM($feedPath)->find('/items/item[position()=1]/id')[0]));
     // city should score 0 (all city fields are the same)
     $scorer = new IsUnique();
     $this->assertEquals(0, $scorer->__invoke(FluentDOM($feedPath)->find('/items/item[position()=1]/city')[0]));
     // score with an exponent
     $scorer = new IsUnique(2);
     $this->assertEquals(1, $scorer->__invoke(FluentDOM($feedPath)->find('/items/item[position()=1]/id')[0]));
     $scorer = new IsUnique(2);
     $this->assertEquals(0, $scorer->__invoke(FluentDOM($feedPath)->find('/items/item[position()=1]/city')[0]));
 }
开发者ID:tbug,项目名称:whatthefield,代码行数:15,代码来源:UniqueTest.php

示例3: __invoke

 /**
  * Check if DOMNode is unique (compared to it's siblings)
  */
 public function __invoke(DOMNode $node)
 {
     $nodePath = (new Utils())->toXPath($node);
     // as all nodes with the same path will have the same score,
     // we cache pr. path name
     if (!isset(self::$pathCache[$nodePath])) {
         $collection = FluentDOM($node->ownerDocument)->find($nodePath);
         $grouped = (new Utils())->groupByContentHash($collection);
         $totalCount = count($collection);
         $uniqueCount = count($grouped);
         // special case for uniqueCount 1:
         // not unique at all, return 0
         if ($uniqueCount === 1) {
             $score = 0;
         } else {
             $score = $uniqueCount / $totalCount;
         }
         self::$pathCache[$nodePath] = $score;
     }
     return self::$pathCache[$nodePath];
 }
开发者ID:tbug,项目名称:whatthefield,代码行数:24,代码来源:IsUnique.php

示例4: execute

 public function execute($request)
 {
     if (!$this->context->user->hasCredential('administrator') || !sfConfig::get('app_check_for_updates')) {
         return sfView::NONE;
     }
     $this->currentVersion = qubitConfiguration::VERSION;
     $this->updateCheckUrl = 'http://updatecheck.qubit-toolkit.org/check/';
     $this->cookiePath = sfContext::getInstance()->request->getRelativeUrlRoot();
     if (1 > strlen($this->cookiePath)) {
         $this->cookiePath = '/';
     }
     $this->updateCheckData = array();
     $this->updateCheckData['address'] = $request->getUriPrefix() . $request->getScriptName() . $request->getPathInfo();
     $this->updateCheckData['version'] = qubitConfiguration::VERSION . ' - ' . sfConfig::get('app_version');
     if (null === ($this->updateCheckData['distribution'] = $this->context->user->getAttribute('distribution'))) {
         $packageXmlPath = sfConfig::get('sf_config_dir') . '/package.xml';
         if (file_exists($packageXmlPath)) {
             require_once sfConfig::get('sf_root_dir') . '/vendor/FluentDOM/FluentDOM.php';
             $fd = FluentDOM($packageXmlPath)->namespaces(array('p' => 'http://pear.php.net/dtd/package-2.0'));
             $this->context->user->setAttribute('distribution', $this->updateCheckData['distribution'] = $fd->find('/*/p:name')->item(0)->textContent);
         }
     }
     $this->updateCheckData['site_description'] = sfConfig::get('app_siteDescription');
     $this->updateCheckData['site_title'] = sfConfig::get('app_siteTitle');
     if (!$request->getCookie('has_js')) {
         if (null === ($this->lastVersion = $this->context->user->getAttribute('last_version'))) {
             try {
                 $browser = new sfWebBrowser();
                 $this->lastVersion = $browser->post($this->updateCheckUrl, $this->updateCheckData)->getResponseText();
             } catch (Exception $e) {
                 $this->lastVersion = 0;
             }
             $this->context->user->setAttribute('last_version', $this->lastVersion);
         }
         if (0 == $this->lastVersion || 1 > version_compare($this->lastVersion, qubitConfiguration::VERSION)) {
             return sfView::NONE;
         }
     }
 }
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:39,代码来源:updateCheckComponent.class.php

示例5: checkDependencies

 public static function checkDependencies()
 {
     require_once sfConfig::get('sf_root_dir') . '/vendor/FluentDOM/FluentDOM.php';
     $dependencies = array();
     // Check if any dependencies are defined
     $packageXmlPath = sfConfig::get('sf_config_dir') . '/package.xml';
     if (!file_exists($packageXmlPath)) {
         return $dependencies;
     }
     $fd = FluentDOM($packageXmlPath)->namespaces(array('p' => 'http://pear.php.net/dtd/package-2.0'));
     // Check if a minimum PHP version is defined, and if it is less than our
     // current version
     if (0 < strlen($min = $fd->find('p:dependencies/p:required/p:php/p:min')) && 0 > version_compare(PHP_VERSION, $min)) {
         $dependencies['php']['min'] = $min;
     }
     foreach ($fd->find('p:dependencies/*/p:extension/p:name') as $node) {
         if (!extension_loaded($node->textContent)) {
             $dependencies['extensions'][] = $node->textContent;
         }
     }
     return $dependencies;
 }
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:22,代码来源:sfInstall.class.php

示例6: header

<?php

/**
*
* @version $Id: insertAfter.php 322 2009-09-14 20:19:48Z subjective $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <p> is what I said... </p><div id="foo">FOO!</div>
</body>
</html>
XML;
require_once '../FluentDOM.php';
echo FluentDOM($xml)->find('//p')->insertAfter('//div[@id = "foo"]');
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:19,代码来源:insertAfter.php

示例7: header

<?php

/**
*
* @version $Id: find.php 322 2009-09-14 20:19:48Z subjective $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <p><span>Hello</span>, how are you?</p>
  <p>Me? I'm <span>good</span>.</p>
</body>
</html>
XML;
require_once '../FluentDOM.php';
echo FluentDOM($xml)->find('//p')->find('span')->addClass('red');
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:20,代码来源:find.php

示例8: header

/**
*
* @version $Id: add.php 321 2009-09-14 20:17:23Z lapis $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <p>I would like to say: <b>HELLO</b></p>
  <b>HELLO</b>

  <div>Another list of childNodes</div>
</body>
</html>
XML;
require_once '../FluentDOM.php';
$dom = FluentDOM($xml);
echo $dom->find('//p')->add('//p/b')->toggleClass('inB');
echo "\n\n";
$dom = FluentDOM($xml);
echo $dom->find('//p')->add($dom->find('//div'))->toggleClass('inB');
echo "\n\n";
$dom = FluentDOM($xml);
echo $dom->add($dom->find('//div'))->toggleClass('inB');
echo "\n\n";
$dom = FluentDOM($xml);
echo $dom->add('//div')->toggleClass('inB');
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:30,代码来源:add.php

示例9: header

<?php

/**
*
* @version $Id: wrap.php 322 2009-09-14 20:19:48Z subjective $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>
XML;
require_once '../FluentDOM.php';
echo FluentDOM($xml)->find('//p')->wrap('<div class="outer"><div class="inner"></div></div>');
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:21,代码来源:wrap.php

示例10: header

<?php

/**
*
* @version $Id$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>
XML;
require_once '../src/FluentDOM.php';
echo FluentDOM($xml)->find('//p')->replaceWith('<b>Paragraph. </b>');
开发者ID:noels,项目名称:FluentDOM,代码行数:21,代码来源:replaceWith.php

示例11: header

<?php

/**
*
* @version $Id$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <span>I have nothing more to say... </span>
  <div id="foo">FOO! </div>
</body>
</html>
XML;
require_once '../src/FluentDOM.php';
echo FluentDOM($xml)->find('//span')->appendTo('//div[@id = "foo"]');
开发者ID:noels,项目名称:FluentDOM,代码行数:20,代码来源:appendTo.php

示例12: FluentDOM

<?php

require '../../src/FluentDOM.php';
$fd = FluentDOM('find.xml');
// find the document element <root>
var_dump($fd->find('/root')->item(0)->nodeName);
//find the first <child> in <root>
var_dump($fd->find('/root/child')->item(0)->textContent);
//find the all <child>s anywhere in the document
foreach ($fd->find('//child') as $child) {
    var_dump($child->textContent);
}
//find the <root> first then the second element in it
var_dump($fd->find('/root')->find('*[2]')->item(0)->textContent);
开发者ID:noels,项目名称:FluentDOM,代码行数:14,代码来源:find-xpath.php

示例13: header

<?php

header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>
XML;
require_once '../../FluentDOM.php';
$dom = FluentDOM($xml)->find('//p');
echo $dom[0]->textContent, ' ', $dom[2]->textContent;
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:16,代码来源:ArrayAccess.php

示例14: header

<?php

/**
*
* @version $Id$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$xml = <<<XML
<html>
<head></head>
<body>
  <div id="foo">FOO!</div><p>I would like to say: </p>
</body>
</html>
XML;
require_once '../src/FluentDOM.php';
echo FluentDOM($xml)->find('//p')->insertBefore('//div[@id = "foo"]');
开发者ID:noels,项目名称:FluentDOM,代码行数:19,代码来源:insertBefore.php

示例15: header

<?php

/**
* Example file for property 'attr'
*
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2010 Bastian Feder, Thomas Weinert
*/
header('Content-type: text/plain');
$html = <<<HTML
<html>
 <head>
  <title>FluentDOM project page</title>
 </head>
 <body>
  <p style="color: red;">
   Always nice to visit
   <a href='http://fluentdom.org' target="_blank">here</a> or 
   <a href='http://github.org/FluentDOM' target="_blank">here.</a>
  </p>
 </body>
</html>
HTML;
echo "Example for property 'attr' - remove attributes:\n\n";
require_once '../../src/FluentDOM.php';
$fd = FluentDOM($html, 'text/html')->find('/html/body//*');
// like $fd->removeAttr(array('style', 'target')); but array syntax
unset($fd->attr[array('style', 'target')]);
echo (string) $fd;
开发者ID:noels,项目名称:FluentDOM,代码行数:29,代码来源:attr-unset.php


注:本文中的FluentDOM函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。