/** * @return array of match * every match is an array with the following entries: * 0: int startIndex * the index at which the pattern starts * 1: int endIndex * the index at which the pattern ends * */ public function find(array $tokens) { $ret = []; $tai = new TokenArrayIterator($tokens); $start = null; while ($tai->valid()) { $cur = $tai->current(); if (null === $start) { if (TokenTool::match(T_NAMESPACE, $cur)) { $start = $tai->key(); } } else { $found = false; TokenArrayIteratorTool::skipWhiteSpaces($tai); if (true === TokenArrayIteratorTool::skipNsChain($tai)) { TokenArrayIteratorTool::skipWhiteSpaces($tai); if (TokenTool::match(';', $tai->current())) { $found = true; $ret[] = [$start, $tai->key()]; $this->onMatchFound($start, $tai); $start = null; } } if (false === $found) { $start = null; } } $tai->next(); } return $ret; }
/** * @return array of match * every match is an array with the following entries: * 0: int startIndex * the index at which the pattern starts * 1: int endIndex * the index at which the pattern ends * */ public function find(array $tokens) { $ret = []; $tai = new TokenArrayIterator($tokens); $start = null; while ($tai->valid()) { $cur = $tai->current(); if (null === $start) { if (TokenTool::match([T_CLASS, T_TRAIT], $cur)) { $start = $tai->key(); } } else { $found = false; TokenArrayIteratorTool::skipWhiteSpaces($tai); $start = $tai->key(); if (TokenArrayIteratorTool::skipNsChain($tai)) { $found = true; // skipNsChain ends AFTER the chain, not AT the end of it. $tai->prev(); $end = $tai->key(); $tai->next(); $ret[] = [$start, $end]; $this->onMatchFound($start, $tai); $start = null; } if (false === $found) { $start = null; } } $tai->next(); } return $ret; }
/** * @return array of match * every match is an array with the following entries: * 0: int startIndex * the index at which the pattern starts * 1: int endIndex * the index at which the pattern ends * */ public function find(array $tokens) { $ret = []; $tai = new TokenArrayIterator($tokens); $start = null; while ($tai->valid()) { $cur = $tai->current(); if (null === $start) { if (TokenTool::match(T_NEW, $cur)) { $start = $tai->key(); } } else { $found = false; TokenArrayIteratorTool::skipWhiteSpaces($tai); if (true === TokenArrayIteratorTool::skipNsChain($tai)) { $this->parseParenthesis($tai, $found, $start, $ret); } elseif (TokenTool::match(T_VARIABLE, $tai->current())) { $tai->next(); if (TokenTool::match('[', $tai->current())) { if (true === TokenArrayIteratorTool::moveToCorrespondingEnd($tai)) { $tai->next(); $this->parseParenthesis($tai, $found, $start, $ret); } } else { $this->parseParenthesis($tai, $found, $start, $ret); } } if (false === $found) { $start = null; } } $tai->next(); } return $ret; }