Skip to content

Commit

Permalink
Added RepresentationCollectionFinderProviderInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Jul 13, 2020
1 parent 172cf68 commit 1e3ece4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/grid/RepresentationCollectionFinder.php
Expand Up @@ -22,7 +22,7 @@
*
* @author Dmytro Naumenko <d.naumenko.a@gmail.com>
*/
class RepresentationCollectionFinder
class RepresentationCollectionFinder implements RepresentationCollectionFinderInterface
{
private $module;
private $controller;
Expand Down Expand Up @@ -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);

Expand Down
32 changes: 32 additions & 0 deletions src/grid/RepresentationCollectionFinderInterface.php
@@ -0,0 +1,32 @@
<?php

namespace hipanel\grid;

use hiqdev\higrid\representations\RepresentationCollection;
use hiqdev\higrid\representations\RepresentationCollectionInterface;
use yii\base\InvalidConfigException;

/**
* Interface RepresentationCollectionFinderInterface provides an API to find
* representation collections in conformance to the current HTTP request
*
* @author Dmytro Naumenko <d.naumenko.a@gmail.com>
*/
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();
}
8 changes: 8 additions & 0 deletions src/grid/RepresentationCollectionFinderProviderInterface.php
@@ -0,0 +1,8 @@
<?php

namespace hipanel\grid;

interface RepresentationCollectionFinderProviderInterface
{
public function getRepresentationCollectionFinder(): RepresentationCollectionFinderInterface;
}

0 comments on commit 1e3ece4

Please sign in to comment.