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