public function validate() { // check if template exists $templateSettings = TemplateSettings::get(); if (!$templateSettings->exists($this->template)) { throw new SalicSettingsException("Template '" . $this->template . "' not found", $this->file, $templateSettings->templates); } // create empty areas that are not present $myTemplate = $templateSettings->data($this->template); $templateAreas = $myTemplate->areas; foreach ($templateAreas as $area) { if (!array_key_exists($area, $this->areas)) { $this->areas[$area] = []; } } // check blocks list foreach ($this->areas as $areaKey => &$blocks) { // check if area exists in template if (!in_array($areaKey, $templateAreas)) { throw new SalicSettingsException("Area '{$areaKey}' doesn't exist in the template", $this->file . self::fis . 'areas'); } $blockKeys = array(); // for duplicate checking foreach ($blocks as $i => &$block) { // check all blocks $block['key'] = self::getString('key', $block, null, "areas>{$areaKey}>{$i}"); // use index, blockKey is not known yet // check for duplicate keys $blockKey = $block['key']; if (in_array($blockKey, $blockKeys)) { throw new SalicSettingsException("Duplicate blockKey '{$blockKey}'", $this->file . self::fis . "areas>{$areaKey}"); } $blockKeys[] = $blockKey; $block['type'] = self::getString('type', $block, null, "areas>{$areaKey}>{$blockKey}"); // eg. 'templates.json:areas>main>intro' if (!BlockSettings::exists2($block['type'])) { throw new SalicSettingsException("Block '{$block['type']}' is not defined in blocks.json", $this->file . self::fis . "areas>{$areaKey}>{$blockKey}", BlockSettings::get()->blocktypes); } $blockSettings = BlockSettings::data2($block['type']); if ($blockSettings->subblocks === true) { // if the blocktype has variable subblocks, check if the count is given $block['subblock-count'] = self::getInt('subblock-count', $block, 1, "areas>{$areaKey}>{$blockKey}"); } // set to parsed value, TODO: move stuff like this to parseFromJson() $block['vars'] = self::getDict('vars', $block, [], "areas>{$areaKey}>{$blockKey}"); } } // check variables list $templateVars = $myTemplate->variables; foreach ($this->variables as $var => $value) { // check if variable exists in template if (!array_key_exists($var, $templateVars)) { throw new SalicSettingsException("Variable '{$var}' doesn't exist in the template", $this->file . self::fis . 'variables'); } //TODO: variable value type checking } }