41 lines
1006 B
PHP
41 lines
1006 B
PHP
<?php
|
|
|
|
namespace App\Classes\Traits;
|
|
|
|
use App\Classes\AttachmentsManager;
|
|
|
|
trait ManagesAttachments
|
|
{
|
|
private array $attachmentsManagers = [];
|
|
|
|
/**
|
|
* Register an attachments manager for specified filename
|
|
*/
|
|
private function registerAttachmentsManager(string $kind): AttachmentsManager
|
|
{
|
|
if (!array_key_exists($kind, $this->attachmentsManagers)) {
|
|
$this->attachmentsManagers[$kind] = new AttachmentsManager($kind, $this->dataDir, $this->disk);
|
|
}
|
|
|
|
return $this->attachmentsManagers[$kind];
|
|
}
|
|
|
|
/**
|
|
* Save all attachments files that needs to be
|
|
*/
|
|
private function saveAttachments()
|
|
{
|
|
foreach ($this->attachmentsManagers as $manager) {
|
|
$manager->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return an instance of attachments manager for specified kind of files
|
|
*/
|
|
public function attachments(string $kind): AttachmentsManager
|
|
{
|
|
return $this->registerAttachmentsManager($kind);
|
|
}
|
|
}
|