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 public function __construct()
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();
56 * Fetch all core entity types as an associated array
57 * with their basic names as the keys.
58 * @return array<Entity>
60 public function all(): array
63 'bookshelf' => $this->bookshelf,
64 'book' => $this->book,
65 'chapter' => $this->chapter,
66 'page' => $this->page,
71 * Get an entity instance by it's basic name.
73 public function get(string $type): Entity
75 $type = strtolower($type);
76 return $this->all()[$type];
80 * Get the morph classes, as an array, for a single or multiple types.
82 public function getMorphClasses(array $types): array
85 foreach ($types as $type) {
86 $model = $this->get($type);
87 $morphClasses[] = $model->getMorphClass();