File dsl/ast/DslVariable.class.php
Last commit: Tue Jul 19 00:10:39 2022 +0200 Jan Dankert Fetched from upstream.
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 }
Downloaddsl/ast/DslVariable.class.php
History Tue, 19 Jul 2022 00:10:39 +0200 Jan Dankert Fetched from upstream. Mon, 27 Jun 2022 00:41:50 +0200 Jan Dankert Fetched from upstream. Mon, 6 Jun 2022 14:06:46 +0200 Jan Dankert First commit after fetching from upstream repo.