2010-03-31 07:42:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony package.
|
2010-03-31 07:42:18 +01:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\CssSelector;
|
|
|
|
|
2010-03-31 07:42:18 +01:00
|
|
|
/**
|
|
|
|
* Token represents a CSS Selector token.
|
|
|
|
*
|
|
|
|
* This component is a port of the Python lxml library,
|
|
|
|
* which is copyright Infrae and distributed under the BSD license.
|
|
|
|
*
|
2010-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2010-03-31 07:42:18 +01:00
|
|
|
*/
|
|
|
|
class Token
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $type;
|
|
|
|
protected $value;
|
|
|
|
protected $position;
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2011-02-05 22:08:01 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param string $type The type of this token.
|
|
|
|
* @param mixed $value The value of this token.
|
|
|
|
* @param int $position The order of this token.
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function __construct($type, $value, $position)
|
|
|
|
{
|
|
|
|
$this->type = $type;
|
|
|
|
$this->value = $value;
|
|
|
|
$this->position = $position;
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2011-02-05 22:08:01 +00:00
|
|
|
/**
|
|
|
|
* Get a string representation of this token.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return (string) $this->value;
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2011-02-05 22:08:01 +00:00
|
|
|
/**
|
|
|
|
* Answer whether this token's type equals to $type.
|
|
|
|
*
|
|
|
|
* @param string $type The type to test against this token's one.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isType($type)
|
|
|
|
{
|
|
|
|
return $this->type == $type;
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2011-02-05 22:08:01 +00:00
|
|
|
/**
|
|
|
|
* Get the position of this token.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getPosition()
|
|
|
|
{
|
|
|
|
return $this->position;
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|