From 1e3ece4c35e12328de7e773ec5b49cfa88433ff7 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Mon, 13 Jul 2020 14:00:23 +0300 Subject: [PATCH] Added RepresentationCollectionFinderProviderInterface --- src/grid/RepresentationCollectionFinder.php | 8 +++-- ...epresentationCollectionFinderInterface.php | 32 +++++++++++++++++++ ...ationCollectionFinderProviderInterface.php | 8 +++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/grid/RepresentationCollectionFinderInterface.php create mode 100644 src/grid/RepresentationCollectionFinderProviderInterface.php diff --git a/src/grid/RepresentationCollectionFinder.php b/src/grid/RepresentationCollectionFinder.php index 3a12acb6..0cb5f5e6 100644 --- a/src/grid/RepresentationCollectionFinder.php +++ b/src/grid/RepresentationCollectionFinder.php @@ -22,7 +22,7 @@ * * @author Dmytro Naumenko */ -class RepresentationCollectionFinder +class RepresentationCollectionFinder implements RepresentationCollectionFinderInterface { private $module; private $controller; @@ -86,10 +86,14 @@ public function findOrFail() return $collection; } - public static function forCurrentRoute(string $representationsLocation) + public static function forCurrentRoute(string $representationsLocation): RepresentationCollectionFinderInterface { $controller = Yii::$app->controller; + if ($controller->module instanceof RepresentationCollectionFinderProviderInterface) { + return $controller->module->getRepresentationCollectionFinder(); + } + $module = $controller->module->id; $controller = Inflector::id2camel($controller->id); diff --git a/src/grid/RepresentationCollectionFinderInterface.php b/src/grid/RepresentationCollectionFinderInterface.php new file mode 100644 index 00000000..dac2a9e5 --- /dev/null +++ b/src/grid/RepresentationCollectionFinderInterface.php @@ -0,0 +1,32 @@ + + */ +interface RepresentationCollectionFinderInterface +{ + /** + * @return RepresentationCollectionInterface|RepresentationCollection + */ + public function find(); + + /** + * @throws InvalidConfigException When collection does not exist for the route + * @return RepresentationCollection|RepresentationCollectionInterface + */ + public function findOrFail(); + + /** + * @return RepresentationCollectionInterface|RepresentationCollection + */ + public function findOrFallback(); +} diff --git a/src/grid/RepresentationCollectionFinderProviderInterface.php b/src/grid/RepresentationCollectionFinderProviderInterface.php new file mode 100644 index 00000000..fecdab75 --- /dev/null +++ b/src/grid/RepresentationCollectionFinderProviderInterface.php @@ -0,0 +1,8 @@ +