From 12db28d90076629b09a642e8dd4366a1a92f900d Mon Sep 17 00:00:00 2001 From: dakorpar Date: Mon, 11 Feb 2019 10:33:05 +0100 Subject: [PATCH 1/2] Replace deprecated TokenIterator with Stream and Nette\Utils\Tokenizer with Nette\Tokenizer\Tokenizer --- src/Kdyby/Aop/Pointcut/Parser.php | 47 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/Kdyby/Aop/Pointcut/Parser.php b/src/Kdyby/Aop/Pointcut/Parser.php index 04f4e39..dfad5ea 100644 --- a/src/Kdyby/Aop/Pointcut/Parser.php +++ b/src/Kdyby/Aop/Pointcut/Parser.php @@ -13,8 +13,8 @@ use Kdyby; use Nette; use Nette\PhpGenerator\PhpLiteral; -use Nette\Utils\TokenIterator; -use Nette\Utils\Tokenizer; +use Nette\Tokenizer\Stream; +use Nette\Tokenizer\Tokenizer; @@ -73,10 +73,10 @@ public function __construct(MatcherFactory $matcherFactory) public function parse($input) { try { - $tokens = new TokenIterator($this->tokenizer->tokenize($input)); + $tokens = $this->tokenizer->tokenize($input); $tokens->ignored = [self::TOK_WHITESPACE]; - } catch (Nette\Utils\TokenizerException $e) { + } catch (Nette\Tokenizer\Exception $e) { throw new Kdyby\Aop\ParserException("Input contains unexpected expressions", 0, $e); } @@ -90,14 +90,14 @@ public function parse($input) * @return Rules|mixed * @throws \Kdyby\Aop\ParserException */ - protected function doParse(TokenIterator $tokens) + protected function doParse(Stream $tokens) { $inverseNext = FALSE; $operator = NULL; $rules = []; while ($token = $tokens->nextToken()) { if ($tokens->isCurrent(self::TOK_KEYWORD)) { - $rule = $this->{'parse' . $token[0]}($tokens); + $rule = $this->{'parse' . $token->value}($tokens); if ($inverseNext) { $rule = new Matcher\Inverse($rule); $inverseNext = FALSE; @@ -145,7 +145,7 @@ protected function doParse(TokenIterator $tokens) - protected function parseClass(TokenIterator $tokens) + protected function parseClass(Stream $tokens) { $tokens->nextUntil(self::TOK_IDENTIFIER); $className = $tokens->nextValue(); @@ -156,7 +156,7 @@ protected function parseClass(TokenIterator $tokens) - protected function parseMethod(TokenIterator $tokens) + protected function parseMethod(Stream $tokens) { $visibility = NULL; $arguments = []; @@ -201,7 +201,7 @@ protected function parseMethod(TokenIterator $tokens) - protected function parseWithin(TokenIterator $tokens) + protected function parseWithin(Stream $tokens) { $tokens->nextUntil(self::TOK_IDENTIFIER); $within = $tokens->nextValue(); @@ -212,7 +212,7 @@ protected function parseWithin(TokenIterator $tokens) - protected function parseFilter(TokenIterator $tokens) + protected function parseFilter(Stream $tokens) { $tokens->nextUntil(self::TOK_IDENTIFIER); $filter = $tokens->nextValue(); @@ -223,7 +223,7 @@ protected function parseFilter(TokenIterator $tokens) - protected function parseSetting(TokenIterator $tokens) + protected function parseSetting(Stream $tokens) { $tokens->nextUntil('('); if (!$criteria = $this->parseArguments($tokens)) { @@ -235,7 +235,7 @@ protected function parseSetting(TokenIterator $tokens) - protected function parseEvaluate(TokenIterator $tokens) + protected function parseEvaluate(Stream $tokens) { $tokens->nextUntil('('); if (!$criteria = $this->parseArguments($tokens)) { @@ -247,7 +247,7 @@ protected function parseEvaluate(TokenIterator $tokens) - protected function parseClassAnnotatedWith(TokenIterator $tokens) + protected function parseClassAnnotatedWith(Stream $tokens) { $tokens->nextUntil(self::TOK_IDENTIFIER); $annotation = $tokens->nextValue(); @@ -258,7 +258,7 @@ protected function parseClassAnnotatedWith(TokenIterator $tokens) - protected function parseMethodAnnotatedWith(TokenIterator $tokens) + protected function parseMethodAnnotatedWith(Stream $tokens) { $tokens->nextUntil(self::TOK_IDENTIFIER); $annotation = $tokens->nextValue(); @@ -269,7 +269,7 @@ protected function parseMethodAnnotatedWith(TokenIterator $tokens) - protected function parseArguments(TokenIterator $tokens) + protected function parseArguments(Stream $tokens) { $operator = NULL; $conditions = []; @@ -323,7 +323,7 @@ protected function parseArguments(TokenIterator $tokens) $right[] = self::sanitizeArgumentExpression($tokens->currentValue(), $token); } elseif (!$tokens->isCurrent(',', self::TOK_WHITESPACE)) { - throw new Kdyby\Aop\ParserException('Unexpected token ' . $token[Tokenizer::TYPE]); + throw new Kdyby\Aop\ParserException('Unexpected token ' . $token->type); } } @@ -380,11 +380,14 @@ protected function parseArguments(TokenIterator $tokens) return $criteria; } - - + /** + * @param mixed $value + * @param Nette\Tokenizer\Token $token + * @return PhpLiteral + */ protected static function sanitizeArgumentExpression($value, $token) { - if ($token[Tokenizer::TYPE] === self::TOK_STRING || is_numeric($value) || preg_match('~^(TRUE|FALSE)\z~i', $value)) { + if ($token->type === self::TOK_STRING || is_numeric($value) || preg_match('~^(TRUE|FALSE)\z~i', $value)) { return new PhpLiteral($value); } @@ -394,13 +397,13 @@ protected static function sanitizeArgumentExpression($value, $token) /** - * @param TokenIterator $tokens + * @param Stream $tokens * @param array|string $types * @param array|string $allowedToSkip * @throws \Kdyby\Aop\ParserException * @return NULL|string */ - protected static function nextValue(TokenIterator $tokens, $types, $allowedToSkip = []) + protected static function nextValue(Stream $tokens, $types, $allowedToSkip = []) { do { if (call_user_func_array([$tokens, 'isCurrent'], (array)$types)) { @@ -409,7 +412,7 @@ protected static function nextValue(TokenIterator $tokens, $types, $allowedToSki if (!$allowedToSkip || !call_user_func_array([$tokens, 'isCurrent'], (array)$allowedToSkip)) { $type = $tokens->currentToken(); - throw new Kdyby\Aop\ParserException('Unexpected token ' . $type[Tokenizer::TYPE] . ' at offset ' . $type[Tokenizer::OFFSET]); + throw new Kdyby\Aop\ParserException('Unexpected token ' . $type->type . ' at offset ' . $type->offset); } } while ($token = $tokens->nextToken()); From 881c0d9e1473aa1592cc40206594d414f83b98e6 Mon Sep 17 00:00:00 2001 From: dakorpar Date: Mon, 11 Feb 2019 11:47:23 +0100 Subject: [PATCH 2/2] support for php 7.3 --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2dd1386..63ac835 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,17 +9,22 @@ cache: php: - 7.1 - 7.2 + - 7.3 matrix: include: - php: 7.1 env: COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg" - php: 7.2 env: COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg" + - php: 7.3 + env: COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg" allow_failures: - php: 7.1 env: COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg" - php: 7.2 env: COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg" + - php: 7.3 + env: COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg" before_install: - travis_retry composer self-update