File dsl/ast/DslProperty.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 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 }
Downloaddsl/ast/DslProperty.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.