Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F49507424
Service.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
Service.php
View Options
<?php
namespace
Nasqueron\Api\ServersLog
;
use
Dotenv\Dotenv
;
class
Service
extends
BaseService
{
///
/// Initialisation
///
public
function
__construct
()
{
$this
->
loadEnvironment
();
}
///
/// Controller
///
private
function
isAliveRequest
()
:
bool
{
return
$_SERVER
[
'REQUEST_METHOD'
]
===
"GET"
&&
$_SERVER
[
'REQUEST_URI'
]
===
'/status'
;
}
public
function
handle
()
:
void
{
if
(
$this
->
isAliveRequest
())
{
$this
->
sendSuccessResponse
(
"ALIVE"
);
}
elseif
(
$_SERVER
[
'REQUEST_METHOD'
]
===
"PUT"
)
{
$body
=
$this
->
getBodyObject
();
$this
->
put
(
$body
);
}
else
{
$this
->
sendInvalidMethodResponse
();
}
}
public
function
put
(
$data
)
:
void
{
if
(
$data
===
NULL
)
{
$this
->
sendBadRequestResponse
();
return
;
}
$log
=
self
::
getServersLogFile
();
if
(!
$log
)
{
$this
->
sendInternalServerError
();
return
;
}
Log
::
addEntryToJSONFile
(
$log
,
LogEntry
::
fromJSON
(
$data
)
);
$this
->
sendSuccessResponse
();
}
///
/// Helper methods
///
private
function
loadEnvironment
()
:
void
{
$env
=
Dotenv
::
createUnsafeImmutable
(
__DIR__
);
if
(
file_exists
(
__DIR__
.
'/.env'
))
{
$env
->
load
();
}
$env
->
required
(
'SERVERS_LOG_FILE'
);
}
private
static
function
getServersLogFile
()
:
string
{
return
getenv
(
'SERVERS_LOG_FILE'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Sep 14, 16:12 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4085464
Default Alt Text
Service.php (1 KB)
Attached To
Mode
rAPISRVLOGS Servers log :: Add new entries API
Attached
Detach File
Event Timeline
Log In to Comment