‪TYPO3CMS  ‪main
RemoteRegistry.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
26 {
30  protected ‪$remotes = [];
31 
35  protected ‪$defaultRemote;
36 
37  public function ‪registerRemote(‪ExtensionDownloaderRemoteInterface $remote, array $configuration): void
38  {
39  ‪$identifier = $remote->‪getIdentifier();
40 
41  $this->remotes[‪$identifier] = array_merge(
42  $configuration,
43  [
44  'service' => $remote,
45  'listable' => $remote instanceof ‪ListableRemoteInterface,
46  ]
47  );
48 
49  if ($this->remotes[‪$identifier]['default']
50  && $this->remotes[‪$identifier]['enabled']
51  && $this->remotes[‪$identifier]['listable']
52  ) {
53  // This overrides a previously set default remote
54  $this->defaultRemote = $remote;
55  }
56  }
57 
58  public function ‪hasRemote(string ‪$identifier): bool
59  {
60  return isset($this->remotes[‪$identifier]) && $this->remotes[‪$identifier]['enabled'];
61  }
62 
64  {
65  if (isset($this->remotes[‪$identifier]) && $this->remotes[‪$identifier]['enabled']) {
66  return $this->remotes[‪$identifier]['service'];
67  }
68  throw new RemoteNotRegisteredException(
69  'The requested remote ' . ‪$identifier . ' is not registered in this system or not enabled',
70  1601566451
71  );
72  }
73 
74  public function ‪hasDefaultRemote(): bool
75  {
76  return isset($this->defaultRemote);
77  }
78 
80  {
81  if ($this->defaultRemote !== null) {
83  }
84  throw new RemoteNotRegisteredException('No default remote registered in this system', 1602226715);
85  }
86 
90  public function ‪getListableRemotes(): iterable
91  {
92  foreach ($this->remotes as $remote) {
93  if ($remote['listable'] && $remote['enabled']) {
94  yield $remote['service'];
95  }
96  }
97  }
98 
102  public function ‪getAllRemotes(): iterable
103  {
104  foreach ($this->remotes as $remote) {
105  if ($remote['enabled']) {
106  yield $remote['service'];
107  }
108  }
109  }
110 }
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\registerRemote
‪registerRemote(ExtensionDownloaderRemoteInterface $remote, array $configuration)
Definition: RemoteRegistry.php:35
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\getRemote
‪getRemote(string $identifier)
Definition: RemoteRegistry.php:61
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\getAllRemotes
‪ExtensionDownloaderRemoteInterface[] getAllRemotes()
Definition: RemoteRegistry.php:100
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\hasRemote
‪hasRemote(string $identifier)
Definition: RemoteRegistry.php:56
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\getListableRemotes
‪ListableRemoteInterface[] getListableRemotes()
Definition: RemoteRegistry.php:88
‪TYPO3\CMS\Extensionmanager\Remote\RemoteNotRegisteredException
Definition: RemoteNotRegisteredException.php:25
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\$remotes
‪array< string, array > $remotes
Definition: RemoteRegistry.php:29
‪TYPO3\CMS\Extensionmanager\Remote\ExtensionDownloaderRemoteInterface
Definition: ExtensionDownloaderRemoteInterface.php:28
‪TYPO3\CMS\Extensionmanager\Remote
Definition: DownloadFailedException.php:18
‪TYPO3\CMS\Extensionmanager\Remote\ExtensionDownloaderRemoteInterface\getIdentifier
‪getIdentifier()
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\$defaultRemote
‪ExtensionDownloaderRemoteInterface $defaultRemote
Definition: RemoteRegistry.php:33
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\getDefaultRemote
‪getDefaultRemote()
Definition: RemoteRegistry.php:77
‪TYPO3\CMS\Extensionmanager\Remote\ListableRemoteInterface
Definition: ListableRemoteInterface.php:24
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry\hasDefaultRemote
‪hasDefaultRemote()
Definition: RemoteRegistry.php:72
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry
Definition: RemoteRegistry.php:26
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37