File Manager Lite
Dir:
/home/codewavebd/public_html/vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator
Upload
[..]
AsymmetricVisibilityTokenEmulator.php (3.27 KB)
Edit
Rename
Del
AttributeEmulator.php (1.44 KB)
Edit
Rename
Del
EnumTokenEmulator.php (701 B)
Edit
Rename
Del
KeywordEmulator.php (1.79 KB)
Edit
Rename
Del
MatchTokenEmulator.php (422 B)
Edit
Rename
Del
PropertyTokenEmulator.php (437 B)
Edit
Rename
Del
ReadonlyFunctionTokenEmulator.php (976 B)
Edit
Rename
Del
ReverseEmulator.php (1013 B)
Edit
Rename
Del
TokenEmulator.php (819 B)
Edit
Rename
Del
VoidCastEmulator.php (3.04 KB)
Edit
Rename
Del
Edit: KeywordEmulator.php
<?php declare(strict_types=1); namespace PhpParser\Lexer\TokenEmulator; use PhpParser\Token; abstract class KeywordEmulator extends TokenEmulator { abstract public function getKeywordString(): string; abstract public function getKeywordToken(): int; public function isEmulationNeeded(string $code): bool { return strpos(strtolower($code), $this->getKeywordString()) !== false; } /** @param Token[] $tokens */ protected function isKeywordContext(array $tokens, int $pos): bool { $prevToken = $this->getPreviousNonSpaceToken($tokens, $pos); if ($prevToken === null) { return false; } return $prevToken->id !== \T_OBJECT_OPERATOR && $prevToken->id !== \T_NULLSAFE_OBJECT_OPERATOR; } public function emulate(string $code, array $tokens): array { $keywordString = $this->getKeywordString(); foreach ($tokens as $i => $token) { if ($token->id === T_STRING && strtolower($token->text) === $keywordString && $this->isKeywordContext($tokens, $i)) { $token->id = $this->getKeywordToken(); } } return $tokens; } /** @param Token[] $tokens */ private function getPreviousNonSpaceToken(array $tokens, int $start): ?Token { for ($i = $start - 1; $i >= 0; --$i) { if ($tokens[$i]->id === T_WHITESPACE) { continue; } return $tokens[$i]; } return null; } public function reverseEmulate(string $code, array $tokens): array { $keywordToken = $this->getKeywordToken(); foreach ($tokens as $token) { if ($token->id === $keywordToken) { $token->id = \T_STRING; } } return $tokens; } }
Simpan