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

Last commit: Fri Jul 1 18:09:05 2022 +0200	Jan Dankert	New: Bugfixes and much more string and array functions for the DSL.
1 <?php 2 3 namespace dsl\ast; 4 5 use dsl\context\Scriptable; 6 use dsl\DslRuntimeException; 7 use dsl\executor\DslInterpreter; 8 9 class DslVariable implements DslStatement 10 { 11 public $name; 12 13 /** 14 * @param $name 15 */ 16 public function __construct($name) 17 { 18 $this->name = $name; 19 } 20 21 22 public function execute( & $context ) { 23 24 if ( is_object( $context) ) { 25 26 // copy object methods to the object context to make them callable. 27 $property = $this->name; 28 29 if ( property_exists( $context,$property ) ) { 30 31 return $context->$property; 32 } 33 34 if ( method_exists( $context,$this->name ) ) { 35 36 return function() use ($property, $context) { 37 38 // For Security: Do not expose all available objects, they must implement a marker interface. 39 if ( DslInterpreter::isSecure() && ! $context instanceof Scriptable ) 40 throw new DslRuntimeException('Object '.get_class($context).' is not marked as scriptable and therefore not available in secure mode'); 41 42 return call_user_func_array( array($context,$property),func_get_args() ); 43 }; 44 } 45 46 throw new DslRuntimeException('method or property \''.$property.'\' does not exist' ); 47 } 48 49 if ( ! array_key_exists( $this->name, $context ) ) 50 throw new DslRuntimeException('variable or property \''.$this->name.'\' does not exist'); 51 52 return $context[ $this->name ]; 53 } 54 55 public function parse($tokens) 56 { 57 } 58 }
Download modules/dsl/ast/DslVariable.class.php
History 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 00:40:42 +0200 Jan Dankert New: Marker interface 'Scriptable', Proxy class for MQTT, help() method in Scripts. Sat, 28 May 2022 18:00:13 +0200 Jan Dankert New: DSL with a much better syntax parsing and support for assignments, conditions, ...