Skip to content

Commit

Permalink
Fix root settlement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Surkov committed May 27, 2023
1 parent 94b4edf commit bf37ba8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "symbiotic/full",
"description": "Complete assembly of the SymbioticPHP framework with a cached container and optimized core services",
"license": ["BSD-3-Clause"],
"version": "1.4.2",
"version": "1.4.2.2",
"homepage": "https://symbioticphp.com",
"authors": [
{
Expand Down
6 changes: 5 additions & 1 deletion src/Routing/PackagesSettlements.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public function getByRouter(string $router): ?SettlementInterface
public function getByUrl(string $url): ?SettlementInterface
{
$path = $this->getPathByUrl($url);
return $this->getSettlementByString($path);
$settlement = $this->getSettlementByString($path);
if(null !== $settlement) {
return $settlement;
}
return $this->settlements->getByUrl($url);
}

protected function getSettlementByString(string $string): ?SettlementInterface
Expand Down
10 changes: 8 additions & 2 deletions src/Routing/Settlements.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public function __construct(protected SettlementFactory $factory, array $items)
$counter = 0;

foreach ($items as $v) {
$pattern .= '(?<id_' . $index . '>^/' . preg_quote(trim($v['prefix'], '\\/'), '~') . '/.*)|';
/// for / root
if(empty(trim($v['prefix'], '\\/'))) {
$pattern .= '(?<id_' . $index . '>^/.*)|';
} else {
$pattern .= '(?<id_' . $index . '>^/' . preg_quote(trim($v['prefix'], '\\/'), '~') . '/.*)|';

}
$this->items[$index++] = $v;
if ($counter === 60) {
$this->find_patterns[] = '~' . rtrim($pattern, '|') . '~';
Expand Down Expand Up @@ -102,7 +108,7 @@ public function getByKey(string $key, mixed $value, bool $all = false): Settleme
{
$result = [];
foreach ($this->items as $v) {
if ($v->get($key) === $value) {
if (isset($v[$key]) && $v[$key] === $value) {
if ($all) {
$result[] = $this->factory->make($v);
} else {
Expand Down

0 comments on commit bf37ba8

Please sign in to comment.