Skip to content

Commit

Permalink
Fixes with routes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmongeau committed Feb 7, 2018
1 parent 15d495a commit 06aa574
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 52 deletions.
9 changes: 4 additions & 5 deletions src/Folklore/Panneau/Panneau.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public function getDefaultRoutes()
return $this->defaultRoutes;
}



public function getResourcesRoutes()
{
$registrar = $this->app['panneau.registrar'];
Expand All @@ -64,7 +62,7 @@ public function getResourcesRoutes()
foreach ($resources as $resource) {
$customController = $resource->getController();
if (!is_null($customController)) {
$resourceRoutes = $registrar->getRoutesNames($resource->getId());
$resourceRoutes = $registrar->getRoutesNames('resource.'.$resource->getId());
$routes = array_merge($routes, array_values($resourceRoutes));
}
}
Expand All @@ -74,7 +72,7 @@ public function getResourcesRoutes()
public function getResourceRoutes($id)
{
$registrar = $this->app['panneau.registrar'];
return $registrar->getRoutesNames($id);
return $registrar->getRoutesNames('resource.'.$id);
}

public function getAllRoutes()
Expand Down Expand Up @@ -239,12 +237,13 @@ protected function updateRouterPatterns()
$router = $this->app->bound('router') ? $this->app['router'] : $this->app;
$resources = $this->getResources();
$paramName = $this->app['config']->get('panneau.routes.parameters.resource', 'resource');
$ids = [];
$ids = ['_resource'];
foreach ($resources as $resource) {
if (is_null($resource->getController())) {
$ids[] = $resource->getId();
}
}

$router->pattern($paramName, implode('|', $ids));
}

Expand Down
49 changes: 2 additions & 47 deletions src/Folklore/Panneau/PanneauRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function resource($resourceName, $options = [])
$resourceName => $this->idParameterName
];

$defaultNames = $this->getRoutesNames($isWildcard ? 'resource' : $resourceName);
$defaultNames = $this->getRoutesNames($isWildcard ? 'resource' : 'resource.'.$resourceName);

$path = $isWildcard ? '{'.$this->resourceParameterName.'}' : $resourceName;
$resourceOptions = [
Expand All @@ -75,56 +75,11 @@ public function resource($resourceName, $options = [])
'resource' => $isWildcard ? null : $resourceName,
], $groupConfig), function () use ($isWildcard, $resourceName, $path, $controller, $resourceOptions) {
$this->router->get($path.'/definition', [
'as' =>$this->getRouteName($isWildcard ? 'resource' : $resourceName, 'definition'),
'as' =>$this->getRouteName($isWildcard ? 'resource' : 'resource.'.$resourceName, 'definition'),
'uses' => $controller.'@definition'
]);
$this->router->resource($path, $controller, $resourceOptions);
});

// $allActions = array_keys($this->routePaths);
// if (!empty($only) && !empty($except)) {
// throw new Exception('Cannot specify both mutually exclusive options "except" and "only"');
// } elseif (!empty($only)) {
// $actions = $only;
// } elseif (!empty($except)) {
// $actions = array_except($allActions, $except);
// } else {
// $actions = $allActions;
// }
//
// foreach ($actions as $action) {
// $pathDefinition = $this->routePaths[$action];
// $method = $pathDefinition['method'];
// $path = $pathDefinition['path'];
// $actionParams = [
// 'uses' => $controller.'@'.$action,
// 'as' => array_get($names, $action, $this->getRouteName($resourceName, $action)),
// ];
//
// // If not for a catch-all controller
// if ($resourceName !== '*') {
// // Replace the resource route parameter with the actual resource name
// $path = str_replace('{'.$this->resourceParameterName.'}', $resourceName, $path);
// // Add the actual resource name to the action's parameters,
// // which can later be used by helpers in ResourceController
// $actionParams += [
// 'resource' => $resourceName,
// ];
// }
//
// $route = $this->router->match(
// $method,
// $path,
// $actionParams
// );
// $route->middleware('panneau.middlewares.inject_resource');
//
// // If the whereResource options is set, add it as the route
// // resource parameter filtering clause
// if (!is_null($whereResource)) {
// $route->where($this->resourceParameterName, $whereResource);
// }
// }
}

public function getRoutesNames($resource)
Expand Down

0 comments on commit 06aa574

Please sign in to comment.