private static function createLambdaFromString(string $closure, string $closureArgs)
    {
        $posDollar = strpos($closure, '$');
        if ($posDollar !== false) {
            if (isset(self::$lambdaCache[$closure][$closureArgs]))
                return self::$lambdaCache[$closure][$closureArgs];
            $posArrow = strpos($closure, '==>', $posDollar);
            if ($posArrow !== false) {
                $args = trim(substr($closure, 0, $posArrow), "() \r\n\t");
                $code = substr($closure, $posArrow + 3);
            }
            else {
                $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null';
                $code = $closure;
            }
            $code = trim($code, " \r\n\t");
            if (strlen($code) > 0 && $code[0] != '{')
                $code = "return {$code};";
            $fun = @create_function($args, $code);
            // @codeCoverageIgnoreStart
            if (!$fun)
                throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
            // @codeCoverageIgnoreEnd
            self::$lambdaCache[$closure][$closureArgs] = $fun;
            return $fun;
        }
        return null;
    }
private static function createLambdaFromString(string $closure, string $closureArgs)
    {
        $posDollar = strpos($closure, '$');
        if ($posDollar !== false) {
            if (isset(self::$lambdaCache[$closure][$closureArgs]))
                return self::$lambdaCache[$closure][$closureArgs];
            $posArrow = strpos($closure, '==>', $posDollar);
            if ($posArrow !== false) {
                $args = trim(substr($closure, 0, $posArrow), "() \r\n\t");
                $code = substr($closure, $posArrow + 3);
            }
            else {
                $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null';
                $code = $closure;
            }
            $code = trim($code, " \r\n\t");
            if (strlen($code) > 0 && $code[0] != '{')
                $code = "return {$code};";
            $fun = @create_function($args, $code);
            // @codeCoverageIgnoreStart
            if (!$fun)
                throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
            // @codeCoverageIgnoreEnd
            self::$lambdaCache[$closure][$closureArgs] = $fun;
            return $fun;
        }
        return null;
    }
private static function createLambdaFromString ( string $ closure , string $ closureArgs ) { $ posDollar = strpos ( $ closure , '$' ) ; if ( $ posDollar !== false ) { if ( isset ( self :: $ lambdaCache [ $ closure ] [ $ closureArgs ] ) ) return self :: $ lambdaCache [ $ closure ] [ $ closureArgs ] ; $ posArrow = strpos ( $ closure , '==>' , $ posDollar ) ; if ( $ posArrow !== false ) { $ args = trim ( substr ( $ closure , 0 , $ posArrow ) , "() \r\n\t" ) ; $ code = substr ( $ closure , $ posArrow + 3 ) ; } else { $ args = '$' . str_replace ( ',' , '=null,$' , $ closureArgs ) . '=null' ; $ code = $ closure ; } $ code = trim ( $ code , " \r\n\t" ) ; if ( strlen ( $ code ) > 0 && $ code [ 0 ] != '{' ) $ code = "return {$code};" ; $ fun = @ create_function ( $ args , $ code ) ; // @codeCoverageIgnoreStart if ( ! $ fun ) throw new \ InvalidArgumentException ( self :: ERROR_CANNOT_PARSE_LAMBDA ) ; // @codeCoverageIgnoreEnd self :: $ lambdaCache [ $ closure ] [ $ closureArgs ] = $ fun ; return $ fun ; } return null ; }
Convert string lambda to callable function.
@param string $closure
@param string $closureArgs
@throws \InvalidArgumentException Incorrect lambda syntax.
@return string|null
Convert string lambda to callable function .