1 | <?php |
||
51 | class Service |
||
52 | { |
||
53 | /** |
||
54 | * Registered repositories |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $registry = []; |
||
59 | /** |
||
60 | * Repository auto-connector service |
||
61 | * |
||
62 | * @var AutoConnectorInterface |
||
63 | */ |
||
64 | protected $autoConnector = null; |
||
65 | /** |
||
66 | * Adapter strategy factory |
||
67 | * |
||
68 | * @var AdapterStrategyFactoryInterface |
||
69 | */ |
||
70 | protected $adapterStrategyFactory = null; |
||
71 | /** |
||
72 | * Object manager |
||
73 | * |
||
74 | * @var ManagerInterface |
||
75 | */ |
||
76 | protected $objectManager = null; |
||
77 | /** |
||
78 | * Auto-connect to repositories |
||
79 | * |
||
80 | * @var bool |
||
81 | */ |
||
82 | protected $autoConnectEnabled = true; |
||
83 | |||
84 | /******************************************************************************* |
||
85 | * PUBLIC METHODS |
||
86 | *******************************************************************************/ |
||
87 | |||
88 | /** |
||
89 | * Repository service constructor |
||
90 | * |
||
91 | * @param AutoConnectorInterface $autoConnector Auto-connector |
||
92 | * @param AdapterStrategyFactoryInterface $adapterStrategyFactory Adapter strategy factory |
||
93 | * @param ManagerInterface $objectManager Object manager |
||
94 | */ |
||
95 | public function __construct( |
||
104 | |||
105 | /** |
||
106 | * Pre-register a repository |
||
107 | * |
||
108 | * The purpose of repository pre-registration is to provide custom arguments (like a base |
||
109 | * directory or basic authentication credentials. |
||
110 | * The repository URL may be local or remote, relative or absolute, with Apparat or HTTP scheme. |
||
111 | * |
||
112 | * @param string|Url $url Repository URL |
||
113 | * @param RepositoryInterface $repository Repository |
||
114 | */ |
||
115 | 6 | public function register($url, RepositoryInterface $repository) |
|
121 | |||
122 | /** |
||
123 | * Return an object repository by URL |
||
124 | * |
||
125 | * If a repository URL hasn't been pre-registered, the method tries to perform an adhoc registration |
||
126 | * based on the URL given. |
||
127 | * The repository URL may be local or remote, relative or absolute, with Apparat or HTTP scheme. |
||
128 | * |
||
129 | * @param string|Url $url Repository URL |
||
130 | * @return \Apparat\Object\Domain\Repository\Repository Object repository |
||
131 | * @throws InvalidArgumentException If the repository URL is invalid |
||
132 | * @throws InvalidArgumentException If the repository URL is unknown |
||
133 | */ |
||
134 | 9 | public function get($url) |
|
149 | |||
150 | /** |
||
151 | * Test whether a repository URL is registered |
||
152 | * |
||
153 | * @param string $url Repository URL |
||
154 | * @return bool Repository URL is registered |
||
155 | */ |
||
156 | 3 | public function isRegistered($url) |
|
161 | |||
162 | /** |
||
163 | * Return the adapter strategy factory |
||
164 | * |
||
165 | * @return AdapterStrategyFactoryInterface Adapter strategy factory |
||
166 | */ |
||
167 | 10 | public function getAdapterStrategyFactory() |
|
171 | |||
172 | /** |
||
173 | * Return the object manager |
||
174 | * |
||
175 | * @return ManagerInterface Object manager |
||
176 | */ |
||
177 | 3 | public function getObjectManager() |
|
181 | |||
182 | /** |
||
183 | * Normalize a repository URL |
||
184 | * |
||
185 | * @param string|ObjectUrl $url Repository URL |
||
186 | * @return string Normalized repository URL |
||
187 | * @throws InvalidArgumentException If the repository URL is invalid |
||
188 | */ |
||
189 | 20 | public static function normalizeRepositoryUrl($url) |
|
226 | |||
227 | /** |
||
228 | * Enable repository auto-connections |
||
229 | * |
||
230 | * If the method is called without any arguments it will just return the current auto-connection state. |
||
231 | * |
||
232 | * @param null|boolean $autoConnect Enable / disable auto-connections |
||
233 | * @return bool Status of repository auto-connection |
||
234 | */ |
||
235 | 2 | public function useAutoConnect($autoConnect = null) |
|
242 | |||
243 | /******************************************************************************* |
||
244 | * PRIVATE METHODS |
||
245 | *******************************************************************************/ |
||
246 | |||
247 | /** |
||
248 | * Test whether a repository URL registered or can be auto-connected |
||
249 | * |
||
250 | * @param string $url Repository URL |
||
251 | * @return bool Repository is connected |
||
252 | */ |
||
253 | 9 | protected function connected($url) |
|
263 | } |
||
264 |