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.
10 * @package BookStack\Entities
41 * EntityProvider constructor.
42 * @param Bookshelf $bookshelf
44 * @param Chapter $chapter
46 * @param PageRevision $pageRevision
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.
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.
82 public function get(string $type)
84 $type = strtolower($type);
85 return $this->all()[$type];
89 * Get the morph classes, as an array, for a single or multiple types.
90 * @param string|array $types
91 * @return array<string>
93 public function getMorphClasses($types)
95 if (is_string($types)) {
100 foreach ($types as $type) {
101 $model = $this->get($type);
102 $morphClasses[] = $model->getMorphClass();
104 return $morphClasses;