Page MenuHomeDevCentral

InstancesRepository.php
No OneTemporary

InstancesRepository.php

<?php
namespace Nasqueron\SAAS\MediaWiki;
use Nasqueron\SAAS\InstanceNotFoundException;
abstract class InstancesRepository {
///
/// Repository data methods
///
abstract static public function getList () : array;
abstract static public function getAliases () : array;
///
/// Helper methods
///
/**
* @throws InstanceNotFoundException
*/
public static function getCanonicalHost (string $host) : string {
$canonicalList = static::getList();
// Case 1 - the host is canonical
if (array_key_exists($host, $canonicalList)) {
return $host;
}
// Case 2 - the host is an alias
foreach (static::getAliases() as $database => $vhosts) {
if (in_array($host, $vhosts)) {
return array_search($database, $canonicalList);
}
}
throw new InstanceNotFoundException($host);
}
/**
* @throws InstanceNotFoundException
*/
public static function getDatabaseFromHost (string $host) : string {
$canonicalHost = self::getCanonicalHost($host);
return static::getList()[$canonicalHost];
}
}

File Metadata

Mime Type
text/x-php
Expires
Thu, Nov 13, 15:29 (19 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3131814
Default Alt Text
InstancesRepository.php (1 KB)

Event Timeline