class SyncCoreFactory in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/SyncCoreInterface/SyncCoreFactory.php \Drupal\cms_content_sync\SyncCoreInterface\SyncCoreFactory
- 2.0.x src/SyncCoreInterface/SyncCoreFactory.php \Drupal\cms_content_sync\SyncCoreInterface\SyncCoreFactory
Class SyncCoreFactory.
This is the central interface between Drupal and the Sync Core. Drupal will call ::getSyncCore() and then use the Sync Core library whereas the Sync Core library in return uses the interface functions provided here.
Hierarchy
- class \Drupal\cms_content_sync\SyncCoreInterface\SyncCoreFactory
Expanded class hierarchy of SyncCoreFactory
9 files declare their use of SyncCoreFactory
- CliService.php in src/
Cli/ CliService.php - cms_content_sync.install in ./
cms_content_sync.install - Install file for cms_content_sync.
- ContentSyncSettings.php in src/
Controller/ ContentSyncSettings.php - CopyRemoteFlow.php in src/
Form/ CopyRemoteFlow.php - DebugForm.php in src/
Form/ DebugForm.php
File
- src/
SyncCoreInterface/ SyncCoreFactory.php, line 14
Namespace
Drupal\cms_content_sync\SyncCoreInterfaceView source
class SyncCoreFactory {
/**
* @var \EdgeBox\SyncCore\Interfaces\ISyncCore[]
*/
protected static $clients = [];
/**
* @var \EdgeBox\SyncCore\Interfaces\ISyncCore[]
*/
protected static $allSyncCores = null;
/**
* Return an instance of the ISyncCore Client for the given URL.
* Cache clients.
*
* @param string $sync_core_url
* The base URL to the Sync Core
*
* @return \EdgeBox\SyncCore\Interfaces\ISyncCore
*/
public static function getSyncCore($sync_core_url) {
if (!empty(self::$clients[$sync_core_url])) {
return self::$clients[$sync_core_url];
}
return self::$clients[$sync_core_url] = new SyncCore(DrupalApplication::get(), $sync_core_url);
}
/**
* @return \EdgeBox\SyncCore\Interfaces\ISyncCore[]
*/
public static function getAllSyncCores() {
if (!empty(self::$allSyncCores)) {
return self::$allSyncCores;
}
$cores = [];
foreach (Pool::getAll() as $pool) {
$url = parse_url($pool
->getSyncCoreUrl());
$host = $url['host'];
if (isset($cores[$host])) {
continue;
}
$cores[$host] = self::getSyncCore($pool
->getSyncCoreUrl());
}
return self::$allSyncCores = $cores;
}
/**
* @return null|\EdgeBox\SyncCore\Interfaces\ISyncCore
*/
public static function getAnySyncCore() {
$cores = self::getAllSyncCores();
if (!count($cores)) {
return null;
}
return reset($cores);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SyncCoreFactory:: |
protected static | property | ||
SyncCoreFactory:: |
protected static | property | ||
SyncCoreFactory:: |
public static | function | ||
SyncCoreFactory:: |
public static | function | ||
SyncCoreFactory:: |
public static | function | Return an instance of the ISyncCore Client for the given URL. Cache clients. |