Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3768351
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/BaseService.php b/src/BaseService.php
index fd144bf..dcd0d65 100644
--- a/src/BaseService.php
+++ b/src/BaseService.php
@@ -1,34 +1,35 @@
<?php
namespace Nasqueron\Api\ServersLog;
use Exception;
class BaseService {
///
/// Helper methods
///
protected function getBodyObject () {
$content= file_get_contents('php://input');
switch ($_SERVER["HTTP_CONTENT_TYPE"]) {
case "application/json":
return json_decode($content);
default:
throw new Exception("Unknown content type.");
}
}
- protected function sendSuccessResponse () {
+ protected function sendSuccessResponse ($responseBody = '') {
// HTTP 200 OK
+ echo $responseBody;
}
protected function sendInvalidMethodResponse () {
header("HTTP/1.0 405 Method Not Allowed");
http_response_code(405);
}
}
diff --git a/src/Service.php b/src/Service.php
index 852e487..6da464d 100644
--- a/src/Service.php
+++ b/src/Service.php
@@ -1,57 +1,64 @@
<?php
namespace Nasqueron\Api\ServersLog;
use Dotenv\Dotenv;
class Service extends BaseService {
///
/// Initialisation
///
public function __construct () {
$this->loadEnvironment();
}
///
/// Controller
///
- public function handle () : void {
- $body = $this->getBodyObject();
+ private function isAliveRequest() : bool {
+ return
+ $_SERVER['REQUEST_METHOD'] === "GET"
+ &&
+ $_SERVER['REQUEST_URI'] === '/status';
+ }
- if ($_SERVER['REQUEST_METHOD'] === "PUT") {
+ public function handle () : void {
+ if ($this->isAliveRequest()) {
+ $this->sendSuccessResponse("ALIVE");
+ } elseif ($_SERVER['REQUEST_METHOD'] === "PUT") {
+ $body = $this->getBodyObject();
$this->put($body);
- return;
+ } else {
+ $this->sendInvalidMethodResponse();
}
-
- $this->sendInvalidMethodResponse();
}
public function put ($data) : void {
Log::addEntryToJSONFile(
self::getServersLogFile(),
LogEntry::fromJSON($data)
);
$this->sendSuccessResponse();
}
///
/// Helper methods
///
private function loadEnvironment () : void {
$env = new Dotenv(__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-diff
Expires
Mon, Nov 25, 07:36 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259743
Default Alt Text
(2 KB)
Attached To
Mode
rAPISRVLOGS Servers log :: Add new entries API
Attached
Detach File
Event Timeline
Log In to Comment