Automation/app/Libraries/MyStorage/MangboardStorage.php
2024-09-16 11:46:18 +09:00

121 lines
3.9 KiB
PHP

<?php
namespace App\Libraries\MyStorage;
use App\Entities\Mangboard\UserEntity;
use App\Libraries\Mangboard\BoardLibrary;
use App\Libraries\Mangboard\BoardsLibrary;
use App\Libraries\Mangboard\FileLibrary;
use App\Libraries\Mangboard\ImageLibrary;
class MangboardStorage extends FileStorage
{
private $_boards_library = null;
private $_board_library = null;
private $_file_library = null;
private $_image_library = null;
private $_category = "";
private $_user_entity = null;
public function __construct(string $category, UserEntity $user_entity)
{
parent::__construct($category);
$this->_category = $category;
$this->_user_entity = $user_entity;
}
private function getCategory(): string
{
if ($this->_category == "") {
throw new \Exception("저장할 Category가 정의되지 않았습니다.");
}
return $this->_category;
}
private function getUserEntity(): UserEntity
{
if ($this->_user_entity === null) {
throw new \Exception("사용자정보가 없습니다.");
}
return $this->_user_entity;
}
final public function getBasePath(): string
{
return getenv("mangboard.uploads.path");
}
final public function getUploadPath(): string
{
return parent::getUploadPath() . DIRECTORY_SEPARATOR . $this->getBasePath();
}
final public function getUploadURL(): string
{
return sprintf("/wp-content/%s/%s/%s", parent::getUploadURL(), $this->getBasePath(), $this->getBasePath());
}
final public function getHTMLTag(string $content = ""): string
{
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
switch ($this->getOrintginType()) {
case "image":
$content = sprintf(
"<img src=\"%s/%s/%s\" alt=\"%s\">",
$this->getUploadURL(),
$this->getPath(),
$this->getOriginName(),
$this->getOriginName()
);
break;
case "video":
$content = sprintf(
"<video alt=\"%s\" controls autoplay>
<source src=\"%s/%s/%s\" type=\"%s\">
Your browser does not support the video tag.
</video>",
$this->getOriginName(),
$this->getUploadURL(),
$this->getPath(),
$this->getOriginName(),
$this->getMimeType(),
);
break;
}
log_message("debug", sprintf(
"\n--------%s--------\n%s\n--------------------\n",
__FUNCTION__,
$content
));
return $content;
}
private function getBoardsLibrary(): BoardsLibrary
{
if ($this->_boards_library === null) {
$this->_boards_library = new BoardsLibrary($this->getCategory(), $this->getUserEntity());
}
return $this->_boards_library;
}
final public function getBoardLibrary(): BoardLibrary
{
if ($this->_board_library === null) {
$this->_board_library = new BoardLibrary(
$this->getBoardsLibrary()->getEntity(),
$this->getUserEntity()
);
}
return $this->_board_library;
}
final public function getFileLibrary(): FileLibrary
{
if ($this->_file_library === null) {
$this->_file_library = new FileLibrary(
$this->getBoardsLibrary()->getEntity(),
$this->getUserEntity()
);
}
return $this->_file_library;
}
final public function getImageLibrary(): ImageLibrary
{
if ($this->_image_library === null) {
$this->_image_library = new ImageLibrary();
}
return $this->_image_library;
}
}