| 1 |
<?php namespace WPDeveloper\BetterDocs\Dependencies\SuperClosure\Analyzer; |
| 2 |
|
| 3 |
/** |
| 4 |
* A Token object represents and individual token parsed from PHP code. |
| 5 |
* |
| 6 |
* Each Token object is a normalized token created from the result of the |
| 7 |
* `get_token_all()`. function, which is part of PHP's tokenizer. |
| 8 |
* |
| 9 |
* @link http://us2.php.net/manual/en/tokens.php |
| 10 |
*/ |
| 11 |
class Token |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @var string The token name. Always null for literal tokens. |
| 15 |
*/ |
| 16 |
public $name; |
| 17 |
|
| 18 |
/** |
| 19 |
* @var int|null The token's integer value. Always null for literal tokens. |
| 20 |
*/ |
| 21 |
public $value; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var string The PHP code of the token. |
| 25 |
*/ |
| 26 |
public $code; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var int|null The line number of the token in the original code. |
| 30 |
*/ |
| 31 |
public $line; |
| 32 |
|
| 33 |
/** |
| 34 |
* Constructs a token object. |
| 35 |
* |
| 36 |
* @param string $code |
| 37 |
* @param int|null $value |
| 38 |
* @param int|null $line |
| 39 |
* |
| 40 |
* @throws \InvalidArgumentException |
| 41 |
*/ |
| 42 |
public function __construct($code, $value = null, $line = null) |
| 43 |
{ |
| 44 |
if (is_array($code)) { |
| 45 |
list($value, $code, $line) = array_pad($code, 3, null); |
| 46 |
} |
| 47 |
|
| 48 |
$this->code = $code; |
| 49 |
$this->value = $value; |
| 50 |
$this->line = $line; |
| 51 |
$this->name = $value ? token_name($value) : null; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Determines if the token's value/code is equal to the specified value. |
| 56 |
* |
| 57 |
* @param mixed $value The value to check. |
| 58 |
* |
| 59 |
* @return bool True if the token is equal to the value. |
| 60 |
*/ |
| 61 |
public function is($value) |
| 62 |
{ |
| 63 |
return ($this->code === $value || $this->value === $value); |
| 64 |
} |
| 65 |
|
| 66 |
public function __toString() |
| 67 |
{ |
| 68 |
return $this->code; |
| 69 |
} |
| 70 |
} |
| 71 |
|