Token.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\CssSelector;
  11. /**
  12. * Token represents a CSS Selector token.
  13. *
  14. * This component is a port of the Python lxml library,
  15. * which is copyright Infrae and distributed under the BSD license.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class Token
  20. {
  21. private $type;
  22. private $value;
  23. private $position;
  24. /**
  25. * Constructor.
  26. *
  27. * @param string $type The type of this token.
  28. * @param mixed $value The value of this token.
  29. * @param integer $position The order of this token.
  30. */
  31. public function __construct($type, $value, $position)
  32. {
  33. $this->type = $type;
  34. $this->value = $value;
  35. $this->position = $position;
  36. }
  37. /**
  38. * Gets a string representation of this token.
  39. *
  40. * @return string
  41. */
  42. public function __toString()
  43. {
  44. return (string) $this->value;
  45. }
  46. /**
  47. * Answers whether this token's type equals to $type.
  48. *
  49. * @param string $type The type to test against this token's one.
  50. *
  51. * @return Boolean
  52. */
  53. public function isType($type)
  54. {
  55. return $this->type == $type;
  56. }
  57. /**
  58. * Gets the position of this token.
  59. *
  60. * @return integer
  61. */
  62. public function getPosition()
  63. {
  64. return $this->position;
  65. }
  66. }