Server IP : 104.21.38.3 / Your IP : 172.69.166.65 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/lapma.in/phpMyAdmin/vendor/symfony/expression-language/ |
Upload File : |
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <[email protected]> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\ExpressionLanguage; /** * Represents a function that can be used in an expression. * * A function is defined by two PHP callables. The callables are used * by the language to compile and/or evaluate the function. * * The "compiler" function is used at compilation time and must return a * PHP representation of the function call (it receives the function * arguments as arguments). * * The "evaluator" function is used for expression evaluation and must return * the value of the function call based on the values defined for the * expression (it receives the values as a first argument and the function * arguments as remaining arguments). * * @author Fabien Potencier <[email protected]> */ class ExpressionFunction { private $name; private $compiler; private $evaluator; /** * @param string $name The function name * @param callable $compiler A callable able to compile the function * @param callable $evaluator A callable able to evaluate the function */ public function __construct(string $name, callable $compiler, callable $evaluator) { $this->name = $name; $this->compiler = $compiler instanceof \Closure ? $compiler : \Closure::fromCallable($compiler); $this->evaluator = $evaluator instanceof \Closure ? $evaluator : \Closure::fromCallable($evaluator); } /** * @return string */ public function getName() { return $this->name; } /** * @return \Closure */ public function getCompiler() { return $this->compiler; } /** * @return \Closure */ public function getEvaluator() { return $this->evaluator; } /** * Creates an ExpressionFunction from a PHP function name. * * @param string|null $expressionFunctionName The expression function name (default: same than the PHP function name) * * @return self * * @throws \InvalidArgumentException if given PHP function name does not exist * @throws \InvalidArgumentException if given PHP function name is in namespace * and expression function name is not defined */ public static function fromPhp(string $phpFunctionName, string $expressionFunctionName = null) { $phpFunctionName = ltrim($phpFunctionName, '\\'); if (!\function_exists($phpFunctionName)) { throw new \InvalidArgumentException(sprintf('PHP function "%s" does not exist.', $phpFunctionName)); } $parts = explode('\\', $phpFunctionName); if (!$expressionFunctionName && \count($parts) > 1) { throw new \InvalidArgumentException(sprintf('An expression function name must be defined when PHP function "%s" is namespaced.', $phpFunctionName)); } $compiler = function (...$args) use ($phpFunctionName) { return sprintf('\%s(%s)', $phpFunctionName, implode(', ', $args)); }; $evaluator = function ($p, ...$args) use ($phpFunctionName) { return $phpFunctionName(...$args); }; return new self($expressionFunctionName ?: end($parts), $compiler, $evaluator); } }