<?php
// Resources.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use Docuform\Api\HttpRequestHandler;use Docuform\Api\UserType;use Psr\Http\Message\ServerRequestInterface;use Psr\Http\Message\ResponseInterface;use Docuform\Api\ApiScopes;use Nyholm\Psr7\Stream;class Resources extends HttpRequestHandler{public function getAllowedUserTypes($request):array{return[UserType::USERTYPE_CUSTOMER,UserType::USERTYPE_DEALER,UserType::USERTYPE_ADMIN];}public function getRequiredScopes($request):array{if($request->getMethod()!=='GET')return['allOf'=>[ApiScopes::server_read,ApiScopes::server_write],'anyOf'=>[]];else return['allOf'=>[],'anyOf'=>[ApiScopes::server_read,ApiScopes::mcs]];}public function handleRequest($request,& $response,$arguments):int{$result=404;if($request->getMethod()==='GET'){$serverApi=$this->getContainer()->get('RestApi');$resource=new Resource($this->getContainer());$resource->read($request);if(!empty($resource->resourceData)){$bodyStream=Stream::create('');$json=json_encode($resource->resourceData,JSON_UNESCAPED_SLASHES);$bodyStream->write($json);$response=$response->withBody($bodyStream);$result=200;}else{$result=204;}}return $result;}}