File modules/cms/generator/dsl/CMSDslInterpreter.class.php
Last commit: Fri Feb 17 02:02:18 2023 +0100 Jan Dankert Refactoring: Script-context should be the same in all environments; New: DslPdf for creating PDF with scriptbox ;)
1 <?php 2 3 namespace cms\generator\dsl; 4 5 use cms\generator\BaseContext; 6 use cms\generator\PageContext; 7 use cms\model\BaseObject; 8 use dsl\context\BaseScriptableObject; 9 use dsl\executor\DslInterpreter; 10 11 class CMSDslInterpreter extends DslInterpreter 12 { 13 public function __construct() 14 { 15 parent::__construct( DslInterpreter::FLAG_THROW_ERROR + DslInterpreter::FLAG_SECURE ); 16 17 18 $this->addContext( [ 19 'console' => new DslConsole(), 20 'cms' => new DslCms(), 21 'http' => new DslHttp(), 22 'json' => new DslJson(), 23 'Pdf' => function() { return new DslPdf(); }, 24 'Mqtt' => new class extends BaseScriptableObject { 25 public static function open( $url,$user,$password ) { 26 return new DslMqtt( $url,$user,$password ); 27 } 28 } 29 ]); 30 } 31 32 /** 33 * @param $pageContext PageContext 34 * @return void 35 * @throws \util\exception\ObjectNotFoundException 36 */ 37 public function setPageContext( $pageContext ) { 38 39 $this->addContext( [ 40 'page' => new DslObject( (new BaseObject($pageContext->objectId))->load() ), 41 'context' => new DslPageContext( $pageContext ), 42 'project' => new DslProject( (new BaseObject($pageContext->objectId))->load()->getProject() ), 43 ]); 44 } 45 46 /** 47 * @param $context BaseContext 48 * @return void 49 * @throws \util\exception\ObjectNotFoundException 50 */ 51 public function setContext( $context ) { 52 53 $this->addContext( [ 54 'object' => new DslObject( (new BaseObject($context->getObjectId()))->load() ), 55 'project' => new DslProject( (new BaseObject($context->getObjectId()))->load()->getProject() ), 56 ]); 57 } 58 59 60 public function setValue( $value ) { 61 62 $this->addContext( [ 63 'value' => $value, 64 ]); 65 } 66 }
Downloadmodules/cms/generator/dsl/CMSDslInterpreter.class.php
History Fri, 17 Feb 2023 02:02:18 +0100 Jan Dankert Refactoring: Script-context should be the same in all environments; New: DslPdf for creating PDF with scriptbox ;)