Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12587138
InstancesRepository.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
InstancesRepository.php
View Options
<?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
Details
Attached
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)
Attached To
Mode
rSAASMW SaaS MediaWiki
Attached
Detach File
Event Timeline
Log In to Comment