From 45f4364c335f1f54c9dba6930fd09eac4e70f1d7 Mon Sep 17 00:00:00 2001 From: User Date: Wed, 10 Apr 2024 02:23:57 +0300 Subject: [PATCH] 20240410#1 --- src/Content.php | 73 +++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/src/Content.php b/src/Content.php index cbbaaa2..f36f70c 100644 --- a/src/Content.php +++ b/src/Content.php @@ -3,7 +3,6 @@ namespace Rmphp\Content; use Rmphp\Foundation\Exceptions\AppError; -use Rmphp\Foundation\Exceptions\AppException; use Rmphp\Foundation\TemplateInterface; class Content implements TemplateInterface { @@ -16,11 +15,7 @@ class Content implements TemplateInterface { if(!empty($template)) $this->setTemplate($template); } - /** - * @param string $template - * @param array $resource - * @return TemplateInterface - */ + /** @inheritDoc */ public function setTemplate(string $template, array $resource = []) : TemplateInterface { foreach ($resource as $resKey => $resVal){ $this->{$resKey} = $resVal; @@ -30,37 +25,28 @@ class Content implements TemplateInterface { return $this; } - /** - * @param string $subtemplatePath - * @return TemplateInterface - */ - public function setSubtemplePath(string $subtemplatePath) : TemplateInterface { + /** @inheritDoc */ + public function setSubtemplatePath(string $subtemplatePath = "") : TemplateInterface { ContentData::$subtemplatePath = ContentData::$basePath.'/'.$subtemplatePath; return $this; } - /** - * @return string - */ - public function getSubtemplePath(): string { + /** @inheritDoc */ + public function getSubtemplatePath(): string { return ContentData::$subtemplatePath; } /** - * @param string $point - * @param string $string - * @throws AppException + * @inheritDoc */ public function addValue(string $point, string $string) : void { - if (empty($point)) throw new AppException("Empty point"); - if (empty(ContentData::$subtemplatePath))throw new AppException("SubtemplatePath is not defined"); + if (empty($point)) throw new AppError("Empty point"); + if (empty(ContentData::$subtemplatePath))throw new AppError("SubtemplatePath is not defined"); ContentData::$content[$point][] = $string; } /** - * @param string $point - * @param string $string - * @throws AppException + * @inheritDoc */ public function setValue(string $point, string $string) : void { unset(ContentData::$content[$point]); @@ -68,60 +54,45 @@ class Content implements TemplateInterface { } /** - * @param string $point - * @param string $subTempl - * @param array $resource - * @throws AppException + * @inheritDoc */ - public function addSubtemple(string $point, string $subTempl, array $resource = []) : void { - if (empty(ContentData::$subtemplatePath))throw new AppException("SubtemplatePath is not defined"); - if (empty($point)) throw new AppException("Empty point"); - if (empty($subTempl) || !file_exists(ContentData::$subtemplatePath."/".$subTempl)) throw new AppException(ContentData::$subtemplatePath."/".$subTempl. " is not found"); + public function addSubtemplate(string $point, string $subtemplate, array $resource = []) : void { + if (empty(ContentData::$subtemplatePath))throw new AppError("SubtemplatePath is not defined"); + 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"); foreach ($resource as $resKey => $resVal){ $this->{$resKey} = $resVal; } - ob_start(); include ContentData::$subtemplatePath."/".$subTempl; ContentData::$content[$point][] = ob_get_contents(); ob_end_clean(); + ob_start(); include ContentData::$subtemplatePath."/".$subtemplate; ContentData::$content[$point][] = ob_get_contents(); ob_end_clean(); } /** - * @param string $point - * @param string $subTempl - * @param array $resource - * @throws AppException + * @inheritDoc */ - public function setSubtemple(string $point, string $subTempl, array $resource = []) : void { + public function setSubtemplate(string $point, string $subtemplate, array $resource = []) : void { unset(ContentData::$content[$point]); - $this->addSubtemple($point, $subTempl, $resource); + $this->addSubtemplate($point, $subtemplate, $resource); } /** - * @param string $incFile - * @param array $resource - * @return string - * @throws AppException + * @inheritDoc */ public function inc(string $incFile, array $resource = []) : string { foreach ($resource as $resKey => $resVal){ $this->{$resKey} = $resVal; } - if(empty($incFile) || !file_exists(ContentData::$subtemplatePath."/".$incFile)) throw new AppException("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(); return $out; } - /** - * @param string $point - * @return string - */ + /** @inheritDoc */ public function getPoint(string $point) : string { if (empty($point) || empty(ContentData::$content[$point])) return ""; return implode("", ContentData::$content[$point]); } - /** - * @return string - * @throws AppException - */ + /** @inheritDoc */ public function getResponse(): string { if (empty(ContentData::$template) || !file_exists(ContentData::$template)) throw new AppError("Invalid template file"); ob_start(); include ContentData::$template; $out = ob_get_contents(); ob_end_clean();