<?php
// DevicePaperTrays.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use DI\DependencyException;use DI\NotFoundException;use Docuform\Api\ApiScopes;use Docuform\Api\Exception\ApiHttpBadRequestException;use Docuform\Api\Exception\ApiHttpInvalidParameter;use Docuform\Api\Exception\ApiHttpNotFoundException;use Docuform\Api\HttpRequestHandler;use Docuform\Api\UserType;use Docuform\Database\DbException;use Psr\Http\Message\ResponseInterface;use Psr\Http\Message\ServerRequestInterface;class DevicePaperTrays 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');$device=$serverApi->getDevice();if(empty($device)){throw new ApiHttpBadRequestException($request);}$trays=new DevicePaperTray($this->getContainer());$trays->read($device->id);if($trays->deviceId===$device->id){DevicePaperTray::buildJsonResponse($response,$trays,'devicePaperTrays');$result=200;}else{$result=204;}}return $result;}}