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\PharInvocationResolver; |
16
|
|
|
use TYPO3\PharStreamWrapper\Resolver\PharInvocation; |
17
|
|
|
use TYPO3\PharStreamWrapper\Resolver\PharInvocationCollection; |
18
|
|
|
|
19
|
|
|
class Manager |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var self |
23
|
|
|
*/ |
24
|
|
|
private static $instance; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var Behavior |
28
|
|
|
*/ |
29
|
|
|
private $behavior; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Resolvable |
33
|
|
|
*/ |
34
|
|
|
private $resolver; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Collectable |
38
|
|
|
*/ |
39
|
|
|
private $collection; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Behavior $behaviour |
43
|
|
|
* @param Resolvable $resolver |
44
|
|
|
* @param Collectable $collection |
45
|
|
|
* @return self |
46
|
|
|
*/ |
47
|
|
|
public static function initialize( |
48
|
|
|
Behavior $behaviour, |
49
|
|
|
Resolvable $resolver = null, |
50
|
|
|
Collectable $collection = null |
51
|
|
|
): self { |
52
|
|
|
if (self::$instance === null) { |
53
|
|
|
self::$instance = new self($behaviour, $resolver, $collection); |
54
|
|
|
return self::$instance; |
55
|
|
|
} |
56
|
|
|
throw new \LogicException( |
57
|
|
|
'Manager can only be initialized once', |
58
|
|
|
1535189871 |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return self |
64
|
|
|
*/ |
65
|
|
|
public static function instance(): self |
66
|
|
|
{ |
67
|
|
|
if (self::$instance !== null) { |
68
|
|
|
return self::$instance; |
69
|
|
|
} |
70
|
|
|
throw new \LogicException( |
71
|
|
|
'Manager needs to be initialized first', |
72
|
|
|
1535189872 |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
|
|
public static function destroy(): bool |
80
|
|
|
{ |
81
|
|
|
if (self::$instance === null) { |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
self::$instance = null; |
85
|
|
|
return true; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param Behavior $behaviour |
90
|
|
|
* @param Resolvable $resolver |
91
|
|
|
* @param Collectable $collection |
92
|
|
|
*/ |
93
|
|
|
private function __construct( |
94
|
|
|
Behavior $behaviour, |
95
|
|
|
Resolvable $resolver = null, |
96
|
|
|
Collectable $collection = null |
97
|
|
|
) { |
98
|
|
|
$this->collection = $collection ?? new PharInvocationCollection(); |
99
|
|
|
$this->resolver = $resolver ?? new PharInvocationResolver(); |
100
|
|
|
$this->behavior = $behaviour; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $path |
105
|
|
|
* @param string $command |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function assert(string $path, string $command): bool |
109
|
|
|
{ |
110
|
|
|
return $this->behavior->assert($path, $command); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $path |
115
|
|
|
* @param null|int $flags |
116
|
|
|
* @return PharInvocation|null |
117
|
|
|
*/ |
118
|
|
|
public function resolve(string $path, int $flags = null) |
119
|
|
|
{ |
120
|
|
|
return $this->resolver->resolve($path, $flags); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return Collectable |
125
|
|
|
*/ |
126
|
|
|
public function getCollection(): Collectable |
127
|
|
|
{ |
128
|
|
|
return $this->collection; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|