Skip to content

Commit

Permalink
Handle nullable prefix system config (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrooo authored Jul 12, 2023
1 parent 34cd2cf commit 74bb917
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bootstrap_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

mb_internal_encoding("UTF-8");

require 'vendor/autoload.php';
require 'vendor/autoload.php';
4 changes: 2 additions & 2 deletions src/Ouzo/Core/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function getAction(): ?string
private function parsePath(string $path = null, int $limit = null): array
{
if ($path != null) {
$prefix = Config::getValue('global', 'prefix_system');
$pathWithoutPrefix = urldecode(str_replace($prefix, '', $path));
$prefix = Config::getValue('global', 'prefix_system') ?: Strings::EMPTY;
$pathWithoutPrefix = urldecode(str_replace($prefix, Strings::EMPTY, $path));
return preg_split('#/|\?#', $pathWithoutPrefix, $limit ?: -1, PREG_SPLIT_NO_EMPTY);
}
return [];
Expand Down
15 changes: 15 additions & 0 deletions test/src/Ouzo/Core/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,21 @@ public function shouldReturnCorrectProtocol(string $header, mixed $value, string
$this->assertEquals($expected, $protocol);
}

#[Test]
public function should(): void
{
//given
Config::overrideProperty('global', 'prefix_system')->with(null);

$this->path(Config::getPrefixSystem() . '/users');

//when
$rawController = $this->uri->getRawController();

//then
$this->assertEquals('users', $rawController);
}

public static function protocols(): array
{
return [
Expand Down

0 comments on commit 74bb917

Please sign in to comment.