File modules/cms/generator/dsl/DslPageContext.class.php
Last commit: Mon Jun 27 00:40:42 2022 +0200 Jan Dankert New: Marker interface 'Scriptable', Proxy class for MQTT, help() method in Scripts.
1 <?php 2 3 namespace cms\generator\dsl; 4 5 use cms\generator\PageContext; 6 use cms\model\BaseObject; 7 use cms\model\Language; 8 use cms\model\Model; 9 use dsl\context\BaseScriptableObject; 10 use dsl\DslRuntimeException; 11 12 class DslPageContext extends BaseScriptableObject 13 { 14 private $pageContext; 15 16 /** 17 * DslPageContext constructor. 18 * @param $pageContext PageContext 19 */ 20 public function __construct( $pageContext ) { 21 22 $this->pageContext = clone $pageContext; // the original must no be changed 23 24 $this->language = ( new Language( $pageContext->languageId ) )->load()->getName(); 25 $this->model = ( new Model ( $pageContext->modelId ) )->load()->getName(); 26 } 27 28 29 /** 30 * Language name. 31 * @var string 32 */ 33 public $language; 34 35 36 /** 37 * Model name. 38 * @var string 39 */ 40 public $model; 41 42 43 protected function getProject() { 44 return (new BaseObject($this->pageContext->sourceObjectId))->load()->getProject(); 45 } 46 47 public function setLanguage( $name ) { 48 if ( $languageId = array_search( $name,$this->getProject()->getLanguages() ) ) 49 $this->pageContext->languageId = $languageId; 50 else 51 throw new DslRuntimeException("language with name '".$this->language."' does not exist."); 52 53 } 54 55 56 public function setModel( $name ) { 57 if ( $modelId = array_search( $name,$this->getProject()->getModels() ) ) 58 $this->pageContext->modelId = $modelId; 59 else 60 throw new DslRuntimeException("model with name '".$this->model."' does not exist."); 61 } 62 63 64 /** 65 * Creates a link to an object. 66 * 67 * @param $object DslObject 68 */ 69 public function linkTo( $object ) { 70 71 $from = (new BaseObject( $this->pageContext->sourceObjectId ))->load(); 72 $to = (new BaseObject( $object->id ))->load(); 73 return $this->pageContext->getLinkScheme()->linkToObject( $from, $to ); 74 } 75 76 }
Downloadmodules/cms/generator/dsl/DslPageContext.class.php
History Mon, 27 Jun 2022 00:40:42 +0200 Jan Dankert New: Marker interface 'Scriptable', Proxy class for MQTT, help() method in Scripts. Sat, 25 Jun 2022 14:26:33 +0200 Jan Dankert New: Many Enhancements for the internal script language: More access to the data structure of pages, folders, templates, ...