|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* BsbFlystem |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @see https://bushbaby.nl/ |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl) |
|
12
|
|
|
* @author Bas Kamer <[email protected]> |
|
13
|
|
|
* @license MIT |
|
14
|
|
|
* |
|
15
|
|
|
* @package bushbaby/flysystem |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace BsbFlysystem\Service; |
|
21
|
|
|
|
|
22
|
|
|
use BsbFlysystem\Exception\RuntimeException; |
|
23
|
|
|
use Laminas\ServiceManager\AbstractPluginManager; |
|
24
|
|
|
use Laminas\ServiceManager\Exception; |
|
25
|
|
|
use Laminas\ServiceManager\Factory\InvokableFactory; |
|
26
|
|
|
use League\Flysystem\AdapterInterface; |
|
27
|
|
|
|
|
28
|
|
|
class AdapterManager extends AbstractPluginManager |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $instanceOf = AdapterInterface::class; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
7 |
|
* @var bool |
|
37
|
|
|
*/ |
|
38
|
7 |
|
protected $shareByDefault = true; |
|
39
|
1 |
|
|
|
40
|
1 |
|
/** |
|
41
|
1 |
|
* @var bool |
|
42
|
1 |
|
*/ |
|
43
|
|
|
protected $sharedByDefault = true; |
|
44
|
|
|
|
|
45
|
7 |
|
/** |
|
46
|
|
|
* @var array |
|
47
|
1 |
|
*/ |
|
48
|
|
|
protected $factories = [ |
|
49
|
|
|
\League\Flysystem\Adapter\NullAdapter::class => InvokableFactory::class, |
|
50
|
1 |
|
'leagueflysystemadapternulladapter' => InvokableFactory::class, |
|
51
|
1 |
|
]; |
|
52
|
1 |
|
|
|
53
|
|
|
public function validate($instance): void |
|
54
|
1 |
|
{ |
|
55
|
|
View Code Duplication |
if (! $instance instanceof $this->instanceOf) { |
|
|
|
|
|
|
56
|
|
|
throw new Exception\InvalidServiceException(\sprintf('Invalid adapter "%s" created; not an instance of %s', \get_class($instance), $this->instanceOf)); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function validatePlugin($instance): void |
|
61
|
|
|
{ |
|
62
|
|
|
try { |
|
63
|
|
|
$this->validate($instance); |
|
64
|
|
|
} catch (Exception\InvalidServiceException $e) { |
|
65
|
|
|
throw new RuntimeException($e->getMessage(), $e->getCode(), $e); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.