Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/Commands/PageCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function run(array $params)
[
'{{pageName}}' => $pageName,
'{{pageNamespace}}' => str_replace('/', '\\', $pageName),
]
],
);

// Create the index.php file
Expand All @@ -61,7 +61,7 @@ public function run(array $params)
[
'{{pageName}}' => $pageName,
'{{pageSlug}}' => str_replace('/', '_', $pageName),
]
],
);
}

Expand Down
60 changes: 8 additions & 52 deletions src/PageRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,18 @@ class PageRouter extends Router
*/
public function handle(?string $uri = null)
{
// If we cannot find a URI to match against, then set it to root (`/`).
if ($uri === null || $uri === '') {
$uri = '/';
}

// Decode URL-encoded string
$uri = urldecode($uri);

$this->checkDisallowedChars($uri);

// Restart filterInfo
$this->filtersInfo = [];

// Checks defined routes
if ($this->checkRoutes($uri)) {
if ($this->collection->isFiltered($this->matchedRoute[0])) {
$this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]);
try {
$handle = parent::handle($uri);
} catch (PageNotFoundException $e) {
// HACK: Check for page based routes
if ($this->pageBasedRoute($uri)) {
return $this->controllerName();
}

return $this->controller;
}

// HACK: Check for page based routes
if ($this->pageBasedRoute($uri)) {
return $this->controllerName();
}

// Still here? Then we can try to match the URI against
// Controllers/directories, but the application may not
// want this, like in the case of API's.
if (! $this->collection->shouldAutoRoute()) {
throw new PageNotFoundException(
"Can't find a route for '{$this->collection->getHTTPVerb()}: {$uri}'."
);
throw $e;
}

// Checks auto routes
$this->autoRoute($uri);

return $this->controllerName();
return $handle;
}

/**
Expand Down Expand Up @@ -131,20 +103,4 @@ public function pageBasedRoute(string $uri)

return $pageFound;
}

/**
* Checks disallowed characters
*/
private function checkDisallowedChars(string $uri): void
{
foreach (explode('/', $uri) as $segment) {
if ($segment !== '' && $this->permittedURIChars !== ''
&& preg_match('/\A[' . $this->permittedURIChars . ']+\z/iu', $segment) !== 1
) {
throw new BadRequestException(
'The URI you submitted has disallowed characters: "' . $segment . '"'
);
}
}
}
}
Loading