UrlRule.php 963 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace api\rest;
  3. use Yii;
  4. use yii\web\Request;
  5. use yii\base\InvalidConfigException;
  6. use common\helpers\StringHelper;
  7. /**
  8. * Class UrlRule
  9. * @package api\rest
  10. * @author qimall
  11. */
  12. class UrlRule extends \yii\rest\UrlRule
  13. {
  14. /**
  15. * @param $manager
  16. * @param $request Request
  17. * @throws InvalidConfigException if the path info cannot be determined due to unexpected server configuration
  18. * @return array|bool
  19. */
  20. public function parseRequest($manager, $request)
  21. {
  22. $path_info = $request->getPathInfo();
  23. $path_info_list = explode('/', $path_info);
  24. $names = [];
  25. $addons = Yii::$app->services->addons->findAllNames();
  26. foreach ($addons as $addon) {
  27. $names[] = StringHelper::toUnderScore($addon['name']);
  28. }
  29. if (count($path_info_list) >= 3 && in_array($path_info_list[0], $names)) {
  30. return [$path_info, []];
  31. }
  32. return false;
  33. }
  34. }