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