Skip to content

Commit

Permalink
configure Yii Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorgmansuryan committed Jul 18, 2018
1 parent 124ab26 commit 1c815d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function dispatch()
/** @var Rule $route */
$config = $route->getConfig();
$rule = new UrlRule($config);
if (is_callable($route->callable)) {
call_user_func($route->callable, $rule);
}

if ($request = $rule->parseRequest($this->urlManager, $app->request)) {
$params = ArrayHelper::merge($request, [$event]);
foreach ($route->getMiddleware() as $callBack) {
Expand Down
10 changes: 10 additions & 0 deletions src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use yii\base\BaseObject;
use RuntimeException;
use yii\web\UrlRule;
use yii\web\UrlRuleInterface;

/**
* Class Rule
Expand All @@ -16,6 +18,7 @@ class Rule extends BaseObject implements RuleInterface
public $defaults = [];
public $alias;
public $verbs = [];
public $callable;

private $middleware;
private $config;
Expand All @@ -31,6 +34,13 @@ public function init()
}
}

public function configure($callable)
{
$this->callable = $callable;

return $this;
}

/**
* @inheritdoc
*/
Expand Down
6 changes: 6 additions & 0 deletions src/RuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
*/
interface RuleInterface
{
/**
* @param callable $callable
* @return RuleInterface
*/
public function configure($callable);

/**
* @param array $defaults
* @return RuleInterface
Expand Down

0 comments on commit 1c815d4

Please sign in to comment.