Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/UrlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class UrlRule extends BaseObject implements UrlRuleInterface
/**
* @var string The Regular Expressions Syntax used to parse the id of the main resource from url.
* For example, in the following final rule, $linkAttributePattern is default to that `\d+` to parse $brand_id value:
*
*
* GET,HEAD v1/brands/<brand_id:\d+>/items/<IDs:\d[\d,]*>
*
*
* While that works fine with digital IDs, in a system using a different format, like uuid for example,
* you may use $linkAttributePattern to define different patterns. Something like this maybe:
*
*
* [
* // Nested Rules Brand
* 'class' => 'tunecino\nestedrest\UrlRule',
Expand Down Expand Up @@ -204,6 +204,7 @@ public function parseRequest($manager, $request)
$link_attribute = isset($this->linkAttribute) ? $this->linkAttribute : $modelName . '_id';
$this->config['prefix'] = $resourceName . '/<' . $link_attribute . ':' . $this->linkAttributePattern . '>';

$allRelationsConfig = $this->config;
foreach ($this->relations as $key => $value) {
if (is_int($key)) {
$relation = $value;
Expand All @@ -224,10 +225,13 @@ public function parseRequest($manager, $request)
}

$modulePrefix = isset($this->modulePrefix) ? $this->modulePrefix . '/' : '';
$this->config['controller'][$urlName] = $modulePrefix . $controller;
$config = $this->config;
$config['controller'][$urlName] = $modulePrefix . $controller;
$allRelationsConfig['controller'][$urlName] = $modulePrefix . $controller;

$this->setRulesFactory($this->config);
$routeObj = $this->rulesFactory->parseRequest($manager, $request);
/** @var \yii\rest\UrlRule $urlRule */
$urlRule = Yii::createObject($config);
$routeObj = $urlRule->parseRequest($manager, $request);

if ($routeObj) {
$routeObj[1]['relativeClass'] = $this->modelClass;
Expand All @@ -237,6 +241,8 @@ public function parseRequest($manager, $request)
}
}

$this->setRulesFactory($allRelationsConfig);

return false;
}
}