]> BookStack Code Mirror - bookstack/blob - app/Entities/Tools/MixedEntityRequestHelper.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Entities / Tools / MixedEntityRequestHelper.php
1 <?php
2
3 namespace BookStack\Entities\Tools;
4
5 use BookStack\Entities\EntityProvider;
6 use BookStack\Entities\Models\Entity;
7
8 class MixedEntityRequestHelper
9 {
10     public function __construct(
11         protected EntityProvider $entities,
12     ) {
13     }
14
15     /**
16      * Query out an entity, visible to the current user, for the given
17      * entity request details (this provided in a request validated by
18      * this classes' validationRules method).
19      * @param array{type: string, id: string} $requestData
20      */
21     public function getVisibleEntityFromRequestData(array $requestData): Entity
22     {
23         $entityType = $this->entities->get($requestData['type']);
24
25         return $entityType->newQuery()->scopes(['visible'])->findOrFail($requestData['id']);
26     }
27
28     /**
29      * Get the validation rules for an abstract entity request.
30      * @return array{type: string[], id: string[]}
31      */
32     public function validationRules(): array
33     {
34         return [
35                 'type' => ['required', 'string'],
36                 'id'   => ['required', 'integer'],
37         ];
38     }
39 }