-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUploaderPool.php
54 lines (50 loc) · 1.37 KB
/
UploaderPool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Vuefront\Brands\Model;
use Magento\Framework\ObjectManagerInterface;
class UploaderPool
{
/**
* @var ObjectManagerInterface
*/
public $objectManager;
/**
* @var array
*/
public $uploaders;
/**
* @param ObjectManagerInterface $objectManager
* @param array $uploaders
*/
public function __construct(
ObjectManagerInterface $objectManager,
array $uploaders = []
) {
$this->objectManager = $objectManager;
$this->uploaders = $uploaders;
}
/**
* Get Uploader
*
* @param string $type
* @return Uploader
* @throws \Exception
*/
public function getUploader($type)
{
if (!isset($this->uploaders[$type])) {
throw new \Magento\Framework\Exception\LocalizedException(
__("Uploader not found for type: ".$type)
);
}
if (!is_object($this->uploaders[$type])) {
$this->uploaders[$type] = $this->objectManager->create($this->uploaders[$type]);
}
$uploader = $this->uploaders[$type];
if (!($uploader instanceof Uploader)) {
throw new \Magento\Framework\Exception\LocalizedException(
__("Uploader for type {$type} not instance of ". Uploader::class)
);
}
return $uploader;
}
}