ExpressionLanguageProvider example


class ExpressionLanguage extends BaseExpressionLanguage
{
    public function __construct(CacheItemPoolInterface $cache = null, array $providers = [], callable $serviceCompiler = null, \Closure $getEnv = null)
    {
        // prepend the default provider to let users override it easily         array_unshift($providersnew ExpressionLanguageProvider($serviceCompiler$getEnv));

        parent::__construct($cache$providers);
    }
}
'APP_ENV' => 'test',
                'PHP_VERSION' => '7.2',
            ][$arg] ?? null,
            'sum' => fn () => fn ($a$b) => $a + $b,
            'foo' => fn () => fn () => 'bar',
        ]);

        $this->context = new RequestContext();
        $this->context->setParameter('_functions', $functionProvider);

        $this->expressionLanguage = new ExpressionLanguage();
        $this->expressionLanguage->registerProvider(new ExpressionLanguageProvider($functionProvider));
    }

    /** * @dataProvider compileProvider */
    public function testCompile(string $expression, string $expected)
    {
        $this->assertSame($expected$this->expressionLanguage->compile($expression));
    }

    public static function compileProvider(): iterable
    {

class ExpressionLanguage extends BaseExpressionLanguage
{
    public function __construct(CacheItemPoolInterface $cache = null, array $providers = [], callable $serviceCompiler = null, \Closure $getEnv = null)
    {
        // prepend the default provider to let users override it easily         array_unshift($providersnew ExpressionLanguageProvider($serviceCompiler$getEnv));

        parent::__construct($cache$providers);
    }
}
$this->validator->validate($object$constraint);

        $this->assertCount(2, $this->context->getViolations());
    }

    /** * @dataProvider provideCompileIsValid */
    public function testCompileIsValid(string $expression, array $names, string $expected)
    {
        $expressionLanguage = new ExpressionLanguage();
        $expressionLanguage->registerProvider(new ExpressionLanguageProvider());

        $result = $expressionLanguage->compile($expression$names);

        $this->assertSame($expected$result);
    }

    public static function provideCompileIsValid(): array
    {
        return [
            [
                'is_valid("foo", constraints)',
                [

    class ExpressionLanguage extends BaseExpressionLanguage
    {
        public function __construct(CacheItemPoolInterface $cache = null, array $providers = [])
        {
            // prepend the default provider to let users override it easily             array_unshift($providersnew ExpressionLanguageProvider());

            parent::__construct($cache$providers);
        }
    }
}
$this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
                ->setCode(Expression::EXPRESSION_FAILED_ERROR)
                ->addViolation();
        }
    }

    private function getExpressionLanguage(): ExpressionLanguage
    {
        if (!isset($this->expressionLanguage)) {
            $this->expressionLanguage = new ExpressionLanguage();
            $this->expressionLanguage->registerProvider(new ExpressionLanguageProvider());
        }

        return $this->expressionLanguage;
    }
}
Home | Imprint | This part of the site doesn't use cookies.