Skip to content

Commit

Permalink
Dev: allow infinite inheritance on template
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Oct 18, 2017
1 parent eb067f2 commit 87d831a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
18 changes: 16 additions & 2 deletions application/models/TemplateConfiguration.php
Expand Up @@ -583,15 +583,29 @@ protected function setMotherTemplates()
}
}

protected function getTemplateForPath($oRTemplate, $sPath )
{
while (empty($oRTemplate->template->$sPath)){
$oMotherTemplate = $oRTemplate->oMotherTemplate;
if(!($oMotherTemplate instanceof TemplateConfiguration)){
throw new Exception("can't find a template for '$sPath' path !");
break;
}
$oRTemplate = $oMotherTemplate;
}
return $oRTemplate;
}

/**
* Set the default configuration values for the template, and use the motherTemplate value if needed
*/
protected function setThisTemplate()
{
// Mandtory setting in config XML (can be not set in inheritance tree, but must be set in mother template (void value is still a setting))
$this->apiVersion = (!empty($this->template->api_version))? $this->template->api_version : $this->oMotherTemplate->apiVersion;
$this->viewPath = (!empty($this->template->view_folder)) ? $this->path.DIRECTORY_SEPARATOR.$this->template->view_folder.DIRECTORY_SEPARATOR : $this->path.DIRECTORY_SEPARATOR.$this->oMotherTemplate->view_folder.DIRECTORY_SEPARATOR;
$this->filesPath = (!empty($this->template->files_folder)) ? $this->path.DIRECTORY_SEPARATOR.$this->template->files_folder.DIRECTORY_SEPARATOR : $this->path.DIRECTORY_SEPARATOR.$this->oMotherTemplate->file_folder.DIRECTORY_SEPARATOR;

$this->viewPath = $this->path.DIRECTORY_SEPARATOR.$this->getTemplateForPath($this, 'view_folder')->template->view_folder.DIRECTORY_SEPARATOR;
$this->filesPath = $this->path.DIRECTORY_SEPARATOR.$this->getTemplateForPath($this, 'files_folder')->template->files_folder.DIRECTORY_SEPARATOR ;

// Options are optional
$this->setOptions();
Expand Down
34 changes: 26 additions & 8 deletions application/models/TemplateManifest.php
Expand Up @@ -371,7 +371,10 @@ public static function deleteFilesAndEngineInDom($oNewManifest)
$aNodesToDelete[] = $oConfig->getElementsByTagName('engine')->item(0);

foreach($aNodesToDelete as $node){
$oConfig->removeChild($node);
// If extended template already extend another template, it will not have those nodes
if (is_a( $node, 'DOMNode')){
$oConfig->removeChild($node);
}
}
}

Expand Down Expand Up @@ -670,17 +673,32 @@ protected function setMotherTemplates()
}
}

protected function getTemplateForPath($oRTemplate, $sPath )
{
while (empty($oRTemplate->config->xpath($sPath))){
$oMotherTemplate = $oRTemplate->oMotherTemplate;
if(!($oMotherTemplate instanceof TemplateConfiguration)){
throw new Exception("can't find a template for '$sPath' xpath !");
break;
}
$oRTemplate = $oMotherTemplate;
}
return $oRTemplate;
}

/**
* Set the default configuration values for the template, and use the motherTemplate value if needed
*/
protected function setThisTemplate()
{
// Mandtory setting in config XML (can be not set in inheritance tree, but must be set in mother template (void value is still a setting))
$this->apiVersion = (isset($this->config->metadatas->apiVersion)) ? $this->config->metadatas->apiVersion : (isset($this->oMotherTemplate->apiVersion) ? $this->oMotherTemplate->apiVersion : null);
$this->viewPath = (!empty($this->config->xpath("//viewdirectory"))) ? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->viewdirectory.DIRECTORY_SEPARATOR : $this->path.DIRECTORY_SEPARATOR.$this->oMotherTemplate->config->engine->viewdirectory.DIRECTORY_SEPARATOR;
$this->filesPath = (!empty($this->config->xpath("//filesdirectory"))) ? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->filesdirectory.DIRECTORY_SEPARATOR : $this->path.DIRECTORY_SEPARATOR.$this->oMotherTemplate->config->engine->filesdirectory.DIRECTORY_SEPARATOR;
$this->sFilesDirectory = (!empty($this->config->xpath("//filesdirectory"))) ? $this->config->engine->filesdirectory : $this->oMotherTemplate->sFilesDirectory;
$this->templateEditor = (!empty($this->config->xpath("//template_editor"))) ? $this->config->engine->template_editor : $this->oMotherTemplate->templateEditor;
$this->apiVersion = (isset($this->config->metadatas->apiVersion)) ? $this->config->metadatas->apiVersion : (isset($this->oMotherTemplate->apiVersion) ? $this->oMotherTemplate->apiVersion : null);


$this->viewPath = $this->path.DIRECTORY_SEPARATOR.$this->getTemplateForPath($this, '//viewdirectory')->config->engine->viewdirectory.DIRECTORY_SEPARATOR;
$this->filesPath = $this->path.DIRECTORY_SEPARATOR.$this->getTemplateForPath($this, '//filesdirectory')->config->engine->filesdirectory.DIRECTORY_SEPARATOR;
$this->sFilesDirectory = $this->filesPath; // TODO: remove doublon
$this->templateEditor = $this->getTemplateForPath($this, '//template_editor')->config->engine->template_editor;

// Options are optional
if (!empty($this->config->xpath("//options"))){
Expand All @@ -693,8 +711,8 @@ protected function setThisTemplate()
}

// Not mandatory (use package dependances)
$this->cssFramework = (!empty($this->config->xpath("//cssframework"))) ? $this->config->engine->cssframework : '';
$this->packages = (!empty($this->config->xpath("//packages"))) ? $this->config->engine->packages : array();
$this->cssFramework = (!empty($this->config->xpath("//cssframework"))) ? $this->config->engine->cssframework: '';
$this->packages = (!empty($this->config->xpath("//packages"))) ? $this->config->engine->packages: array();

// Add depend package according to packages
$this->depends = array_merge($this->depends, $this->getDependsPackages($this));
Expand Down

0 comments on commit 87d831a

Please sign in to comment.