Neos\Flow\Aop\Pointcut\PointcutExpressionParser::getSubstringBetweenParentheses PHP Method

getSubstringBetweenParentheses() protected method

Returns the substring of $string which is enclosed by parentheses of the first level.
protected getSubstringBetweenParentheses ( string $string ) : string
$string string The string to parse
return string The inner part between the first level of parentheses
    protected function getSubstringBetweenParentheses($string)
    {
        $startingPosition = 0;
        $openParentheses = 0;
        $substring = '';
        for ($i = $startingPosition; $i < strlen($string); $i++) {
            if ($string[$i] === ')') {
                $openParentheses--;
            }
            if ($openParentheses > 0) {
                $substring .= $string[$i];
            }
            if ($string[$i] === '(') {
                $openParentheses++;
            }
        }
        if ($openParentheses < 0) {
            throw new InvalidPointcutExpressionException('Pointcut expression is in excess of ' . abs($openParentheses) . ' closing parenthesis/es, defined in ' . $this->sourceHint, 1168966689);
        }
        if ($openParentheses > 0) {
            throw new InvalidPointcutExpressionException('Pointcut expression lacks of ' . $openParentheses . ' closing parenthesis/es, defined in ' . $this->sourceHint, 1168966690);
        }
        return $substring;
    }