1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace TYPO3\PharStreamWrapper; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under the terms |
9
|
|
|
* of the MIT License (MIT). For the full copyright and license information, |
10
|
|
|
* please read the LICENSE file that was distributed with this source code. |
11
|
|
|
* |
12
|
|
|
* The TYPO3 project - inspiring people to share! |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
use TYPO3\PharStreamWrapper\Resolver\BaseNameResolver; |
16
|
|
|
|
17
|
|
|
class Manager implements Assertable, Resolvable |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var self |
21
|
|
|
*/ |
22
|
|
|
private static $instance; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Behavior |
26
|
|
|
*/ |
27
|
|
|
private $behavior; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Resolvable |
31
|
|
|
*/ |
32
|
|
|
private $resolver; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Behavior $behaviour |
36
|
|
|
* @param Resolvable $resolver |
37
|
|
|
* @return self |
38
|
|
|
*/ |
39
|
|
|
public static function initialize(Behavior $behaviour, Resolvable $resolver = null): self |
40
|
|
|
{ |
41
|
|
|
if (self::$instance === null) { |
42
|
|
|
self::$instance = new self($behaviour, $resolver); |
43
|
|
|
return self::$instance; |
44
|
|
|
} |
45
|
|
|
throw new \LogicException( |
46
|
|
|
'Manager can only be initialized once', |
47
|
|
|
1535189871 |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return self |
53
|
|
|
*/ |
54
|
|
|
public static function instance(): self |
55
|
|
|
{ |
56
|
|
|
if (self::$instance !== null) { |
57
|
|
|
return self::$instance; |
58
|
|
|
} |
59
|
|
|
throw new \LogicException( |
60
|
|
|
'Manager needs to be initialized first', |
61
|
|
|
1535189872 |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
public static function destroy(): bool |
69
|
|
|
{ |
70
|
|
|
if (self::$instance === null) { |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
self::$instance = null; |
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Behavior $behaviour |
79
|
|
|
* @param Resolvable $resolver |
80
|
|
|
*/ |
81
|
|
|
private function __construct(Behavior $behaviour, Resolvable $resolver = null) |
82
|
|
|
{ |
83
|
|
|
$this->behavior = $behaviour; |
84
|
|
|
$this->resolver = $resolver ?? new BaseNameResolver(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $path |
89
|
|
|
* @param string $command |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
public function assert(string $path, string $command): bool |
93
|
|
|
{ |
94
|
|
|
return $this->behavior->assert($path, $command); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $path |
99
|
|
|
* @param null|int $flags |
100
|
|
|
* @return string|null |
101
|
|
|
*/ |
102
|
|
|
public function resolveBaseName(string $path, int $flags = null) |
103
|
|
|
{ |
104
|
|
|
return $this->resolver->resolveBaseName($path, $flags); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|