FEATURE: move widget and template dir installation into middleware, optimize middleware groups
This commit is contained in:
@@ -28,6 +28,10 @@ class TemplateRegistrator
|
||||
* @var int ID of module
|
||||
*/
|
||||
protected $moduleId;
|
||||
/**
|
||||
* @var array list of all registered template paths
|
||||
*/
|
||||
protected $paths = [];
|
||||
|
||||
/**
|
||||
* Set base path
|
||||
@@ -80,24 +84,39 @@ class TemplateRegistrator
|
||||
* Registers new template path.
|
||||
* This method registeres given path itself with all subdirectories
|
||||
*
|
||||
* @param $baseDirectory
|
||||
* @param string $path path relatively to root of the project
|
||||
* @param string $name human readable identification of given template path
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function register($path, $name)
|
||||
public function register($baseDirectory, $path, $name)
|
||||
{
|
||||
// check if base directory was set
|
||||
if (!$this->baseDirectory || !is_dir($this->baseDirectory)) {
|
||||
throw new \Exception('Set $baseDirectory before registering template path.');
|
||||
$this->paths[] = [
|
||||
'namespace' => $this->namespace,
|
||||
'moduleId' => $this->moduleId,
|
||||
'baseDirectory' => $baseDirectory,
|
||||
'path' => $this->baseDirectory . DIRECTORY_SEPARATOR . $path,
|
||||
'name' => $name
|
||||
];
|
||||
$this->unsetNamespace();
|
||||
}
|
||||
|
||||
public function saveTemplates()
|
||||
{
|
||||
if (!is_array($this->paths) || empty($this->paths)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->registeredPath = $this->baseDirectory . DIRECTORY_SEPARATOR . $path;
|
||||
foreach ($this->paths as $path) {
|
||||
$this->setNamespace($path['namespace']);
|
||||
$this->setModuleId($path['moduleId']);
|
||||
$this->setBaseDirectory($path['baseDirectory']);
|
||||
|
||||
// register path
|
||||
$this->registerPath($this->registeredPath, $name);
|
||||
|
||||
$this->unsetNamespace();
|
||||
$this->registeredPath = $this->baseDirectory . DIRECTORY_SEPARATOR . $path['path'];
|
||||
// register path
|
||||
$this->registerPath($this->registeredPath, $path['name']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +165,7 @@ class TemplateRegistrator
|
||||
Template::ASSETS_DIRECTORY,
|
||||
Template::MODULES_DIRECTORY
|
||||
];
|
||||
|
||||
|
||||
if (in_array($dirName, $ignoredDirectories)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user