Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 15, 2023
1 parent 71dc9e3 commit 198a911
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
76 changes: 38 additions & 38 deletions src/Console/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,16 @@ protected function routesFromMountPaths(array $mountPaths): Collection
}

/**
* Filter the route by URI and / or name.
*
* @param array<string, string> $route
* @return array<string, string>|null
* Get the route name for the given mount path and view path.
*/
protected function filterRoute(array $route): ?array
protected function routeName(string $mountPath, string $viewPath): ?string
{
if ($this->option('name') && ! Str::contains((string) $route['name'], $this->option('name'))) {
return null;
}

if (($this->option('path') && ! Str::contains($route['uri'], $this->option('path')))) {
return null;
}

if (($this->option('domain') && ! Str::contains((string) $route['domain'], $this->option('domain')))) {
return null;
}

if ($this->option('except-path')) {
foreach (explode(',', $this->option('except-path')) as $path) {
if (str_contains($route['uri'], $path)) {
return null;
}
}
}
return collect($this->laravel->make(FolioRoutes::class)->routes())->search(function (array $route) use ($mountPath, $viewPath) {
[$routeRelativeMountPath, $routeRelativeViewPath] = $route;

return $route;
return $routeRelativeMountPath === Project::relativePathOf($mountPath)
&& $routeRelativeViewPath === Project::relativePathOf($viewPath);
}) ?: null;
}

/**
Expand Down Expand Up @@ -223,6 +205,37 @@ protected function toDisplayableFormat(array $routes): array
return $this->pluckColumns($routes);
}

/**
* Filter the route by URI and / or name.
*
* @param array<string, string> $route
* @return array<string, string>|null
*/
protected function filterRoute(array $route): ?array
{
if ($this->option('name') && ! Str::contains((string) $route['name'], $this->option('name'))) {
return null;
}

if (($this->option('path') && ! Str::contains($route['uri'], $this->option('path')))) {
return null;
}

if (($this->option('domain') && ! Str::contains((string) $route['domain'], $this->option('domain')))) {
return null;
}

if ($this->option('except-path')) {
foreach (explode(',', $this->option('except-path')) as $path) {
if (str_contains($route['uri'], $path)) {
return null;
}
}
}

return $route;
}

/**
* Sort the routes by a given element.
*
Expand Down Expand Up @@ -273,17 +286,4 @@ protected function getOptions(): array
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (domain, name, uri, view) to sort by', 'uri'],
];
}

/**
* Get the route name for the given mount path and view path.
*/
protected function routeName(string $mountPath, string $viewPath): ?string
{
return collect($this->laravel->make(FolioRoutes::class)->routes())->search(function (array $route) use ($mountPath, $viewPath) {
[$routeRelativeMountPath, $routeRelativeViewPath] = $route;

return $routeRelativeMountPath === Project::relativePathOf($mountPath)
&& $routeRelativeViewPath === Project::relativePathOf($viewPath);
}) ?: null;
}
}
20 changes: 10 additions & 10 deletions src/FolioRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ public function get(string $name, array $arguments, bool $absolute): string
});
}

/**
* Get all the registered routes.
*/
public function routes(): array
{
$this->ensureLoaded();

return $this->routes;
}

/**
* Get the relative route URL for the given route name and arguments.
*
Expand Down Expand Up @@ -194,6 +184,16 @@ protected function formatParameter(string $uri, string $name, mixed $parameter,
return $value;
}

/**
* Get all of the registered routes.
*/
public function routes(): array
{
$this->ensureLoaded();

return $this->routes;
}

/**
* Flush the cached routes.
*/
Expand Down

0 comments on commit 198a911

Please sign in to comment.