1 <?php namespace BookStack\Entities;
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;
11 * Class EntityProvider
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.
46 * EntityProvider constructor.
48 public function __construct(
53 PageRevision $pageRevision
55 $this->bookshelf = $bookshelf;
57 $this->chapter = $chapter;
59 $this->pageRevision = $pageRevision;
63 * Fetch all core entity types as an associated array
64 * with their basic names as the keys.
65 * @return [string => Entity]
67 public function all(): array
70 'bookshelf' => $this->bookshelf,
71 'book' => $this->book,
72 'chapter' => $this->chapter,
73 'page' => $this->page,
78 * Get an entity instance by it's basic name.
80 public function get(string $type): Entity
82 $type = strtolower($type);
83 return $this->all()[$type];
87 * Get the morph classes, as an array, for a single or multiple types.
89 public function getMorphClasses(array $types): array
92 foreach ($types as $type) {
93 $model = $this->get($type);
94 $morphClasses[] = $model->getMorphClass();