1 <?php namespace BookStack\Entities;
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.
39 * EntityProvider constructor.
41 public function __construct(
46 PageRevision $pageRevision
48 $this->bookshelf = $bookshelf;
50 $this->chapter = $chapter;
52 $this->pageRevision = $pageRevision;
56 * Fetch all core entity types as an associated array
57 * with their basic names as the keys.
58 * @return [string => 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();