Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / expression-language / Token.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\ExpressionLanguage;
13
14 /**
15  * Represents a Token.
16  *
17  * @author Fabien Potencier <fabien@symfony.com>
18  */
19 class Token
20 {
21     public $value;
22     public $type;
23     public $cursor;
24
25     const EOF_TYPE = 'end of expression';
26     const NAME_TYPE = 'name';
27     const NUMBER_TYPE = 'number';
28     const STRING_TYPE = 'string';
29     const OPERATOR_TYPE = 'operator';
30     const PUNCTUATION_TYPE = 'punctuation';
31
32     /**
33      * Constructor.
34      *
35      * @param string $type   The type of the token (self::*_TYPE)
36      * @param string $value  The token value
37      * @param int    $cursor The cursor position in the source
38      */
39     public function __construct($type, $value, $cursor)
40     {
41         $this->type = $type;
42         $this->value = $value;
43         $this->cursor = $cursor;
44     }
45
46     /**
47      * Returns a string representation of the token.
48      *
49      * @return string A string representation of the token
50      */
51     public function __toString()
52     {
53         return sprintf('%3d %-11s %s', $this->cursor, strtoupper($this->type), $this->value);
54     }
55
56     /**
57      * Tests the current token for a type and/or a value.
58      *
59      * @param array|int   $type  The type to test
60      * @param string|null $value The token value
61      *
62      * @return bool
63      */
64     public function test($type, $value = null)
65     {
66         return $this->type === $type && (null === $value || $this->value == $value);
67     }
68 }