當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DomCrawler\Link類代碼示例

本文整理匯總了PHP中Symfony\Component\DomCrawler\Link的典型用法代碼示例。如果您正苦於以下問題:PHP Link類的具體用法?PHP Link怎麽用?PHP Link使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Link類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGetUriOnArea

 /**
  * @dataProvider getGetUriTests
  */
 public function testGetUriOnArea($url, $currentUri, $expected)
 {
     $dom = new \DOMDocument();
     $dom->loadHTML(sprintf('<html><map><area href="%s" /></map></html>', $url));
     $link = new Link($dom->getElementsByTagName('area')->item(0), $currentUri);
     $this->assertEquals($expected, $link->getUri());
 }
開發者ID:mawaha,項目名稱:tracker,代碼行數:10,代碼來源:LinkTest.php

示例2: findLinkedPages

 /**
  * @return PagesCollection New Collection with all found links
  */
 public function findLinkedPages()
 {
     $pages = new PagesCollection();
     $crawler = $this->getCrawler();
     foreach ($crawler->filter('a') as $node) {
         $link = new Link($node, $this->uri);
         $page = new Page($link->getUri());
         $page->setClient($this->client);
         $pages->add($page);
     }
     return $pages;
 }
開發者ID:goodhacker,項目名稱:marlon-csrfscanner,代碼行數:15,代碼來源:Page.php

示例3: testGetters

 public function testGetters()
 {
     $dom = new \DOMDocument();
     $dom->loadHTML('<html><a href="/foo">foo</a></html>');
     $node = $dom->getElementsByTagName('a')->item(0);
     $link = new Link($node);
     $this->assertEquals('/foo', $link->getUri(), '->getUri() returns the URI of the link');
     $this->assertEquals($node, $link->getNode(), '->getNode() returns the node associated with the link');
     $this->assertEquals('get', $link->getMethod(), '->getMethod() returns the method of the link');
     $link = new Link($node, 'post');
     $this->assertEquals('post', $link->getMethod(), '->getMethod() returns the method of the link');
     $link = new Link($node, 'get', 'http://localhost', '/bar/');
     $this->assertEquals('http://localhost/foo', $link->getUri(), '->getUri() returns the absolute URI of the link');
     $this->assertEquals('/foo', $link->getUri(false), '->getUri() returns the relative URI of the link if false is the first argument');
     $dom = new \DOMDocument();
     $dom->loadHTML('<html><a href="foo">foo</a></html>');
     $node = $dom->getElementsByTagName('a')->item(0);
     $link = new Link($node, 'get', 'http://localhost', '/bar/');
     $this->assertEquals('http://localhost/bar/foo', $link->getUri(), '->getUri() returns the absolute URI of the link for relative hrefs');
     $this->assertEquals('/bar/foo', $link->getUri(false), '->getUri() returns the relative URI of the link if false is the first argument');
     $dom = new \DOMDocument();
     $dom->loadHTML('<html><a href="http://login.foo.com/foo">foo</a></html>');
     $node = $dom->getElementsByTagName('a')->item(0);
     $link = new Link($node, 'get', 'http://www.foo.com');
     $this->assertEquals('http://login.foo.com/foo', $link->getUri(), '->getUri() returns the absolute URI of the link, regardless of the context of the object');
     $link = new Link($node, 'get');
     $this->assertEquals('http://login.foo.com/foo', $link->getUri(), '->getUri() returns the absolute URI of the link, regardless of the context of the object');
     $link = new Link($node, 'get', null, '/bar/');
     $this->assertEquals('http://login.foo.com/foo', $link->getUri(), '->getUri() returns the absolute URI of the link, regardless of the context of the object');
     $link = new Link($node, 'get', 'http://www.foo.com', '/bar/');
     $this->assertEquals('http://login.foo.com/foo', $link->getUri(), '->getUri() returns the absolute URI of the link, regardless of the context of the object');
     $dom = new \DOMDocument();
     $dom->loadHTML('<html><a href="?get=param">foo</a></html>');
     $node = $dom->getElementsByTagName('a')->item(0);
     $link = new Link($node, 'get', 'http://www.foo.com', '/foo/bar');
     $this->assertEquals('http://www.foo.com/foo/bar?get=param', $link->getUri(), '->getUri() returns the absolute URI of the link, regardless of the context of the object');
     $link = new Link($node, 'get', 'http://www.foo.com', '/foo/bar');
     $this->assertEquals('/foo/bar?get=param', $link->getUri(false), '->getUri() returns the relative URI of the link if false is the first argument');
     $dom = new \DOMDocument();
     $dom->loadHTML('<html><a href="test.html">foo</a></html>');
     $node = $dom->getElementsByTagName('a')->item(0);
     $link = new Link($node, 'get', null, '/foo/bar', 'http://www.foo.com/');
     $this->assertEquals('http://www.foo.com/test.html', $link->getUri());
 }
開發者ID:notbrain,項目名稱:symfony,代碼行數:44,代碼來源:LinkTest.php

示例4: addHtmlContent

 /**
  * Adds an HTML content to the list of nodes.
  *
  * The libxml errors are disabled when the content is parsed.
  *
  * If you want to get parsing errors, be sure to enable
  * internal errors via libxml_use_internal_errors(true)
  * and then, get the errors via libxml_get_errors(). Be
  * sure to clear errors with libxml_clear_errors() afterward.
  *
  * @param string $content The HTML content
  * @param string $charset The charset
  *
  * @api
  */
 public function addHtmlContent($content, $charset = 'UTF-8')
 {
     $internalErrors = libxml_use_internal_errors(true);
     $disableEntities = libxml_disable_entity_loader(true);
     $dom = new \DOMDocument('1.0', $charset);
     $dom->validateOnParse = true;
     set_error_handler(function () {
         throw new \Exception();
     });
     try {
         // Convert charset to HTML-entities to work around bugs in DOMDocument::loadHTML()
         if (function_exists('mb_convert_encoding')) {
             $content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
         } elseif (function_exists('iconv')) {
             $content = preg_replace_callback('/[\\x80-\\xFF]+/', function ($m) {
                 $m = unpack('C*', $m[0]);
                 $i = 1;
                 $entities = '';
                 while (isset($m[$i])) {
                     if (0xf0 <= $m[$i]) {
                         $c = ($m[$i++] - 0xf0 << 18) + ($m[$i++] - 0x80 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
                     } elseif (0xe0 <= $m[$i]) {
                         $c = ($m[$i++] - 0xe0 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
                     } else {
                         $c = ($m[$i++] - 0xc0 << 6) + $m[$i++] - 0x80;
                     }
                     $entities .= '&#' . $c . ';';
                 }
                 return $entities;
             }, iconv($charset, 'UTF-8', $content));
         }
     } catch (\Exception $e) {
     }
     restore_error_handler();
     if ('' !== trim($content)) {
         @$dom->loadHTML($content);
     }
     libxml_use_internal_errors($internalErrors);
     libxml_disable_entity_loader($disableEntities);
     $this->addDocument($dom);
     $base = $this->filterRelativeXPath('descendant-or-self::base')->extract(array('href'));
     $baseHref = current($base);
     if (count($base) && !empty($baseHref)) {
         if ($this->baseHref) {
             $linkNode = $dom->createElement('a');
             $linkNode->setAttribute('href', $baseHref);
             $link = new Link($linkNode, $this->baseHref);
             $this->baseHref = $link->getUri();
         } else {
             $this->baseHref = $baseHref;
         }
     }
 }
開發者ID:jdshao,項目名稱:symfony_backstage,代碼行數:68,代碼來源:Crawler.php

示例5: addHtmlContent

 /**
  * Adds an HTML content to the list of nodes.
  *
  * The libxml errors are disabled when the content is parsed.
  *
  * If you want to get parsing errors, be sure to enable
  * internal errors via libxml_use_internal_errors(true)
  * and then, get the errors via libxml_get_errors(). Be
  * sure to clear errors with libxml_clear_errors() afterward.
  *
  * @param string $content The HTML content
  * @param string $charset The charset
  *
  * @api
  */
 public function addHtmlContent($content, $charset = 'UTF-8')
 {
     $current = libxml_use_internal_errors(true);
     $disableEntities = libxml_disable_entity_loader(true);
     $dom = new \DOMDocument('1.0', $charset);
     $dom->validateOnParse = true;
     if (function_exists('mb_convert_encoding') && in_array(strtolower($charset), array_map('strtolower', mb_list_encodings()))) {
         $content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
     }
     @$dom->loadHTML($content);
     libxml_use_internal_errors($current);
     libxml_disable_entity_loader($disableEntities);
     $this->addDocument($dom);
     $base = $this->filterXPath('descendant-or-self::base')->extract(array('href'));
     $baseHref = current($base);
     if (count($base) && !empty($baseHref)) {
         if ($this->uri) {
             $linkNode = $dom->createElement('a');
             $linkNode->setAttribute('href', $baseHref);
             $link = new Link($linkNode, $this->uri);
             $this->uri = $link->getUri();
         } else {
             $this->uri = $baseHref;
         }
     }
 }
開發者ID:NaszvadiG,項目名稱:ImageCMS,代碼行數:41,代碼來源:Crawler.php

示例6: addHtmlContent

 /**
  * Adds an HTML content to the list of nodes.
  *
  * The libxml errors are disabled when the content is parsed.
  *
  * If you want to get parsing errors, be sure to enable
  * internal errors via libxml_use_internal_errors(true)
  * and then, get the errors via libxml_get_errors(). Be
  * sure to clear errors with libxml_clear_errors() afterward.
  *
  * @param string $content The HTML content
  * @param string $charset The charset
  *
  * @api
  */
 public function addHtmlContent($content, $charset = 'UTF-8')
 {
     $internalErrors = libxml_use_internal_errors(true);
     $disableEntities = libxml_disable_entity_loader(true);
     $dom = new \DOMDocument('1.0', $charset);
     $dom->validateOnParse = true;
     if (function_exists('mb_convert_encoding')) {
         $hasError = false;
         set_error_handler(function () use(&$hasError) {
             $hasError = true;
         });
         $tmpContent = @mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
         restore_error_handler();
         if (!$hasError) {
             $content = $tmpContent;
         }
     }
     if ('' !== trim($content)) {
         @$dom->loadHTML($content);
     }
     libxml_use_internal_errors($internalErrors);
     libxml_disable_entity_loader($disableEntities);
     $this->addDocument($dom);
     $base = $this->filterRelativeXPath('descendant-or-self::base')->extract(array('href'));
     $baseHref = current($base);
     if (count($base) && !empty($baseHref)) {
         if ($this->uri) {
             $linkNode = $dom->createElement('a');
             $linkNode->setAttribute('href', $baseHref);
             $link = new Link($linkNode, $this->uri);
             $this->uri = $link->getUri();
         } else {
             $this->uri = $baseHref;
         }
     }
 }
開發者ID:ymnl007,項目名稱:92five,代碼行數:51,代碼來源:Crawler.php

示例7: click

 /**
  * Clicks on a given link.
  *
  * @param Link $link A Link instance
  */
 public function click(Link $link)
 {
     return $this->request($link->getMethod(), $link->getUri());
 }
開發者ID:rosstuck,項目名稱:Pok,代碼行數:9,代碼來源:Client.php

示例8: __construct

 /**
  * Link constructor.
  *
  * @param DOMElement $node
  * @param string $currentUri
  */
 public function __construct(DOMElement $node, $currentUri)
 {
     parent::__construct($node, $currentUri);
 }
開發者ID:sleimanx2,項目名稱:grawler,代碼行數:10,代碼來源:Link.php

示例9: getUri

 /**
  * @return null|string
  */
 public function getUri()
 {
     switch ($this->type) {
         case 'application/rss+xml':
         case 'application/x.atom+xml':
         case 'application/atom+xml':
         case 'application/rdf+xml':
             return parent::getUri();
         default:
             break;
     }
     return null;
 }
開發者ID:norikt,項目名稱:feedseek,代碼行數:16,代碼來源:FeedLink.php

示例10: getUri

 /**
  * Gets the URI of the form.
  *
  * The returned URI is not the same as the form "action" attribute.
  * This method merges the value if the method is GET to mimics
  * browser behavior.
  *
  * @return string The URI
  *
  * @api
  */
 public function getUri()
 {
     $uri = parent::getUri();
     if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) {
         $query = parse_url($uri, PHP_URL_QUERY);
         $currentParameters = array();
         if ($query) {
             parse_str($query, $currentParameters);
         }
         $queryString = http_build_query(array_merge($currentParameters, $this->getValues()), null, '&');
         $pos = strpos($uri, '?');
         $base = false === $pos ? $uri : substr($uri, 0, $pos);
         $uri = rtrim($base . '?' . $queryString, '?');
     }
     return $uri;
 }
開發者ID:mgldev,項目名稱:coffeetrack,代碼行數:27,代碼來源:Form.php

示例11: getUri

 /**
  * Gets the URI of the form.
  *
  * The returned URI is not the same as the form "action" attribute.
  * This method merges the value if the method is GET to mimics
  * browser behavior.
  *
  * @return string The URI
  *
  * @api
  */
 public function getUri()
 {
     $uri = parent::getUri();
     if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH')) && ($queryString = http_build_query($this->getValues(), null, '&'))) {
         $sep = false === strpos($uri, '?') ? '?' : '&';
         $uri .= $sep . $queryString;
     }
     return $uri;
 }
開發者ID:rimi-itk,項目名稱:bpi-client,代碼行數:20,代碼來源:Form.php

示例12: getUri

    /**
     * Gets the URI of the form.
     *
     * The returned URI is not the same as the form "action" attribute.
     * This method merges the value if the method is GET to mimics
     * browser behavior.
     *
     * @return string The URI
     *
     * @api
     */
    public function getUri()
    {
        $uri = parent::getUri();

        if (!in_array($this->getMethod(), array('post', 'put', 'delete')) && $queryString = http_build_query($this->getValues(), null, '&')) {
            $sep = false === strpos($uri, '?') ? '?' : '&';
            $uri .= $sep.$queryString;
        }

        return $uri;
    }
開發者ID:nacef,項目名稱:symfony,代碼行數:22,代碼來源:Form.php

示例13: addHtmlContent

 /**
  * Adds an HTML content to the list of nodes.
  *
  * The libxml errors are disabled when the content is parsed.
  *
  * If you want to get parsing errors, be sure to enable
  * internal errors via libxml_use_internal_errors(true)
  * and then, get the errors via libxml_get_errors(). Be
  * sure to clear errors with libxml_clear_errors() afterward.
  *
  * @param string $content The HTML content
  * @param string $charset The charset
  */
 public function addHtmlContent($content, $charset = 'UTF-8')
 {
     $internalErrors = libxml_use_internal_errors(true);
     $disableEntities = libxml_disable_entity_loader(true);
     $dom = new \DOMDocument('1.0', $charset);
     $dom->validateOnParse = true;
     set_error_handler(function () {
         throw new \Exception();
     });
     try {
         // Convert charset to HTML-entities to work around bugs in DOMDocument::loadHTML()
         $content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
     } catch (\Exception $e) {
     }
     restore_error_handler();
     if ('' !== trim($content)) {
         @$dom->loadHTML($content);
     }
     libxml_use_internal_errors($internalErrors);
     libxml_disable_entity_loader($disableEntities);
     $this->addDocument($dom);
     $base = $this->filterRelativeXPath('descendant-or-self::base')->extract(array('href'));
     $baseHref = current($base);
     if (count($base) && !empty($baseHref)) {
         if ($this->baseHref) {
             $linkNode = $dom->createElement('a');
             $linkNode->setAttribute('href', $baseHref);
             $link = new Link($linkNode, $this->baseHref);
             $this->baseHref = $link->getUri();
         } else {
             $this->baseHref = $baseHref;
         }
     }
 }
開發者ID:imydou,項目名稱:dkuu,代碼行數:47,代碼來源:Crawler.php


注:本文中的Symfony\Component\DomCrawler\Link類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。