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 | 24 | public static function normalizeRepositoryUrl($url) |
|
163 | |||
164 | /** |
||
165 | * Return an object repository by URL |
||
166 | * |
||
167 | * If a repository URL hasn't been pre-registered, the method tries to perform an adhoc registration |
||
168 | * based on the URL given. |
||
169 | * The repository URL may be local or remote, relative or absolute, with Apparat or HTTP scheme. |
||
170 | * |
||
171 | * @param string|ObjectUrl $url Repository URL |
||
172 | * @return \Apparat\Object\Domain\Repository\Repository Object repository |
||
173 | * @throws InvalidArgumentException If the repository URL is invalid |
||
174 | * @throws InvalidArgumentException If the repository URL is unknown |
||
175 | */ |
||
176 | 10 | public function get($url) |
|
191 | |||
192 | /** |
||
193 | * Test whether a repository URL registered or can be auto-connected |
||
194 | * |
||
195 | * @param string $url Repository URL |
||
196 | * @return bool Repository is connected |
||
197 | */ |
||
198 | 10 | protected function connected($url) |
|
208 | |||
209 | /** |
||
210 | * Test whether a repository URL is registered |
||
211 | * |
||
212 | * @param string|ObjectUrl $url Repository URL |
||
213 | * @return bool Repository URL is registered |
||
214 | */ |
||
215 | 5 | public function isRegistered($url) |
|
220 | |||
221 | /** |
||
222 | * Return the adapter strategy factory |
||
223 | * |
||
224 | * @return AdapterStrategyFactoryInterface Adapter strategy factory |
||
225 | */ |
||
226 | 10 | public function getAdapterStrategyFactory() |
|
230 | |||
231 | /** |
||
232 | * Return the object manager |
||
233 | * |
||
234 | * @return ManagerInterface Object manager |
||
235 | */ |
||
236 | 4 | public function getObjectManager() |
|
240 | |||
241 | /******************************************************************************* |
||
242 | * PRIVATE METHODS |
||
243 | *******************************************************************************/ |
||
244 | |||
245 | /** |
||
246 | * Enable repository auto-connections |
||
247 | * |
||
248 | * If the method is called without any arguments it will just return the current auto-connection state. |
||
249 | * |
||
250 | * @param null|boolean $autoConnect Enable / disable auto-connections |
||
251 | * @return bool Status of repository auto-connection |
||
252 | */ |
||
253 | 9 | public function useAutoConnect($autoConnect = null) |
|
260 | } |
||
261 |