*/ class RemotesController extends AbstractStationApiCrudController { protected string $entityClass = Entity\StationRemote::class; protected string $resourceRouteName = 'api:stations:remote'; protected function viewRecord(object $record, ServerRequest $request): mixed { if (!($record instanceof Entity\StationRemote)) { throw new InvalidArgumentException( sprintf('Record must be an instance of %s.', Entity\StationRemote::class) ); } $returnArray = $this->toArray($record); $return = new Entity\Api\StationRemote(); $return->fromParentObject($returnArray); $isInternal = ('true' === $request->getParam('internal', 'false')); $router = $request->getRouter(); $return->is_editable = $record->isEditable(); $return->links = [ 'self' => (string)$router->fromHere( route_name: $this->resourceRouteName, route_params: ['id' => $record->getIdRequired()], absolute: !$isInternal ), ]; return $return; } /** * @inheritDoc */ protected function getRecord(Entity\Station $station, int|string $id): ?object { $record = parent::getRecord($station, $id); if ($record instanceof Entity\StationRemote && !$record->isEditable()) { throw new PermissionDeniedException('This record cannot be edited.'); } return $record; } }