-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix server request for root services (#1169)
- Loading branch information
Showing
7 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Tests\Router\Fixtures; | ||
|
||
final class UserContext | ||
{ | ||
private function __construct() {} | ||
|
||
public static function create(): self | ||
{ | ||
return new self(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Tests\Router\Fixtures; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use Spiral\Boot\Bootloader\Bootloader; | ||
|
||
final class UserContextBootloader extends Bootloader | ||
{ | ||
public function defineBindings(): array | ||
{ | ||
return [ | ||
UserContext::class => [self::class, 'userContext'], | ||
]; | ||
} | ||
|
||
private function userContext(ServerRequestInterface $request): UserContext | ||
{ | ||
return isset($request->getQueryParams()['context']) | ||
? UserContext::create() | ||
: throw new \Exception( | ||
'Unable to resolve UserContext, invalid request.', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Tests\Router\Fixtures; | ||
|
||
class UserContextController | ||
{ | ||
public function __construct( | ||
private readonly UserContext $scope, | ||
) {} | ||
|
||
public function scope(): string | ||
{ | ||
return $this->scope ? 'OK' : 'FAIL'; | ||
} | ||
} |