forked from grumpydevelop/federator

- also cleaned up dummy - added new rewrite for apache for sharedInbox (your.fqdn/inbox) - fixed json-formatting of publicKey when requesting user via api
122 lines
3 KiB
PHP
122 lines
3 KiB
PHP
<?php
|
|
/**
|
|
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* @author Sascha Nitsch (grumpydeveloper)
|
|
**/
|
|
|
|
namespace Federator\Api\V1;
|
|
|
|
/**
|
|
* dummy api class for functional poc
|
|
*/
|
|
class Dummy implements \Federator\Api\APIInterface
|
|
{
|
|
/**
|
|
* \Federator\Main instance
|
|
*
|
|
* @var \Federator\Main $main
|
|
*/
|
|
private $main;
|
|
|
|
/**
|
|
* internal message to output
|
|
*
|
|
* @var string $message
|
|
*/
|
|
private $message = '';
|
|
|
|
/**
|
|
* constructor
|
|
*
|
|
* @param \Federator\Main $main main instance
|
|
*/
|
|
public function __construct(\Federator\Main $main)
|
|
{
|
|
$this->main = $main;
|
|
}
|
|
|
|
/**
|
|
* run given url path
|
|
*
|
|
* @param array<string> $paths path array split by /
|
|
* @param \Federator\Data\User|false $user user who is calling us @unused-param
|
|
* @return bool true on success
|
|
*/
|
|
public function exec($paths, $user): bool
|
|
{
|
|
// only for user with the 'publish' permission
|
|
// if ($user === false || $user->hasPermission('publish') === false) {
|
|
// throw new \Federator\Exceptions\PermissionDenied();
|
|
// }
|
|
$method = $_SERVER["REQUEST_METHOD"];
|
|
switch ($method) {
|
|
case 'GET':
|
|
switch (sizeof($paths)) {
|
|
case 3:
|
|
switch ($paths[2]) {
|
|
case 'moo':
|
|
return $this->getDummy();
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
case 'POST':
|
|
switch (sizeof($paths)) {
|
|
case 3:
|
|
switch ($paths[2]) {
|
|
case 'moo':
|
|
return $this->postDummy();
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
$this->main->setResponseCode(404);
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get function for "/v1/dummy/moo"
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function getDummy()
|
|
{
|
|
$dummyResponse = json_encode([
|
|
'r1' => ' (__) ',
|
|
'r2' => ' `------(oo) ',
|
|
'r3' => ' || __ (__) ',
|
|
'r4' => ' ||w || ',
|
|
'r5' => ' '
|
|
], JSON_PRETTY_PRINT);
|
|
if ($dummyResponse !== false) {
|
|
$this->message = $dummyResponse;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* post function for /v1/dummy/moo"
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function postDummy()
|
|
{
|
|
return $this->getDummy();
|
|
}
|
|
|
|
/**
|
|
* get internal represenation as json string
|
|
*
|
|
* @return string json string
|
|
*/
|
|
public function toJson()
|
|
{
|
|
return $this->message;
|
|
}
|
|
}
|