3 namespace BookStack\Entities;
5 use BookStack\Entities\Models\Book;
6 use BookStack\Entities\Models\Bookshelf;
7 use BookStack\Entities\Models\Chapter;
8 use BookStack\Entities\Models\Entity;
9 use BookStack\Entities\Models\Page;
10 use BookStack\Entities\Models\PageRevision;
13 * Class EntityProvider.
15 * Provides access to the core entity models.
16 * Wrapped up in this provider since they are often used together
17 * 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.
59 * @return array<Entity>
61 public function all(): array
64 'bookshelf' => $this->bookshelf,
65 'book' => $this->book,
66 'chapter' => $this->chapter,
67 'page' => $this->page,
72 * Get an entity instance by it's basic name.
74 public function get(string $type): Entity
76 $type = strtolower($type);
78 return $this->all()[$type];
82 * Get the morph classes, as an array, for a single or multiple types.
84 public function getMorphClasses(array $types): array
87 foreach ($types as $type) {
88 $model = $this->get($type);
89 $morphClasses[] = $model->getMorphClass();