diff --git a/.phpunit.result.cache b/.phpunit.result.cache index be1bc9d..52a4ae4 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Tests\\JuelEngineTest::testEngine":4,"Tests\\JuelEngineTest::testEngineManager":5,"Tests\\JuelEngineTest::testEngineFactory":4,"Tests\\JuelEngineTest::testJuelEngineManager":4,"Tests\\ExpressionLanguageTest::testNumericMethods":4,"Tests\\ExpressionLanguageTest::testMethodInvocation":4,"Tests\\JuelEngineTest::testJuelEngineManagerWithFunction":4,"Tests\\LuaEngineTest::testLuaScript":5},"times":{"Tests\\JuelEngineTest::testEngine":0.003,"Tests\\JuelEngineTest::testEngineFactory":0.006,"Tests\\JuelEngineTest::testEngineManager":0.003,"Tests\\JuelEngineTest::testJuelEngineManager":0.001,"Tests\\ExpressionLanguageTest::testNumericVariables":0.006,"Tests\\ExpressionLanguageTest::testNumericMethods":0,"Tests\\ExpressionLanguageTest::testBooleanMethods":0,"Tests\\ExpressionLanguageTest::testMethodInvocation":0.001,"Tests\\ExpressionLanguageTest::testExpressionString":0,"Tests\\ExpressionLanguageTest::testIsDeferred":0,"Tests\\ExpressionLanguageTest::testGetExpectedType":0,"Tests\\ExpressionLanguageTest::testGetType":0,"Tests\\JuelEngineTest::testJuelEngineManagerWithVariable":0.001,"Tests\\JuelEngineTest::testJuelEngineManagerWithFunction":0.001,"Tests\\LuaEngineTest::testLuaScript":0}} \ No newline at end of file +{"version":1,"defects":{"Tests\\JuelEngineTest::testEngine":4,"Tests\\JuelEngineTest::testEngineManager":5,"Tests\\JuelEngineTest::testEngineFactory":4,"Tests\\JuelEngineTest::testJuelEngineManager":4,"Tests\\ExpressionLanguageTest::testNumericMethods":4,"Tests\\ExpressionLanguageTest::testMethodInvocation":4,"Tests\\JuelEngineTest::testJuelEngineManagerWithFunction":3,"Tests\\LuaEngineTest::testLuaScript":5,"Tests\\JuelEngineTest::testOgnlSyntaxInJuelExpression":4},"times":{"Tests\\JuelEngineTest::testEngine":0.003,"Tests\\JuelEngineTest::testEngineFactory":0.021,"Tests\\JuelEngineTest::testEngineManager":0.003,"Tests\\JuelEngineTest::testJuelEngineManager":0.001,"Tests\\ExpressionLanguageTest::testNumericVariables":0.006,"Tests\\ExpressionLanguageTest::testNumericMethods":0,"Tests\\ExpressionLanguageTest::testBooleanMethods":0,"Tests\\ExpressionLanguageTest::testMethodInvocation":0.001,"Tests\\ExpressionLanguageTest::testExpressionString":0,"Tests\\ExpressionLanguageTest::testIsDeferred":0,"Tests\\ExpressionLanguageTest::testGetExpectedType":0,"Tests\\ExpressionLanguageTest::testGetType":0,"Tests\\JuelEngineTest::testJuelEngineManagerWithVariable":0.002,"Tests\\JuelEngineTest::testJuelEngineManagerWithFunction":0.002,"Tests\\LuaEngineTest::testLuaScript":0,"Tests\\JuelEngineTest::testOgnlSyntaxInJuelExpression":0.005}} \ No newline at end of file diff --git a/composer.json b/composer.json index d8c435c..2ea07ed 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,9 @@ }, "require": { "php": "^7.4 || ^8.0", - "bingo-soft/el": "^1.0", - "bingo-soft/juel": "^1.0" + "bingo-soft/el": "^1.1", + "bingo-soft/juel": "^1.2", + "bingo-soft/util": "^1.3" }, "require-dev": { "doctrine/coding-standard": "*", diff --git a/src/AbstractScriptEngine.php b/src/AbstractScriptEngine.php index 9b3c4d2..d91e1fb 100644 --- a/src/AbstractScriptEngine.php +++ b/src/AbstractScriptEngine.php @@ -107,7 +107,7 @@ public function put(string $key, $value): void { $nn = $this->getBindings(ScriptContextInterface::ENGINE_SCOPE); if ($nn !== null) { - $nn->put($key, $value); + $nn->put($key, $value); } } diff --git a/src/Engine/Juel/JuelScriptEngine.php b/src/Engine/Juel/JuelScriptEngine.php index c7aeb0a..269a12e 100644 --- a/src/Engine/Juel/JuelScriptEngine.php +++ b/src/Engine/Juel/JuelScriptEngine.php @@ -27,6 +27,7 @@ SimpleBindings, SimpleScriptContext }; +use Util\Reflection\MetaObject; class JuelScriptEngine extends AbstractScriptEngine { @@ -71,10 +72,20 @@ public function createBindings(): BindingsInterface return new SimpleBindings(); } + public function put(string $key, $value): void + { + parent::put($key, $value); + if ($value instanceof MetaObject) { + $context = $this->createElContext($this->context); + $context->getELResolver()->setValue($context, null, $key, $value); + } + } + public function evaluateExpression(ValueExpression $expr, ScriptContextInterface $ctx) { try { - return $expr->getValue($this->createElContext($ctx)); + $context = $this->createElContext($ctx); + return $expr->getValue($context); } catch (ELException $elexp) { throw new ScriptException($elexp); } diff --git a/tests/JuelEngineTest.php b/tests/JuelEngineTest.php index 5f4ec40..0c9562b 100644 --- a/tests/JuelEngineTest.php +++ b/tests/JuelEngineTest.php @@ -15,6 +15,7 @@ ExpressionFactoryImpl, SimpleContext }; +use Util\Reflection\MetaObject; class JuelEngineTest extends TestCase { @@ -63,4 +64,18 @@ public function bar(): int $this->assertEquals(3.23, $engine->eval('${simple.propFloat + 2}')); $this->assertEquals(34, $engine->eval('${simple.bar() + simple.foo()}')); } + + public function testOgnlSyntaxInJuelExpression(): void + { + $rich1 = new RichType(); + $meta1 = new MetaObject($rich1); + $meta1->setValue("richType.richType.richField", 10); + + + $manager = new ScriptEngineManager(); + $engine = $manager->getEngineByName("juel"); + $engine->put("parameterObject", $meta1); + + $this->assertEquals(21, $engine->eval('${richType.richType.richField + 11}')); + } } diff --git a/tests/RichType.php b/tests/RichType.php new file mode 100644 index 0000000..a08f07c --- /dev/null +++ b/tests/RichType.php @@ -0,0 +1,52 @@ +richType; + } + + public function setRichType(RichType $richType): void + { + $this->richType = $richType; + } + + public function getRichProperty(): string + { + return $this->richProperty; + } + + public function setRichProperty(string $richProperty): void + { + $this->richProperty = $richProperty; + } + + public function getRichList(): array + { + return $this->richList; + } + + public function setRichList(array $richList): void + { + $this->richList = $richList; + } + + public function getRichMap(): array + { + return $this->richMap; + } + + public function setRichMap(array $richMap): void + { + $this->richMap = $richMap; + } +}