[DomCrawler] tagged the guaranteed BC API

This commit is contained in:
Fabien Potencier 2011-03-24 10:00:10 +01:00
parent 9206af1773
commit e515913747
7 changed files with 116 additions and 0 deletions

View File

@ -17,6 +17,8 @@ use Symfony\Component\CssSelector\Parser as CssParser;
* Crawler eases navigation of a list of \DOMNode objects. * Crawler eases navigation of a list of \DOMNode objects.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/ */
class Crawler extends \SplObjectStorage class Crawler extends \SplObjectStorage
{ {
@ -32,6 +34,8 @@ class Crawler extends \SplObjectStorage
* @param string $uri The base URI to use for absolute links or form actions * @param string $uri The base URI to use for absolute links or form actions
* @param string $base An optional base href for generating the uris for Form and Link. * @param string $base An optional base href for generating the uris for Form and Link.
* This will be autodetected if $node has a <base> tag. * This will be autodetected if $node has a <base> tag.
*
* @api
*/ */
public function __construct($node = null, $uri = null, $base = null) public function __construct($node = null, $uri = null, $base = null)
{ {
@ -48,6 +52,8 @@ class Crawler extends \SplObjectStorage
/** /**
* Removes all the nodes. * Removes all the nodes.
*
* @api
*/ */
public function clear() public function clear()
{ {
@ -61,6 +67,8 @@ class Crawler extends \SplObjectStorage
* on the type of the argument. * on the type of the argument.
* *
* @param null|\DOMNodeList|array|\DOMNode $node A node * @param null|\DOMNodeList|array|\DOMNode $node A node
*
* @api
*/ */
public function add($node) public function add($node)
{ {
@ -75,6 +83,12 @@ class Crawler extends \SplObjectStorage
} }
} }
/**
* Adds HTML/XML content.
*
* @param string $content A string to parse as HTML/XML
* @param string $type The content type of the string
*/
public function addContent($content, $type = null) public function addContent($content, $type = null)
{ {
if (empty($type)) { if (empty($type)) {
@ -103,6 +117,8 @@ class Crawler extends \SplObjectStorage
* *
* @param string $content The HTML content * @param string $content The HTML content
* @param string $charset The charset * @param string $charset The charset
*
* @api
*/ */
public function addHtmlContent($content, $charset = 'UTF-8') public function addHtmlContent($content, $charset = 'UTF-8')
{ {
@ -124,6 +140,8 @@ class Crawler extends \SplObjectStorage
* *
* @param string $content The XML content * @param string $content The XML content
* @param string $charset The charset * @param string $charset The charset
*
* @api
*/ */
public function addXmlContent($content, $charset = 'UTF-8') public function addXmlContent($content, $charset = 'UTF-8')
{ {
@ -139,6 +157,8 @@ class Crawler extends \SplObjectStorage
* Adds a \DOMDocument to the list of nodes. * Adds a \DOMDocument to the list of nodes.
* *
* @param \DOMDocument $dom A \DOMDocument instance * @param \DOMDocument $dom A \DOMDocument instance
*
* @api
*/ */
public function addDocument(\DOMDocument $dom) public function addDocument(\DOMDocument $dom)
{ {
@ -151,6 +171,8 @@ class Crawler extends \SplObjectStorage
* Adds a \DOMNodeList to the list of nodes. * Adds a \DOMNodeList to the list of nodes.
* *
* @param \DOMNodeList $nodes A \DOMNodeList instance * @param \DOMNodeList $nodes A \DOMNodeList instance
*
* @api
*/ */
public function addNodeList(\DOMNodeList $nodes) public function addNodeList(\DOMNodeList $nodes)
{ {
@ -163,6 +185,8 @@ class Crawler extends \SplObjectStorage
* Adds an array of \DOMNode instances to the list of nodes. * Adds an array of \DOMNode instances to the list of nodes.
* *
* @param array $nodes An array of \DOMNode instances * @param array $nodes An array of \DOMNode instances
*
* @api
*/ */
public function addNodes(array $nodes) public function addNodes(array $nodes)
{ {
@ -175,6 +199,8 @@ class Crawler extends \SplObjectStorage
* Adds a \DOMNode instance to the list of nodes. * Adds a \DOMNode instance to the list of nodes.
* *
* @param \DOMNode $node A \DOMNode instance * @param \DOMNode $node A \DOMNode instance
*
* @api
*/ */
public function addNode(\DOMNode $node) public function addNode(\DOMNode $node)
{ {
@ -191,6 +217,8 @@ class Crawler extends \SplObjectStorage
* @param integer $position The position * @param integer $position The position
* *
* @return A new instance of the Crawler with the selected node, or an empty Crawler if it does not exist. * @return A new instance of the Crawler with the selected node, or an empty Crawler if it does not exist.
*
* @api
*/ */
public function eq($position) public function eq($position)
{ {
@ -218,6 +246,8 @@ class Crawler extends \SplObjectStorage
* @param \Closure $closure An anonymous function * @param \Closure $closure An anonymous function
* *
* @return array An array of values returned by the anonymous function * @return array An array of values returned by the anonymous function
*
* @api
*/ */
public function each(\Closure $closure) public function each(\Closure $closure)
{ {
@ -237,6 +267,8 @@ class Crawler extends \SplObjectStorage
* @param \Closure $closure An anonymous function * @param \Closure $closure An anonymous function
* *
* @return Crawler A Crawler instance with the selected nodes. * @return Crawler A Crawler instance with the selected nodes.
*
* @api
*/ */
public function reduce(\Closure $closure) public function reduce(\Closure $closure)
{ {
@ -254,6 +286,8 @@ class Crawler extends \SplObjectStorage
* Returns the first node of the current selection * Returns the first node of the current selection
* *
* @return Crawler A Crawler instance with the first selected node * @return Crawler A Crawler instance with the first selected node
*
* @api
*/ */
public function first() public function first()
{ {
@ -264,6 +298,8 @@ class Crawler extends \SplObjectStorage
* Returns the last node of the current selection * Returns the last node of the current selection
* *
* @return Crawler A Crawler instance with the last selected node * @return Crawler A Crawler instance with the last selected node
*
* @api
*/ */
public function last() public function last()
{ {
@ -276,6 +312,8 @@ class Crawler extends \SplObjectStorage
* @return Crawler A Crawler instance with the sibling nodes * @return Crawler A Crawler instance with the sibling nodes
* *
* @throws \InvalidArgumentException When current node is empty * @throws \InvalidArgumentException When current node is empty
*
* @api
*/ */
public function siblings() public function siblings()
{ {
@ -292,6 +330,8 @@ class Crawler extends \SplObjectStorage
* @return Crawler A Crawler instance with the next sibling nodes * @return Crawler A Crawler instance with the next sibling nodes
* *
* @throws \InvalidArgumentException When current node is empty * @throws \InvalidArgumentException When current node is empty
*
* @api
*/ */
public function nextAll() public function nextAll()
{ {
@ -306,6 +346,8 @@ class Crawler extends \SplObjectStorage
* Returns the previous sibling nodes of the current selection * Returns the previous sibling nodes of the current selection
* *
* @return Crawler A Crawler instance with the previous sibling nodes * @return Crawler A Crawler instance with the previous sibling nodes
*
* @api
*/ */
public function previousAll() public function previousAll()
{ {
@ -322,6 +364,8 @@ class Crawler extends \SplObjectStorage
* @return Crawler A Crawler instance with the parents nodes of the current selection * @return Crawler A Crawler instance with the parents nodes of the current selection
* *
* @throws \InvalidArgumentException When current node is empty * @throws \InvalidArgumentException When current node is empty
*
* @api
*/ */
public function parents() public function parents()
{ {
@ -347,6 +391,8 @@ class Crawler extends \SplObjectStorage
* @return Crawler A Crawler instance with the children nodes * @return Crawler A Crawler instance with the children nodes
* *
* @throws \InvalidArgumentException When current node is empty * @throws \InvalidArgumentException When current node is empty
*
* @api
*/ */
public function children() public function children()
{ {
@ -365,6 +411,8 @@ class Crawler extends \SplObjectStorage
* @return string The attribute value * @return string The attribute value
* *
* @throws \InvalidArgumentException When current node is empty * @throws \InvalidArgumentException When current node is empty
*
* @api
*/ */
public function attr($attribute) public function attr($attribute)
{ {
@ -381,6 +429,8 @@ class Crawler extends \SplObjectStorage
* @return string The node value * @return string The node value
* *
* @throws \InvalidArgumentException When current node is empty * @throws \InvalidArgumentException When current node is empty
*
* @api
*/ */
public function text() public function text()
{ {
@ -403,6 +453,8 @@ class Crawler extends \SplObjectStorage
* @param array $attributes An array of attributes * @param array $attributes An array of attributes
* *
* @return array An array of extracted values * @return array An array of extracted values
*
* @api
*/ */
public function extract($attributes) public function extract($attributes)
{ {
@ -433,6 +485,8 @@ class Crawler extends \SplObjectStorage
* @param string $xpath An XPath expression * @param string $xpath An XPath expression
* *
* @return Crawler A new instance of Crawler with the filtered list of nodes * @return Crawler A new instance of Crawler with the filtered list of nodes
*
* @api
*/ */
public function filterXPath($xpath) public function filterXPath($xpath)
{ {
@ -457,6 +511,8 @@ class Crawler extends \SplObjectStorage
* @return Crawler A new instance of Crawler with the filtered list of nodes * @return Crawler A new instance of Crawler with the filtered list of nodes
* *
* @throws \RuntimeException if the CssSelector Component is not available * @throws \RuntimeException if the CssSelector Component is not available
*
* @api
*/ */
public function filter($selector) public function filter($selector)
{ {
@ -475,6 +531,8 @@ class Crawler extends \SplObjectStorage
* @param string $value The link text * @param string $value The link text
* *
* @return Crawler A new instance of Crawler with the filtered list of nodes * @return Crawler A new instance of Crawler with the filtered list of nodes
*
* @api
*/ */
public function selectLink($value) public function selectLink($value)
{ {
@ -490,6 +548,8 @@ class Crawler extends \SplObjectStorage
* @param string $value The button text * @param string $value The button text
* *
* @return Crawler A new instance of Crawler with the filtered list of nodes * @return Crawler A new instance of Crawler with the filtered list of nodes
*
* @api
*/ */
public function selectButton($value) public function selectButton($value)
{ {
@ -508,6 +568,8 @@ class Crawler extends \SplObjectStorage
* @return Link A Link instance * @return Link A Link instance
* *
* @throws \InvalidArgumentException If the current node list is empty * @throws \InvalidArgumentException If the current node list is empty
*
* @api
*/ */
public function link($method = 'get') public function link($method = 'get')
{ {
@ -524,6 +586,8 @@ class Crawler extends \SplObjectStorage
* Returns an array of Link objects for the nodes in the list. * Returns an array of Link objects for the nodes in the list.
* *
* @return array An array of Link instances * @return array An array of Link instances
*
* @api
*/ */
public function links() public function links()
{ {
@ -544,6 +608,8 @@ class Crawler extends \SplObjectStorage
* @return Form A Form instance * @return Form A Form instance
* *
* @throws \InvalidArgumentException If the current node list is empty * @throws \InvalidArgumentException If the current node list is empty
*
* @api
*/ */
public function form(array $values = null, $method = null) public function form(array $values = null, $method = null)
{ {

View File

@ -17,6 +17,8 @@ namespace Symfony\Component\DomCrawler\Field;
* It is constructed from a HTML select tag, or a HTML checkbox, or radio inputs. * It is constructed from a HTML select tag, or a HTML checkbox, or radio inputs.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/ */
class ChoiceFormField extends FormField class ChoiceFormField extends FormField
{ {
@ -55,6 +57,8 @@ class ChoiceFormField extends FormField
* Ticks a checkbox. * Ticks a checkbox.
* *
* @throws \InvalidArgumentException When value type provided is not correct * @throws \InvalidArgumentException When value type provided is not correct
*
* @api
*/ */
public function tick() public function tick()
{ {
@ -69,6 +73,8 @@ class ChoiceFormField extends FormField
* Ticks a checkbox. * Ticks a checkbox.
* *
* @throws \InvalidArgumentException When value type provided is not correct * @throws \InvalidArgumentException When value type provided is not correct
*
* @api
*/ */
public function untick() public function untick()
{ {

View File

@ -15,6 +15,8 @@ namespace Symfony\Component\DomCrawler\Field;
* FileFormField represents a file form field (an HTML file input tag). * FileFormField represents a file form field (an HTML file input tag).
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/ */
class FileFormField extends FormField class FileFormField extends FormField
{ {
@ -39,6 +41,8 @@ class FileFormField extends FormField
* Sets the value of the field. * Sets the value of the field.
* *
* @param string $value The value of the field * @param string $value The value of the field
*
* @api
*/ */
public function upload($value) public function upload($value)
{ {

View File

@ -18,6 +18,8 @@ namespace Symfony\Component\DomCrawler\Field;
* specialized classes (cf. FileFormField and ChoiceFormField). * specialized classes (cf. FileFormField and ChoiceFormField).
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/ */
class InputFormField extends FormField class InputFormField extends FormField
{ {

View File

@ -15,6 +15,8 @@ namespace Symfony\Component\DomCrawler\Field;
* TextareaFormField represents a textarea form field (an HTML textarea tag). * TextareaFormField represents a textarea form field (an HTML textarea tag).
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/ */
class TextareaFormField extends FormField class TextareaFormField extends FormField
{ {

View File

@ -17,6 +17,8 @@ use Symfony\Component\DomCrawler\Field\FormField;
* Form represents an HTML form. * Form represents an HTML form.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/ */
class Form implements \ArrayAccess class Form implements \ArrayAccess
{ {
@ -39,6 +41,8 @@ class Form implements \ArrayAccess
* @param string $base An optional base href for generating the submit uri * @param string $base An optional base href for generating the submit uri
* *
* @throws \LogicException if the node is not a button inside a form tag * @throws \LogicException if the node is not a button inside a form tag
*
* @api
*/ */
public function __construct(\DOMNode $node, $method = null, $host = null, $path = '/', $base = null) public function __construct(\DOMNode $node, $method = null, $host = null, $path = '/', $base = null)
{ {
@ -76,6 +80,8 @@ class Form implements \ArrayAccess
* Sets the value of the fields. * Sets the value of the fields.
* *
* @param array $values An array of field values * @param array $values An array of field values
*
* @api
*/ */
public function setValues(array $values) public function setValues(array $values)
{ {
@ -92,6 +98,8 @@ class Form implements \ArrayAccess
* The returned array does not include file fields (@see getFiles). * The returned array does not include file fields (@see getFiles).
* *
* @return array An array of field values. * @return array An array of field values.
*
* @api
*/ */
public function getValues() public function getValues()
{ {
@ -109,6 +117,8 @@ class Form implements \ArrayAccess
* Gets the file field values. * Gets the file field values.
* *
* @return array An array of file field values. * @return array An array of file field values.
*
* @api
*/ */
public function getFiles() public function getFiles()
{ {
@ -133,6 +143,8 @@ class Form implements \ArrayAccess
* (like foo[bar] to arrays) like PHP does. * (like foo[bar] to arrays) like PHP does.
* *
* @return array An array of field values. * @return array An array of field values.
*
* @api
*/ */
public function getPhpValues() public function getPhpValues()
{ {
@ -149,6 +161,8 @@ class Form implements \ArrayAccess
* (like foo[bar] to arrays) like PHP does. * (like foo[bar] to arrays) like PHP does.
* *
* @return array An array of field values. * @return array An array of field values.
*
* @api
*/ */
public function getPhpFiles() public function getPhpFiles()
{ {
@ -168,6 +182,8 @@ class Form implements \ArrayAccess
* @param Boolean $absolute Whether to return an absolute URI or not (this only works if a base URI has been provided) * @param Boolean $absolute Whether to return an absolute URI or not (this only works if a base URI has been provided)
* *
* @return string The URI * @return string The URI
*
* @api
*/ */
public function getUri($absolute = true) public function getUri($absolute = true)
{ {
@ -207,6 +223,8 @@ class Form implements \ArrayAccess
* If no method is defined in the form, GET is returned. * If no method is defined in the form, GET is returned.
* *
* @return string The method * @return string The method
*
* @api
*/ */
public function getMethod() public function getMethod()
{ {
@ -223,6 +241,8 @@ class Form implements \ArrayAccess
* @param string $name The field name * @param string $name The field name
* *
* @return Boolean true if the field exists, false otherwise * @return Boolean true if the field exists, false otherwise
*
* @api
*/ */
public function has($name) public function has($name)
{ {
@ -233,6 +253,8 @@ class Form implements \ArrayAccess
* Removes a field from the form. * Removes a field from the form.
* *
* @param string $name The field name * @param string $name The field name
*
* @api
*/ */
public function remove($name) public function remove($name)
{ {
@ -247,6 +269,8 @@ class Form implements \ArrayAccess
* @return FormField The field instance * @return FormField The field instance
* *
* @throws \InvalidArgumentException When field is not present in this form * @throws \InvalidArgumentException When field is not present in this form
*
* @api
*/ */
public function get($name) public function get($name)
{ {
@ -263,6 +287,8 @@ class Form implements \ArrayAccess
* @param string $name The field name * @param string $name The field name
* *
* @return FormField The field instance * @return FormField The field instance
*
* @api
*/ */
public function set(Field\FormField $field) public function set(Field\FormField $field)
{ {
@ -273,6 +299,8 @@ class Form implements \ArrayAccess
* Gets all fields. * Gets all fields.
* *
* @return array An array of fields * @return array An array of fields
*
* @api
*/ */
public function all() public function all()
{ {

View File

@ -15,6 +15,8 @@ namespace Symfony\Component\DomCrawler;
* Link represents an HTML link (an HTML a tag). * Link represents an HTML link (an HTML a tag).
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/ */
class Link class Link
{ {
@ -34,6 +36,8 @@ class Link
* @param strin $base An optional base href for generating the uri * @param strin $base An optional base href for generating the uri
* *
* @throws \LogicException if the node is not a link * @throws \LogicException if the node is not a link
*
* @api
*/ */
public function __construct(\DOMNode $node, $method = 'get', $host = null, $path = '/', $base = null) public function __construct(\DOMNode $node, $method = 'get', $host = null, $path = '/', $base = null)
{ {
@ -64,6 +68,8 @@ class Link
* @param Boolean $absolute Whether to return an absolute URI or not (this only works if a base URI has been provided) * @param Boolean $absolute Whether to return an absolute URI or not (this only works if a base URI has been provided)
* *
* @return string The URI * @return string The URI
*
* @api
*/ */
public function getUri($absolute = true) public function getUri($absolute = true)
{ {
@ -93,6 +99,8 @@ class Link
* Gets the method associated with this link. * Gets the method associated with this link.
* *
* @return string The method * @return string The method
*
* @api
*/ */
public function getMethod() public function getMethod()
{ {