mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-31 15:24:31 +03:00
Entity Repo & Controller Refactor (#1690)
* Started mass-refactoring of the current entity repos * Rewrote book tree logic - Now does two simple queries instead of one really complex one. - Extracted logic into its own class. - Remove model-level akward union field listing. - Logic now more readable than being large separate query and compilation functions. * Extracted and split book sort logic * Finished up Book controller/repo organisation * Refactored bookshelves controllers and repo parts * Fixed issues found via phpunit * Refactored Chapter controller * Updated Chapter export controller * Started Page controller/repo refactor * Refactored another chunk of PageController * Completed initial pagecontroller refactor pass * Fixed tests and continued reduction of old repos * Removed old page remove and further reduced entity repo * Removed old entity repo, split out page controller * Ran phpcbf and split out some page content methods * Tidied up some EntityProvider elements * Fixed issued caused by viewservice change
This commit is contained in:
@ -39,11 +39,6 @@ class EntityProvider
|
||||
|
||||
/**
|
||||
* EntityProvider constructor.
|
||||
* @param Bookshelf $bookshelf
|
||||
* @param Book $book
|
||||
* @param Chapter $chapter
|
||||
* @param Page $page
|
||||
* @param PageRevision $pageRevision
|
||||
*/
|
||||
public function __construct(
|
||||
Bookshelf $bookshelf,
|
||||
@ -62,9 +57,8 @@ class EntityProvider
|
||||
/**
|
||||
* Fetch all core entity types as an associated array
|
||||
* with their basic names as the keys.
|
||||
* @return Entity[]
|
||||
*/
|
||||
public function all()
|
||||
public function all(): array
|
||||
{
|
||||
return [
|
||||
'bookshelf' => $this->bookshelf,
|
||||
@ -76,10 +70,8 @@ class EntityProvider
|
||||
|
||||
/**
|
||||
* Get an entity instance by it's basic name.
|
||||
* @param string $type
|
||||
* @return Entity
|
||||
*/
|
||||
public function get(string $type)
|
||||
public function get(string $type): Entity
|
||||
{
|
||||
$type = strtolower($type);
|
||||
return $this->all()[$type];
|
||||
@ -87,15 +79,9 @@ class EntityProvider
|
||||
|
||||
/**
|
||||
* Get the morph classes, as an array, for a single or multiple types.
|
||||
* @param string|array $types
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getMorphClasses($types)
|
||||
public function getMorphClasses(array $types): array
|
||||
{
|
||||
if (is_string($types)) {
|
||||
$types = [$types];
|
||||
}
|
||||
|
||||
$morphClasses = [];
|
||||
foreach ($types as $type) {
|
||||
$model = $this->get($type);
|
||||
|
Reference in New Issue
Block a user