]> BookStack Code Mirror - bookstack/blob - app/Entities/EntityProvider.php
Fixed 'interaction_required' response for azure
[bookstack] / app / Entities / EntityProvider.php
1 <?php namespace BookStack\Entities;
2
3 /**
4  * Class EntityProvider
5  *
6  * Provides access to the core entity models.
7  * Wrapped up in this provider since they are often used together
8  * so this is a neater alternative to injecting all in individually.
9  *
10  * @package BookStack\Entities
11  */
12 class EntityProvider
13 {
14
15     /**
16      * @var Bookshelf
17      */
18     public $bookshelf;
19
20     /**
21      * @var Book
22      */
23     public $book;
24
25     /**
26      * @var Chapter
27      */
28     public $chapter;
29
30     /**
31      * @var Page
32      */
33     public $page;
34
35     /**
36      * @var PageRevision
37      */
38     public $pageRevision;
39
40     /**
41      * EntityProvider constructor.
42      */
43     public function __construct(
44         Bookshelf $bookshelf,
45         Book $book,
46         Chapter $chapter,
47         Page $page,
48         PageRevision $pageRevision
49     ) {
50         $this->bookshelf = $bookshelf;
51         $this->book = $book;
52         $this->chapter = $chapter;
53         $this->page = $page;
54         $this->pageRevision = $pageRevision;
55     }
56
57     /**
58      * Fetch all core entity types as an associated array
59      * with their basic names as the keys.
60      */
61     public function all(): array
62     {
63         return [
64             'bookshelf' => $this->bookshelf,
65             'book' => $this->book,
66             'chapter' => $this->chapter,
67             'page' => $this->page,
68         ];
69     }
70
71     /**
72      * Get an entity instance by it's basic name.
73      */
74     public function get(string $type): Entity
75     {
76         $type = strtolower($type);
77         return $this->all()[$type];
78     }
79
80     /**
81      * Get the morph classes, as an array, for a single or multiple types.
82      */
83     public function getMorphClasses(array $types): array
84     {
85         $morphClasses = [];
86         foreach ($types as $type) {
87             $model = $this->get($type);
88             $morphClasses[] = $model->getMorphClass();
89         }
90         return $morphClasses;
91     }
92 }