Extract the name of the command from the expression.

@param  string  $expression
@return string

@throws \InvalidArgumentException
487639
protected static function name($expression)
    {
        if (trim($expression) === '') {
            throw new InvalidArgumentException('Console command definition is empty.');
        }

        if (! preg_match('/[^\s]+/', $expression, $matches)) {
            throw new InvalidArgumentException('Unable to determine command name from signature.');
        }

        return $matches[0];
    }
1081730
protected function _compile_asset($expression)
    {
        if (strcspn($expression, '$\'"') === strlen($expression)) {
            $expression = '(\'' . trim($expression, '()') . '\')';
        }

        return asset(substr($expression, 2, -2));
        /*return "<?= asset{$expression}; ?>";*/
    }
739035
public function orderBy( $expression, $direction = 'ASC' ) {
		$direction = strtoupper( $direction );
		if ( !in_array( $direction, array( 'ASC', 'DESC' ) ) ) {
			throw new InvalidArgumentException( '$direction has to be either ASC or DESC' );
		}

		$this->expressionValidator->validate( $expression,
			ExpressionValidator::VALIDATE_VARIABLE | ExpressionValidator::VALIDATE_FUNCTION
		);

		$this->usageValidator->trackUsedPrefixes( $expression );
		$this->usageValidator->trackUsedVariables( $expression );
		$this->modifiers['ORDER BY'] = $direction . ' (' . $expression . ')';
	}
721302
public function filter( $expression ) {
		$this->expressionValidator->validate( $expression, ExpressionValidator::VALIDATE_FUNCTION );

		$this->usageValidator->trackUsedPrefixes( $expression );
		$this->usageValidator->trackUsedVariables( $expression );

		$this->filters[] = '(' . $expression . ')';

		return $this;
	}
154004
private function parseRequestValueExpression(string $expression, RequestInterface $request): string
    {
        $expression = preg_replace_callback(
            '/(\$\w+)/',
            function ($matches) use ($request) {
                $variable = $request->get(substr($matches[1], 1));

                if (is_array($variable) || is_object($variable)) {
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Cannot use %s ($%s) as parameter in expression.',
                            gettype($variable),
                            $matches[1]
                        )
                    );
                }

                return is_string($variable) ? sprintf('"%s"', $variable)
                    : $variable;
            },
            $expression
        );

        return $this->expression->evaluate(
            $expression,
            ['container' => $this->container]
        );
    }
433754
protected function parseInlineArguments(string $expression) : array
    {
        $splited = explode(',', $expression);
        $arguments = [];
        $function_part = false;
        $current = 0;
        foreach ($splited as $part){

            if(!isset($arguments[$current])) {
                $arguments[$current] = '';
            }

            // Função: string seguida de (
            if(preg_match('#[a-zA-Z] ?\(#', $part) && strpos($part, ')', -1) === false) {
                $function_part = true;
                $arguments[$current] = trim($part);
                continue;

            } elseif($function_part == true && strpos($part, ')', -1) !== false) {
                // Função: string terminando com )
                $function_part = false;
                $arguments[$current] .= "," . trim($part);

            } elseif($function_part == true) {
                // Função: argumentos internos
                $arguments[$current] .= "," . trim($part);
                continue;

            } else {
                $arguments[$current] = $part;
            }
            $current++;
        }

        return $arguments;
    }
630502
protected function compileInject( $expression )
	{
		$segments = $this->parseSegments( $expression, 2 );

		return '<?php $' . trim( $segments[0] ) . " = app('" . trim( $segments[1] ) . "'); ?>";
	}
1022191
public function preProcessExpression(Expression $expression)
    {
        $expression = $this->completeExpression($expression);
        
        if ($this->isParameterized() && ($expression instanceof Expr\Parameter)) {
            
            $placeholder = $this->getPlaceholderForExpression($expression);
            if (null === $placeholder) {
                $placeholder = new Expr\Raw(':p' . $this->parameterCounter++);
                $this->setPlaceholder($expression->hashCode(), $placeholder);
            }
            
            return $placeholder;
        }
        
        return $expression;
    }
1002831
protected function parseJsonArguments(string $expression) : array
    {
        // Prepara o json
        $expression = preg_replace('#\{\s*#','{', $expression);  // transoforma [ em { sem espaços
        $expression = preg_replace('#\s*\}#','}', $expression);  // transoforma ] em } sem espaços
        $expression = preg_replace('#\s*:#',':', $expression);    // remove espaçoes antes de :
        $expression = preg_replace('#:\s*#',':', $expression);    // remove espaçoes após de :
        $expression = preg_replace('#,\s*#',',', $expression);    // remove espaços antes das virgulas
        $expression = preg_replace('#\s*,#',',', $expression);    // remove espaços após as virgulas

        // Aspas
        $expression = preg_replace("#'([a-zA-Z0-9\_-]*)':#",'"$1":', $expression); // transforma 'xxx': em "xxx":
        $expression = preg_replace("#:'([a-zA-Z0-9\_-]*)'#",':"$1"', $expression); // transforma :'xxx' em :"xxx":
        $expression = preg_replace('#:([^"])#',':"$1', $expression);  // Adiciona aspas ausentes no inicio dos valores
        $expression = preg_replace('#([^"]),"#','$1","', $expression);// Adiciona aspas ausentes no final dos valores
        $expression = preg_replace('#([^"])}#','$1"}', $expression);  // Adiciona aspas ausentes no final do json

        $decoded = json_decode($expression, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException('Invalid json syntax');
        }

        return $decoded;
    }
655467
public function search($expression)
    {
        // Apply JMESPath expression on each result, but as a flat sequence.
        return flatmap($this, function (Result $result) use ($expression) {
            return (array) $result->search($expression);
        });
    }
247495
private function replaceViewFunctionCalls(string $expression) : string
    {
        $phpTokens = token_get_all('<?php ' . $expression . ' ?>');
        $opulenceTokens = [];

        // This is essentially a foreach loop that can be fast-forwarded
        while (list($index, $token) = each($phpTokens)) {
            if (is_string($token)) {
                // Convert the simple token to an array for uniformity
                $opulenceTokens[] = [T_STRING, $token, 0];

                continue;
            }

            switch ($token[0]) {
                case T_STRING:
                    // If this is a function
                    if (count($phpTokens) > $index && $phpTokens[$index + 1] === '(') {
                        $prevToken = $index > 0 ? $phpTokens[$index - 1] : null;

                        // If this is a native PHP function or is really a method call, don't convert it
                        if (
                            (
                                ($prevToken[0] === T_OBJECT_OPERATOR || $prevToken[0] === T_DOUBLE_COLON) &&
                                is_array($prevToken)
                            ) ||
                            function_exists($token[1])
                        ) {
                            $opulenceTokens[] = $token;
                        } else {
                            // This is a view function
                            // Add $__opulenceFortuneTranspiler
                            $opulenceTokens[] = [T_VARIABLE, '$__opulenceFortuneTranspiler', $token[2]];
                            // Add ->
                            $opulenceTokens[] = [T_OBJECT_OPERATOR, '->', $token[2]];
                            // Add callViewFunction("FUNCTION_NAME")
                            $opulenceTokens[] = [T_STRING, 'callViewFunction("' . $token[1] . '")', $token[2]];
                        }
                    } else {
                        $opulenceTokens[] = $token;
                    }

                    break;
                default:
                    $opulenceTokens[] = $token;

                    break;
            }
        }

        // Remove php open/close PHP tags
        array_shift($opulenceTokens);
        array_pop($opulenceTokens);

        // Rejoin the tokens
        $joinedTokens = implode('', array_column($opulenceTokens, 1));

        $replacementCount = 0;
        $callback = function (array $matches) {
            if ($matches[2] === ')') {
                // There were no parameters
                return $matches[1] . ')';
            } else {
                // There were parameters
                return $matches[1] . ', ' . $matches[2];
            }
        };

        /**
         * View functions are left in a broken state
         * For example, 'foo()' will currently look like '...->callViewFunction("foo")()'
         * This should be converted to '...->callViewFunction("foo")'
         * Similarly, 'foo("bar")' will currently look like '...->callViewFunction("foo")("bar")'
         * This should be converted to '...->callViewFunction("foo", "bar")'
         */
        do {
            $joinedTokens = preg_replace_callback(
                '/(\$__opulenceFortuneTranspiler->callViewFunction\([^\)]+)\)\((.)/',
                $callback,
                $joinedTokens,
                -1,
                $replacementCount
            );
        } while ($replacementCount > 0);

        return trim($joinedTokens);
    }
665317
public static function parse(string $expression): string
    {
        $expression = \trim($expression);

        if ($expression === '' || \is_numeric($expression)) {
            return $expression;
        }

        if (!isset(self::$cache[$expression])) {
            $tree = self::treeStruct($expression);
            self::$cache[$expression] = self::transform($tree);
        }

        return self::$cache[$expression];
    }
281946
public function search($expression)
    {
        // Apply JMESPath expression on each result, but as a flat sequence.
        return \Aws\flatmap($this, function (\Aws\ResultInterface $result) use ($expression) {
            return (array)$result->search($expression);
        });
    }
829774
public static function var_line($expression) {
        $line = print_r($expression, true);
        $line = str_replace(PHP_EOL, ' ', $line);
        $line = trim($line);
        return $line;
    }
391080
public function parse($expression, $names)
    {
        if ($expression instanceof ParsedExpression) {
            return $expression;
        }

        asort($names);
        $cacheKeyItems = array();

        foreach ($names as $nameKey => $name) {
            $cacheKeyItems[] = is_int($nameKey) ? $name : $nameKey.':'.$name;
        }

        $key = $expression.'//'.implode('|', $cacheKeyItems);

        if (null === $parsedExpression = $this->cache->fetch($key)) {
            $nodes = $this->getParser()->parse($this->getLexer()->tokenize((string) $expression), $names);
            $parsedExpression = new ParsedExpression((string) $expression, $nodes);

            $this->cache->save($key, $parsedExpression);
        }

        return $parsedExpression;
    }
873759
protected function getEventName($event)
    {
        if (Assert::instanceOf($event, '\\One\\Event\\Event')) {
            return $event->getName();
        } elseif (Assert::string($event)) {
            return $event;
        }

        throw new InvalidArgumentException(
            '`Event` must be `string` or extends class `One\Event\Event`'
        );
    }
1165204
public function remove(ExpressionContract $expression)
    {
        $filtered = array_filter($this->_expressions, function ($known) use ($expression) {
            return "$known" != "$expression";
        });

        $this->_expressions = array_values($filtered);

        return $this;
    }