X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/257a5a23ecaf7ce779969d575ff8a0b976181d13..refs/pull/1462/head:/app/Entities/EntityProvider.php diff --git a/app/Entities/EntityProvider.php b/app/Entities/EntityProvider.php index 0442b9f44..d0d4a7ad6 100644 --- a/app/Entities/EntityProvider.php +++ b/app/Entities/EntityProvider.php @@ -15,27 +15,27 @@ class EntityProvider /** * @var Bookshelf */ - protected $bookshelf; + public $bookshelf; /** * @var Book */ - protected $book; + public $book; /** * @var Chapter */ - protected $chapter; + public $chapter; /** * @var Page */ - protected $page; + public $page; /** * @var PageRevision */ - protected $pageRevision; + public $pageRevision; /** * EntityProvider constructor. @@ -74,5 +74,33 @@ class EntityProvider ]; } + /** + * Get an entity instance by it's basic name. + * @param string $type + * @return Entity + */ + public function get(string $type) + { + $type = strtolower($type); + return $this->all()[$type]; + } -} \ No newline at end of file + /** + * Get the morph classes, as an array, for a single or multiple types. + * @param string|array $types + * @return array + */ + public function getMorphClasses($types) + { + if (is_string($types)) { + $types = [$types]; + } + + $morphClasses = []; + foreach ($types as $type) { + $model = $this->get($type); + $morphClasses[] = $model->getMorphClass(); + } + return $morphClasses; + } +}