File dsl/ast/DslFor.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\DslRuntimeException; 6 use dsl\DslToken; 7 use dsl\standard\ArrayInstance; 8 9 class DslFor implements DslStatement 10 { 11 private $name; 12 private $list; 13 private $statements; 14 15 /** 16 * DslFor constructor. 17 * 18 * @param $name String 19 * @param $list DslToken[] 20 * @param $statements DslToken[] 21 */ 22 public function __construct($name, $list, $statements) 23 { 24 $this->name = $name; 25 $this->list = new DslExpression( $list ); 26 $this->statements = new DslStatementList( $statements ); 27 } 28 29 30 public function execute( & $context ) { 31 32 $list = $this->list->execute( $context ); 33 34 if ( ! $list instanceof ArrayInstance ) 35 throw new DslRuntimeException('for value is not an array'); 36 37 $copiedContext = $context; 38 foreach( $list->getInternalValue() as $loopVar ) { 39 40 // copy loop var to current loop context 41 $copiedContext[ $this->name ] = $loopVar; 42 43 // Execute "for" block 44 $this->statements->execute( $copiedContext ); 45 } 46 } 47 48 public function parse($tokens) 49 { 50 } 51 }
Downloaddsl/ast/DslFor.class.php
History Tue, 19 Jul 2022 00:10:39 +0200 Jan Dankert Fetched from upstream. Mon, 6 Jun 2022 14:06:46 +0200 Jan Dankert First commit after fetching from upstream repo.