RouteRule.php 711 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace common\modules\rbac\components;
  3. /**
  4. * RouteRule Rule for check route with extra params.
  5. *
  6. * @author Misbahul D Munir <misbahuldmunir@gmail.com>
  7. *
  8. * @since 1.0
  9. */
  10. class RouteRule extends \yii\rbac\Rule
  11. {
  12. const RULE_NAME = 'route_rule';
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function execute($user, $item, $params)
  17. {
  18. $routeParams = isset($item->data['params']) ? $item->data['params'] : [];
  19. $allow = true;
  20. $queryParams = \Yii::$app->request->getQueryParams();
  21. foreach ($routeParams as $key => $value) {
  22. $allow = $allow && (!isset($queryParams[$key]) || $queryParams[$key] == $value);
  23. }
  24. return $allow;
  25. }
  26. }