dev-master
9999999-devBundle for PEL (PHP Expression Language) integration in Symfony
MIT
The Requires
The Development Requires
by Boris Guéry
expression expression language pel
Bundle for PEL (PHP Expression Language) integration in Symfony
This bundle integrates Kitano PHP Expression language into Symfony 2., (*1)
First, install the bundle package with composer:, (*3)
$ php composer.phar require kitano/pel-bundle
Next, activate the bundle into app/AppKernel.php
:, (*4)
<?php // ... public function registerBundles() { $bundles = array( //... new Kitano\PelBundle\KitanoPelBundle(), ); // ... }
The Expression
compiler can be injected into your services:, (*5)
<?php namespace My\Service; use Pel\Expression\ExpressionCompiler; class MyService { private $expressionCompiler; public function __construct(ExpressionCompiler $expressionCompiler) { $this->expressionCompiler = $expressionCompiler; } }
<service id="my.service.my_service" class="My\Service\MyService"> <argument type="service" id="kitano_pel.expression.compiler" /> </service>
And then you can start compiling expressions:, (*6)
<?php namespace My\Service; use Pel\Expression\ExpressionCompiler; use Pel\Expression\Expression; class MyService { // ... public function someMethod() { $evaluator = eval($this->expressionCompiler->compileExpression(new Expression("['foo', 'bar']"))); $result = call_user_func($evaluator, array())); // $result => array('foo', 'bar') } }
After having created your expression compiler
(see https://github.com/Kitano/php-expression#adding-a-custom-function-compiler),
you need to register a new service into the Dependency Container with one of the following tag
(depending on your expression type):
* kitano_pel.type_compiler
* kitano_pel.function_compiler
, (*7)
If we take the isNumber()
function compiler example:, (*8)
<service id="my.expression.compiler.is_number_compiler" class="My\Expression\Compiler\Func\IsNumberFunctionCompiler" public="false"> <tag name="kitano_pel.function_compiler" /> </service>
Then, you can start compiling your custom expressions:, (*9)
<?php namespace My\Service; use Pel\Expression\ExpressionCompiler; use Pel\Expression\Expression; class MyService { // ... public function someMethod() { $evaluator = eval($this->expressionCompiler->compileExpression(new Expression("isNumber('1234')"))); $result = call_user_func($evaluator, array())); // $result => bool(true) } }
Install development dependencies, (*10)
$ composer install --dev
Run the test suite, (*11)
$ vendor/bin/phpunit
This bundle is under the MIT license. See the complete license in the bundle:, (*12)
Resources/meta/LICENSE
Bundle for PEL (PHP Expression Language) integration in Symfony
MIT
expression expression language pel