mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-15 15:44:03 +08:00
2fbf5527c7
Fixes #4444
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Tools;
|
|
|
|
use BookStack\Entities\EntityProvider;
|
|
use BookStack\Entities\Models\Entity;
|
|
|
|
class MixedEntityRequestHelper
|
|
{
|
|
public function __construct(
|
|
protected EntityProvider $entities,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Query out an entity, visible to the current user, for the given
|
|
* entity request details (this provided in a request validated by
|
|
* this classes' validationRules method).
|
|
* @param array{type: string, id: string} $requestData
|
|
*/
|
|
public function getVisibleEntityFromRequestData(array $requestData): Entity
|
|
{
|
|
$entityType = $this->entities->get($requestData['type']);
|
|
|
|
return $entityType->newQuery()->scopes(['visible'])->findOrFail($requestData['id']);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules for an abstract entity request.
|
|
* @return array{type: string[], id: string[]}
|
|
*/
|
|
public function validationRules(): array
|
|
{
|
|
return [
|
|
'type' => ['required', 'string'],
|
|
'id' => ['required', 'integer'],
|
|
];
|
|
}
|
|
}
|