Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12423860
GetHost.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
GetHost.php
View Options
<?php
namespace
Nasqueron\SAAS\MediaWiki\Utilities
;
use
Nasqueron\SAAS\MediaWiki\Configuration\Instances
;
use
Nasqueron\SAAS\MediaWiki\Configuration\Settings
;
use
Nasqueron\SAAS\InstanceNotFoundException
;
use
Keruald\Commands\Command
;
class
GetHost
extends
Command
{
public
const
EXIT_HOST_NOT_FOUND
=
2
;
public
function
main
()
:
int
{
if
(
$this
->
getArgc
()
<
2
)
{
self
::
usage
();
return
1
;
}
try
{
$this
->
display
->
out
(
$this
->
search
(
$this
->
getArgv
()[
1
]));
}
catch
(
InstanceNotFoundException
$exception
)
{
$this
->
display
->
error
(
"Host not found."
);
return
self
::
EXIT_HOST_NOT_FOUND
;
}
return
0
;
}
public
function
search
(
string
$needle
)
:
string
{
if
(
self
::
isDomain
(
$needle
))
{
return
Instances
::
getCanonicalHost
(
$needle
);
}
return
self
::
getHostFromAlias
(
$needle
);
}
public
static
function
isDomain
(
$string
)
:
bool
{
return
strpos
(
$string
,
"."
)
!==
false
;
}
public
static
function
getHostFromAlias
(
string
$alias
)
:
string
{
// Map alias to database
$map
=
Settings
::
getDatabaseMap
();
if
(
isset
(
$map
[
$alias
]))
{
$alias
=
$map
[
$alias
];
}
// Get database from host
$host
=
array_search
(
$alias
,
Instances
::
getList
());
if
(
$host
===
false
)
{
throw
new
InstanceNotFoundException
(
$alias
);
}
return
$host
;
}
public
function
usage
()
:
void
{
$commandName
=
$this
->
getCommandName
();
$this
->
display
->
error
(
"Usage: $commandName <wiki host or alias>"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Nov 6, 19:13 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3128872
Default Alt Text
GetHost.php (1 KB)
Attached To
Mode
rSAASMW SaaS MediaWiki
Attached
Detach File
Event Timeline
Log In to Comment