2017 © Pedro Peláez
 

symfony-bundle pel-bundle

Bundle for PEL (PHP Expression Language) integration in Symfony

image

kitano/pel-bundle

Bundle for PEL (PHP Expression Language) integration in Symfony

  • Wednesday, April 17, 2013
  • by Kitano
  • Repository
  • 5 Watchers
  • 4 Stars
  • 1,039 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PelBundle

This bundle integrates Kitano PHP Expression language into Symfony 2., (*1)

TODO

  • Add symfony specific expressions + compilers (if any)

Index

State

Unstable. Build Status, (*2)

Installation

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(),
        );

        // ...
    }

Usage

Basic Usage

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')
    }
}

Registering custom expression compiler

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)
    }
}

Testing

Install development dependencies, (*10)

$ composer install --dev

Run the test suite, (*11)

$ vendor/bin/phpunit

License

This bundle is under the MIT license. See the complete license in the bundle:, (*12)

Resources/meta/LICENSE

The Versions

17/04 2013

dev-master

9999999-dev

Bundle for PEL (PHP Expression Language) integration in Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

expression expression language pel