File modules/dsl/ast/DslProperty.class.php

Last commit: Tue Jul 19 00:10:00 2022 +0200	Jan Dankert	New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper.
1 <?php 2 3 namespace dsl\ast; 4 5 use cms\generator\dsl\DslObject; 6 use dsl\context\Scriptable; 7 use dsl\DslRuntimeException; 8 use dsl\executor\DslInterpreter; 9 use dsl\standard\Data; 10 use dsl\standard\NumberInstance; 11 use dsl\standard\ArrayInstance; 12 use dsl\standard\StringInstance; 13 14 class DslProperty implements DslStatement 15 { 16 public $variable; 17 public $property; 18 19 /** 20 * DslProperty constructor. 21 * @param $variable 22 * @param $property 23 */ 24 public function __construct($variable, $property) 25 { 26 $this->variable = $variable; 27 $this->property = $property; 28 } 29 30 31 /** 32 * @param array $context 33 * @return mixed 34 * @throws DslRuntimeException 35 */ 36 public function execute( & $context ) { 37 38 $object = $this->variable->execute( $context ); 39 40 if ( is_object( $object ) ) { 41 42 if ( $object instanceof Data ) { 43 $objectContext = $object->getData(); 44 } 45 else { 46 47 // object attributes 48 $objectContext = get_object_vars( $object ); 49 50 //if ( $object instanceof StandardArray ) { 51 // foreach( $object->getInternalValue() as $key=> $value ) 52 // $objectContext[$key] = $value; 53 //} 54 55 // copy object methods to the object context to make them callable. 56 foreach( get_class_methods( $object ) as $method ) { 57 $objectContext[ $method ] = function() use ($method, $object) { 58 59 // For Security: Do not expose all available objects, they must implement a marker interface. 60 if ( DslInterpreter::isSecure() && ! $object instanceof Scriptable ) 61 throw new DslRuntimeException('Object '.get_class($object).' is not marked as scriptable and therefore not available in secure mode'); 62 63 return call_user_func_array( array($object,$method),func_get_args() ); 64 }; 65 } 66 } 67 } 68 else { 69 $objectContext = DslExpression::convertValueToStandardObject($object); 70 } 71 72 $prop = $this->property->execute( $objectContext ); 73 74 return $prop; 75 } 76 77 public function parse($tokens) 78 { 79 } 80 }
Download modules/dsl/ast/DslProperty.class.php
History Tue, 19 Jul 2022 00:10:00 +0200 Jan Dankert New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper. Fri, 1 Jul 2022 19:30:30 +0200 Jan Dankert New: Data Object for accessing data trees Fri, 1 Jul 2022 18:09:05 +0200 Jan Dankert New: Bugfixes and much more string and array functions for the DSL. Mon, 27 Jun 2022 01:11:02 +0200 Jan Dankert New: Secure Flag for Script Interpreter which is enabled by default. Mon, 27 Jun 2022 00:40:42 +0200 Jan Dankert New: Marker interface 'Scriptable', Proxy class for MQTT, help() method in Scripts. Tue, 31 May 2022 00:30:18 +0200 Jan Dankert New: DSL with support for parameterless functions. Sun, 29 May 2022 16:56:40 +0200 Jan Dankert New: DSL with support for functions with return values, full arithmetic, object properties