Skip to content

Commit

Permalink
Testing fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Kallio committed Jan 8, 2016
1 parent 18792e2 commit b88967b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/YamlRoute/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ private function _newRoute($name, $route)
}
}
if (isset($route['config']['controller'])) {
$route = $this->_createPassParams($route);

$opts = [];
foreach ($route['config'] as $key => $item) {
Expand All @@ -234,6 +233,8 @@ private function _newRoute($name, $route)
}
}

$route = $this->_createPassParams($route);

$thirdParam = $this->_buildThirdParam($name, $route);

$path = $method == 'scope' ? $route['path'] : '/';
Expand All @@ -258,24 +259,22 @@ private function _newRoute($name, $route)
}
}

$x = self::_createPassParams($x);

$opts = [];

foreach ($x['config'] as $k => $item) {
if (!in_array($k, $exclude)) {
if (is_array($item) && $k === 'pass') {
foreach ($item as $i => $y) {
if (!is_integer($i)) {
$opts[$i] = $y;
}
$opts[$i] = $y;
}
} else {
$opts[$k] = $item;
}
}
}

$x = self::_createPassParams($x);

$thirdParam = $this->_buildThirdParam($key, $x);

/* @var \Cake\Routing\Router $routes */
Expand Down Expand Up @@ -361,9 +360,14 @@ private function _createPassParams($route)
preg_match_all('/\{([^}]+)\}/', $route['path'], $matches);
if (isset($matches[1])) {
foreach ($matches[1] as $key => $item) {
$route['config']['pass'][] = $item;
$route['config']['pass'][$item] = $item;
}
}
$arr = [];
foreach ($route['config']['pass'] as $key => $item) {
$arr[] = $key;
}
$route['config']['pass'] = $arr;

return $route;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/YamlRoute/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testIntegration()
$assert .= '\Cake\Routing\Router::plugin(\'PluginCars\', [\'path\' => \'/cars\'], function ($routes) {' . "\n";
$assert .= "\t" . '$routes->extensions([\'0\' => \'json\', \'1\' => \'xml\']);' . "\n";
$assert .= "\t" . '$routes->connect(\'/\', [\'plugin\' => \'PluginCars\', \'controller\' => \'Cars\', \'action\' => \'index\'], [\'_name\' => \'cars\']);' . "\n";
$assert .= "\t" . '$routes->connect(\'/bmws\', [\'controller\' => \'Bmws\'], [\'_name\' => \'bmws_list\']);' . "\n";
$assert .= "\t" . '$routes->connect(\'/bmws\', [\'controller\' => \'Bmws\', \'foo\' => \'bar\'], [\'_name\' => \'bmws_list\', \'pass\' => [\'0\' => \'foo\']]);' . "\n";
$assert .= "\t" . '$routes->connect(\'/bmws/:id\', [\'_method\' => \'GET\', \'controller\' => \'Bmws\', \'action\' => \'view\'], [\'_name\' => \'bmws_view\', \'pass\' => [\'0\' => \'id\'], \'id\' => \'[0-9]+\']);' . "\n";
$assert .= "\t" . '$routes->connect(\'/bmws/add\', [\'_method\' => \'POST\', \'controller\' => \'Bmws\', \'action\' => \'add\'], [\'_name\' => \'bmws_add\']);' . "\n";
$assert .= "\t" . '$routes->connect(\'/ladas\', [\'controller\' => \'Ladas\'], [\'_name\' => \'ladas\']);' . "\n";
Expand Down
2 changes: 2 additions & 0 deletions tests/plugins/PluginCars/config/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cars:
path: /bmws
config:
controller: Bmws
pass:
foo: bar
bmws_view:
path: /bmws/{id}
config:
Expand Down

0 comments on commit b88967b

Please sign in to comment.