Description
The purpose of this library is to provide a common base for an PHP Expression Language.
This is not really a creative library since it burrows almost all the code from the great
JMSSecurityExtraBundle which already defines
more or less such a base for a powerful EL (Expression Language).
The idea is to take this code outside of the Johannes's bundle and to standardize it.
PHP Expression alternatives and similar libraries
Based on the "Miscellaneous" category.
Alternatively, view PHP Expression alternatives based on common mentions on social networks and blogs.
-
Country List
:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats. -
Hprose-PHP
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP -
PHPVerbalExpressions
PHP Regular expressions made easy -
SuperClosure
Serialize closures. Not maintained. Consider using opis/closure. -
dotenv-linter
⚡️Lightning-fast linter for .env files. Written in Rust 🦀 -
Pagerfanta
Pagination library for PHP applications with support for several data providers -
Essence
Extracts information about web pages, like youtube videos, twitter statuses or blog articles. -
sabre/vobject
:date: The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects -
html2text
A PHP component to convert HTML into a plain text format -
RMT
RMT is a handy tool to help releasing new version of your software -
JSONPCallbackValidator
JSONP callback validator. -
Token Bucket
Implementation of the Token Bucket algorithm in PHP. -
Prooph Service Bus
PHP Lightweight Message Bus supporting CQRS. -
Lodash-PHP
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP -
Embera
A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support. -
PHP-GPIO
A PHP library to play with the Raspberry PI's GPIO pins -
noCAPTCHA
:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3) -
ClassPreloader
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files. -
Metrics
Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in. -
git-profile
Utility that helps you switch git configurations with ease. -
Slimdump
A tool for creating configurable dumps of large MySQL-databases. -
Cake Utility
[READ-ONLY] CakePHP Utility classes such as Inflector, Text, Hash, Security and Xml. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp -
RedisSessionHandler
An alternative Redis session handler for PHP featuring per-session locking and session fixation protection -
html-object
A set of classes to create and manipulate HTML objects abstractions -
Opengraph
A PHP 5.3+ and PHP 7.3 framework for OpenGraph Protocol -
Sslurp
Sslurp is a simple library which aims to make properly dealing with SSL in PHP suck less. -
Procrastinator
Execute time consuming tasks as late as possible in a request -
Yell
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.
Access the most powerful time series database as a service
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of PHP Expression or a related project?
README
PHP Expression Language
The purpose of this library is to provide a common base for an PHP Expression Language.
This is not really a creative library since it burrows almost all the code from the great JMSSecurityExtraBundle which already defines more or less such a base for a powerful EL (Expression Language).
The idea is to take this code outside of the Johannes's bundle and to standardize it.
Simple usage
$compiler = new ExpressionCompiler();
$evaluator = eval($compiler->compileExpression(new Expression("date.format(format)")));
$context = array(
'date' => new \DateTime(),
'format' => 'Y',
);
$result = $evaluator($context);
echo $result; // 2013
Adding a custom function compiler
The isNumber() function expression:
First you need to create a compiler for your function
<?php namespace My\Expression\Compiler\Func; use Pel\Expression\Compiler\Func\FunctionCompilerInterface; use Pel\Expression\ExpressionCompiler; use Pel\Expression\Ast\FunctionExpression; use Pel\Exception\RuntimeException; class IsNumberFunctionCompiler implements FunctionCompilerInterface { public function getName() { return 'isNumber'; } public function compilePreconditions(ExpressionCompiler $compiler, FunctionExpression $function) { if (1 !== count($function->args)) { throw new RuntimeException(sprintf('The isNumber() function expects exactly one argument, but got "%s".', var_export($function->args, true))); } } public function compile(ExpressionCompiler $compiler, FunctionExpression $function) { $compiler ->write("is_numeric(") ->compileInternal($function->args[0]) ->write(")") ; } }
Next, after having instanciated the
ExpressionCompiler
, you just need to register your custom function compiler<?php $compiler = new ExpressionCompiler(); $compiler->addFunctionCompiler(new IsNumberFunctionCompiler()); $evaluator = eval($compiler->compileExpression(new Expression("isNumber('1234')"))); var_dump(call_user_func($evaluator, array())); // bool(true) $evaluator = eval($compiler->compileExpression(new Expression("isNumber('1234abc')"))); var_dump(call_user_func($evaluator, array())); // bool(false)
License
This bundle is under the MIT license. See the complete license in library:
LICENSE
*Note that all licence references and agreements mentioned in the PHP Expression README section above
are relevant to that project's source code only.