Automation/app/Libraries/MyStorage/MyStorageFileLibrary.php
2024-09-05 17:22:34 +09:00

54 lines
1.4 KiB
PHP

<?php
namespace App\Libraries\MyStorage;
use App\Libraries\MyStorage\MyStorageLibrary;
class MyStorageFileLibrary extends MyStorageLibrary
{
private $_defaultPath = "";
private $_path = "";
private $_fileName = "";
private $_savePath = "";
public function __construct($defaultPath)
{
parent::__construct();
$this->_defaultPath = $defaultPath;
}
final public function getDefaultPath(): string
{
return $this->_defaultPath;
}
final public function getPath(): string
{
return $this->_path;
}
final public function setPath(string $path): void
{
$this->_path = $path;
}
final public function getFileName(): string
{
return $this->_fileName;
}
final public function setFileName(string $fileName): void
{
$this->_fileName = $fileName;
}
final public function save($content): bool
{
$fullPath = $this->getDefaultPath() . DIRECTORY_SEPARATOR . $this->getPath();
if (!is_dir($fullPath)) {
if (!mkdir($fullPath)) {
throw new \Exception("Make Directory Error:" . $fullPath);
}
}
$fileName = $fullPath . DIRECTORY_SEPARATOR . $this->getFileName();
log_message("debug", "download:SavePath-> " . $fileName);
return file_put_contents($fileName, $content);
}
}