]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/EntityProvider.php
Update maintenance.php
[bookstack] / app / Entities / EntityProvider.php
index 0442b9f44b98b850b21793dda58436018470925c..d0d4a7ad6c073a7737fdb0a03ef569fbef2487cb 100644 (file)
@@ -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<string>
+     */
+    public function getMorphClasses($types)
+    {
+        if (is_string($types)) {
+            $types = [$types];
+        }
+
+        $morphClasses = [];
+        foreach ($types as $type) {
+            $model = $this->get($type);
+            $morphClasses[] = $model->getMorphClass();
+        }
+        return $morphClasses;
+    }
+}