class AttributeEmulator
Hierarchy
- class \PhpParser\Lexer\TokenEmulator\TokenEmulator
- class \PhpParser\Lexer\TokenEmulator\AttributeEmulator extends \PhpParser\Lexer\TokenEmulator\TokenEmulator
Expanded class hierarchy of AttributeEmulator
1 file declares its use of AttributeEmulator
- Emulative.php in vendor/
nikic/ php-parser/ lib/ PhpParser/ Lexer/ Emulative.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ Lexer/ TokenEmulator/ AttributeEmulator.php, line 8
Namespace
PhpParser\Lexer\TokenEmulatorView source
final class AttributeEmulator extends TokenEmulator {
public function getPhpVersion() : PhpVersion {
return PhpVersion::fromComponents(8, 0);
}
public function isEmulationNeeded(string $code) : bool {
return strpos($code, '#[') !== false;
}
public function emulate(string $code, array $tokens) : array {
// We need to manually iterate and manage a count because we'll change
// the tokens array on the way.
for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
$token = $tokens[$i];
if ($token->text === '#' && isset($tokens[$i + 1]) && $tokens[$i + 1]->text === '[') {
array_splice($tokens, $i, 2, [
new Token(\T_ATTRIBUTE, '#[', $token->line, $token->pos),
]);
$c--;
continue;
}
}
return $tokens;
}
public function reverseEmulate(string $code, array $tokens) : array {
// TODO
return $tokens;
}
public function preprocessCode(string $code, array &$patches) : string {
$pos = 0;
while (false !== ($pos = strpos($code, '#[', $pos))) {
// Replace #[ with %[
$code[$pos] = '%';
$patches[] = [
$pos,
'replace',
'#',
];
$pos += 2;
}
return $code;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
AttributeEmulator::emulate | public | function | Overrides TokenEmulator::emulate | |
AttributeEmulator::getPhpVersion | public | function | Overrides TokenEmulator::getPhpVersion | |
AttributeEmulator::isEmulationNeeded | public | function | Overrides TokenEmulator::isEmulationNeeded | |
AttributeEmulator::preprocessCode | public | function | Overrides TokenEmulator::preprocessCode | |
AttributeEmulator::reverseEmulate | public | function | Overrides TokenEmulator::reverseEmulate |