1 | <?php |
||
50 | class Service |
||
51 | { |
||
52 | /** |
||
53 | * Registered repositories |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $registry = []; |
||
58 | /** |
||
59 | * Repository auto-connector service |
||
60 | * |
||
61 | * @var AutoConnectorInterface |
||
62 | */ |
||
63 | protected $autoConnector = null; |
||
64 | /** |
||
65 | * Adapter strategy factory |
||
66 | * |
||
67 | * @var AdapterStrategyFactoryInterface |
||
68 | */ |
||
69 | protected $adapterStrategyFactory = null; |
||
70 | /** |
||
71 | * Object manager |
||
72 | * |
||
73 | * @var ManagerInterface |
||
74 | */ |
||
75 | protected $objectManager = null; |
||
76 | /** |
||
77 | * Auto-connect to repositories |
||
78 | * |
||
79 | * @var bool |
||
80 | */ |
||
81 | protected $autoConnectEnabled = true; |
||
82 | |||
83 | /******************************************************************************* |
||
84 | * PUBLIC METHODS |
||
85 | *******************************************************************************/ |
||
86 | |||
87 | /** |
||
88 | * Repository service constructor |
||
89 | * |
||
90 | * @param AutoConnectorInterface $autoConnector Auto-connector |
||
91 | * @param AdapterStrategyFactoryInterface $adapterStrategyFactory Adapter strategy factory |
||
92 | * @param ManagerInterface $objectManager Object manager |
||
93 | */ |
||
94 | public function __construct( |
||
103 | |||
104 | /** |
||
105 | * Pre-register a repository |
||
106 | * |
||
107 | * The purpose of repository pre-registration is to provide custom arguments (like a base |
||
108 | * directory or basic authentication credentials. |
||
109 | * The repository URL may be local or remote, relative or absolute, with Apparat or HTTP scheme. |
||
110 | * |
||
111 | * @param string|ObjectUrl $url Repository URL |
||
112 | * @param RepositoryInterface $repository Repository |
||
113 | */ |
||
114 | 6 | public function register($url, RepositoryInterface $repository) |
|
120 | |||
121 | /** |
||
122 | * Normalize a repository URL |
||
123 | * |
||
124 | * @param string|ObjectUrl $url Repository URL |
||
125 | * @return string Normalized repository URL |
||
126 | * @throws InvalidArgumentException If the repository URL is invalid |
||
127 | */ |
||
128 | 22 | public static function normalizeRepositoryUrl($url) |
|
164 | |||
165 | /** |
||
166 | * Return an object repository by URL |
||
167 | * |
||
168 | * If a repository URL hasn't been pre-registered, the method tries to perform an adhoc registration |
||
169 | * based on the URL given. |
||
170 | * The repository URL may be local or remote, relative or absolute, with Apparat or HTTP scheme. |
||
171 | * |
||
172 | * @param string|ObjectUrl $url Repository URL |
||
173 | * @return \Apparat\Object\Domain\Repository\Repository Object repository |
||
174 | * @throws InvalidArgumentException If the repository URL is invalid |
||
175 | * @throws InvalidArgumentException If the repository URL is unknown |
||
176 | */ |
||
177 | 9 | public function get($url) |
|
192 | |||
193 | /** |
||
194 | * Test whether a repository URL registered or can be auto-connected |
||
195 | * |
||
196 | * @param string $url Repository URL |
||
197 | * @return bool Repository is connected |
||
198 | */ |
||
199 | 9 | protected function connected($url) |
|
209 | |||
210 | /** |
||
211 | * Test whether a repository URL is registered |
||
212 | * |
||
213 | * @param string|ObjectUrl $url Repository URL |
||
214 | * @return bool Repository URL is registered |
||
215 | */ |
||
216 | 4 | public function isRegistered($url) |
|
221 | |||
222 | /** |
||
223 | * Return the adapter strategy factory |
||
224 | * |
||
225 | * @return AdapterStrategyFactoryInterface Adapter strategy factory |
||
226 | */ |
||
227 | 10 | public function getAdapterStrategyFactory() |
|
231 | |||
232 | /** |
||
233 | * Return the object manager |
||
234 | * |
||
235 | * @return ManagerInterface Object manager |
||
236 | */ |
||
237 | 3 | public function getObjectManager() |
|
241 | |||
242 | /******************************************************************************* |
||
243 | * PRIVATE METHODS |
||
244 | *******************************************************************************/ |
||
245 | |||
246 | /** |
||
247 | * Enable repository auto-connections |
||
248 | * |
||
249 | * If the method is called without any arguments it will just return the current auto-connection state. |
||
250 | * |
||
251 | * @param null|boolean $autoConnect Enable / disable auto-connections |
||
252 | * @return bool Status of repository auto-connection |
||
253 | */ |
||
254 | 7 | public function useAutoConnect($autoConnect = null) |
|
261 | } |
||
262 |