20240410#5

This commit is contained in:
User
2024-04-10 02:54:51 +03:00
parent 4ed91f096c
commit a576bf0638

View File

@@ -21,13 +21,13 @@ class Content implements TemplateInterface {
$this->{$resKey} = $resVal; $this->{$resKey} = $resVal;
} }
ContentData::$basePath = dirname(__DIR__, 4); ContentData::$basePath = dirname(__DIR__, 4);
ContentData::$template = ContentData::$basePath.'/'.$template; ContentData::$template = ContentData::$basePath.$template;
return $this; return $this;
} }
/** @inheritDoc */ /** @inheritDoc */
public function setSubtemplatePath(string $subtemplatePath = "") : TemplateInterface { public function setSubtemplatePath(string $subtemplatePath = "") : TemplateInterface {
ContentData::$subtemplatePath = ContentData::$basePath.'/'.$subtemplatePath; ContentData::$subtemplatePath = ContentData::$basePath.$subtemplatePath;
return $this; return $this;
} }
@@ -59,11 +59,11 @@ class Content implements TemplateInterface {
public function addSubtemplate(string $point, string $subtemplate, array $resource = []) : void { public function addSubtemplate(string $point, string $subtemplate, array $resource = []) : void {
if (empty(ContentData::$subtemplatePath))throw new AppError("SubtemplatePath is not defined"); if (empty(ContentData::$subtemplatePath))throw new AppError("SubtemplatePath is not defined");
if (empty($point)) throw new AppError("Empty point"); if (empty($point)) throw new AppError("Empty point");
if (empty($subtemplate) || !file_exists(ContentData::$subtemplatePath."/".$subtemplate)) throw new AppError(ContentData::$subtemplatePath."/".$subtemplate. " is not found"); if (empty($subtemplate) || !file_exists(ContentData::$subtemplatePath.$subtemplate)) throw new AppError(ContentData::$subtemplatePath.$subtemplate. " is not found");
foreach ($resource as $resKey => $resVal){ foreach ($resource as $resKey => $resVal){
$this->{$resKey} = $resVal; $this->{$resKey} = $resVal;
} }
ob_start(); include ContentData::$subtemplatePath."/".$subtemplate; ContentData::$content[$point][] = ob_get_contents(); ob_end_clean(); ob_start(); include ContentData::$subtemplatePath.$subtemplate; ContentData::$content[$point][] = ob_get_contents(); ob_end_clean();
} }
/** /**
@@ -81,8 +81,8 @@ class Content implements TemplateInterface {
foreach ($resource as $resKey => $resVal){ foreach ($resource as $resKey => $resVal){
$this->{$resKey} = $resVal; $this->{$resKey} = $resVal;
} }
if(empty($incFile) || !file_exists(ContentData::$subtemplatePath."/".$incFile)) throw new AppError("Empty inc file"); if(empty($incFile) || !file_exists(ContentData::$subtemplatePath.$incFile)) throw new AppError("Empty inc file");
ob_start(); include ContentData::$subtemplatePath."/".$incFile; $out = ob_get_contents(); ob_end_clean(); ob_start(); include ContentData::$subtemplatePath.$incFile; $out = ob_get_contents(); ob_end_clean();
return $out; return $out;
} }