merged 2.0

This commit is contained in:
Fabien Potencier 2012-04-10 20:26:56 +02:00
commit 02e1b81f65
8 changed files with 99 additions and 16 deletions

View File

@ -22,6 +22,9 @@ use Symfony\Component\CssSelector\CssSelector;
*/
class Crawler extends \SplObjectStorage
{
/**
* @var string The current URI or the base href value
*/
private $uri;
/**
@ -75,8 +78,10 @@ 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
* @param string $content A string to parse as HTML/XML
* @param null|string $type The content type of the string
*
* @return null|void
*/
public function addContent($content, $type = null)
{
@ -228,7 +233,7 @@ class Crawler extends \SplObjectStorage
*
* @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 Crawler A new instance of the Crawler with the selected node, or an empty Crawler if it does not exist.
*
* @api
*/

View File

@ -22,8 +22,17 @@ namespace Symfony\Component\DomCrawler\Field;
*/
class ChoiceFormField extends FormField
{
/**
* @var string
*/
private $type;
/**
* @var Boolean
*/
private $multiple;
/**
* @var array
*/
private $options;
/**
@ -44,7 +53,7 @@ class ChoiceFormField extends FormField
/**
* Check if the current selected option is disabled
*
* @return bool
* @return Boolean
*/
public function isDisabled()
{
@ -62,8 +71,6 @@ class ChoiceFormField extends FormField
*
* @param string $value The value of the field
*
* @throws \InvalidArgumentException When value type provided is not correct
*
* @api
*/
public function select($value)
@ -74,7 +81,7 @@ class ChoiceFormField extends FormField
/**
* Ticks a checkbox.
*
* @throws \InvalidArgumentException When value type provided is not correct
* @throws \LogicException When the type provided is not correct
*
* @api
*/
@ -90,7 +97,7 @@ class ChoiceFormField extends FormField
/**
* Ticks a checkbox.
*
* @throws \InvalidArgumentException When value type provided is not correct
* @throws \LogicException When the type provided is not correct
*
* @api
*/
@ -248,7 +255,7 @@ class ChoiceFormField extends FormField
/**
* Returns option value with associated disabled flag
*
* @param type $node
* @param \DOMNode $node
*
* @return array
*/

View File

@ -18,11 +18,29 @@ namespace Symfony\Component\DomCrawler\Field;
*/
abstract class FormField
{
/**
* @var \DOMNode
*/
protected $node;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $value;
/**
* @var \DOMDocument
*/
protected $document;
/**
* @var \DOMXPath
*/
protected $xpath;
/**
* @var Boolean
*/
protected $disabled;
/**
@ -87,6 +105,11 @@ abstract class FormField
return true;
}
/**
* Check if the current field is disabled
*
* @return Boolean
*/
public function isDisabled()
{
return $this->node->hasAttribute('disabled');

View File

@ -22,7 +22,13 @@ use Symfony\Component\DomCrawler\Field\FormField;
*/
class Form extends Link implements \ArrayAccess
{
/**
* @var \DOMNode
*/
private $button;
/**
* @var Field\FormField[]
*/
private $fields;
/**
@ -58,6 +64,8 @@ class Form extends Link implements \ArrayAccess
*
* @param array $values An array of field values
*
* @return Form
*
* @api
*/
public function setValues(array $values)
@ -253,8 +261,6 @@ class Form extends Link implements \ArrayAccess
*
* @param FormField $field The field
*
* @return FormField The field instance
*
* @api
*/
public function set(FormField $field)

View File

@ -20,8 +20,17 @@ namespace Symfony\Component\DomCrawler;
*/
class Link
{
/**
* @var \DOMNode A \DOMNode instance
*/
protected $node;
/**
* @var string The method to use for the link
*/
protected $method;
/**
* @var string The URI of the page where the link is embedded (or the base href)
*/
protected $currentUri;
/**
@ -31,7 +40,7 @@ class Link
* @param string $currentUri The URI of the page where the link is embedded (or the base href)
* @param string $method The method to use for the link (get by default)
*
* @throws \LogicException if the node is not a link
* @throws \InvalidArgumentException if the node is not a link
*
* @api
*/
@ -90,7 +99,7 @@ class Link
}
// only an anchor
if ('#' === $uri[0]) {
if ('#' === $uri[0]) {
$baseUri = $this->currentUri;
if (false !== $pos = strpos($baseUri, '#')) {
$baseUri = substr($baseUri, 0, $pos);
@ -120,11 +129,23 @@ class Link
return substr($this->currentUri, 0, strrpos($this->currentUri, '/') + 1).$uri;
}
/**
* Returns raw uri data
*
* @return string
*/
protected function getRawUri()
{
return $this->node->getAttribute('href');
}
/**
* Sets current \DOMNode instance
*
* @param \DOMNode $node A \DOMNode instance
*
* @throws \LogicException If given node is not an anchor
*/
protected function setNode(\DOMNode $node)
{
if ('a' != $node->nodeName) {

View File

@ -32,7 +32,10 @@ class DateComparator extends Comparator
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
}
if (false === $target = @strtotime($matches[2])) {
try {
$date = new \DateTime($matches[2]);
$target = $date->format('U');
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
}

View File

@ -174,13 +174,18 @@ class StubIntlDateFormatter
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only integer unix timestamps are supported');
}
if (!is_int($timestamp)) {
// behave like the intl extension
// behave like the intl extension
if (!is_int($timestamp) && version_compare(\PHP_VERSION, '5.3.4', '<')) {
StubIntl::setErrorCode(StubIntl::U_ILLEGAL_ARGUMENT_ERROR);
return false;
}
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
if ($timestamp instanceOf \DateTime && version_compare(\PHP_VERSION, '5.3.4', '>=')) {
$timestamp = $timestamp->getTimestamp();
}
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
$formatted = $transformer->format($this->createDateTime($timestamp));

View File

@ -274,6 +274,19 @@ class StubIntlDateFormatterTest extends LocaleTestCase
array('zzzzz', 0, 'GMT+00:00'),
);
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
if (version_compare(\PHP_VERSION, '5.3.4', '>=')) {
$dateTime = new \DateTime('@0');
/* general, DateTime */
$formatData[] = array('y-M-d', $dateTime, '1970-1-1');
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00');
$formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70");
$formatData[] = array('h:mm a', $dateTime, '12:00 AM');
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00');
$formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM');
}
return $formatData;
}