Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Container Scopes #1104

Merged
merged 104 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
5a74a11
Add HttpRequest scope
msmakouz Jan 22, 2024
ac81df7
Merge remote-tracking branch 'origin/feature/scopes' into feature/htt…
msmakouz Jan 22, 2024
a0d9d03
Bind controller in scope
msmakouz Jan 22, 2024
a56620b
Add Proxy attributes
msmakouz Jan 22, 2024
94bd526
Fix tests
msmakouz Jan 23, 2024
fcbd72d
Fix Psalm
msmakouz Jan 23, 2024
229011f
Add Http binding in the http scope
msmakouz Jan 24, 2024
5f632fd
Fix parameters in phpdoc
msmakouz Jan 24, 2024
adcbc74
Simplify code
msmakouz Jan 24, 2024
a82dcfe
Simplify Hmvc tests
msmakouz Jan 25, 2024
6651415
Simplify http tests
msmakouz Jan 25, 2024
d1eb653
Add dev version of spiral/testing
msmakouz Jan 25, 2024
7e3c737
Simplify spiral/annotated-routes tests
msmakouz Jan 25, 2024
6ebb717
Simplify testHttpBinding test
msmakouz Jan 25, 2024
98385be
Fix test app directory
msmakouz Jan 25, 2024
a337cb4
Add todo
msmakouz Jan 29, 2024
004d36d
Merge pull request #1069 from spiral/feature/http-request-scope
msmakouz Jan 29, 2024
7983a60
Merge remote-tracking branch 'origin/master' into feature/scopes
msmakouz Feb 13, 2024
ebca2fc
Merge remote-tracking branch 'origin/master' into feature/scopes
msmakouz Feb 15, 2024
a3465cc
Change enum name from ScopeName to Spiral
msmakouz Feb 16, 2024
287abf0
Merge pull request #1078 from spiral/rename-enum
msmakouz Feb 16, 2024
0e87fd4
Add PaginationProviderInterface binding in scope
msmakouz Feb 16, 2024
1e65f86
Add unit test
msmakouz Feb 16, 2024
3a2f629
Fix scope
msmakouz Feb 16, 2024
d9281b7
Merge pull request #1079 from spiral/feature/scoped-pagination
msmakouz Feb 16, 2024
5147e08
Using HTTP scopes
msmakouz Feb 17, 2024
e5c84ec
Apply fixes from StyleCI
StyleCIBot Feb 17, 2024
0dba8cb
Improve test
msmakouz Feb 17, 2024
dae1870
Fix CS
msmakouz Feb 17, 2024
1752d6d
Apply fixes from StyleCI
StyleCIBot Feb 17, 2024
7ad2a89
Merge remote-tracking branch 'origin/master' into feature/scopes
msmakouz Feb 20, 2024
6eb1792
Uses named scopes in console component
butschster Feb 20, 2024
a556d3a
Merge remote-tracking branch 'origin/feature/scopes' into feature/scopes
butschster Feb 20, 2024
82fed45
Apply fixes from StyleCI
StyleCIBot Feb 20, 2024
f378299
Merge remote-tracking branch 'origin/feature/scopes' into feature/htt…
msmakouz Feb 20, 2024
2f9c1e0
Add PaginationFactory binding
msmakouz Feb 20, 2024
79d18b7
Simplify unit tests
msmakouz Feb 20, 2024
a54de6b
Deprecate SectionScope
msmakouz Feb 20, 2024
07b2f37
Remove unused code
msmakouz Feb 20, 2024
35649c9
Add for CookieQueue in scope
msmakouz Feb 20, 2024
0440963
Remove unused code
msmakouz Feb 20, 2024
23bea6d
Add http scope to Session, SessionFactory
msmakouz Feb 20, 2024
b7e48f4
Add unit test for SessionFactoryInterface binding in root scope
msmakouz Feb 20, 2024
83c195e
Add exceptions test
msmakouz Feb 20, 2024
683faf5
Fixed bootloader scoped bindings
butschster Feb 20, 2024
aefe526
Add http.request scope to InputManager and InputScope
msmakouz Feb 20, 2024
cb6df86
Add http.request scope to CookieManager
msmakouz Feb 20, 2024
9a2b173
Add Spiral enum instead of string
msmakouz Feb 21, 2024
69fe624
Add proxy AuthContextInterface binding
msmakouz Feb 26, 2024
66b3b0e
Fix InputInterface binding
msmakouz Feb 26, 2024
9a77110
Fix InputInterface binding and add test
msmakouz Feb 26, 2024
b98575d
Merge remote-tracking branch 'origin/master' into feature/scopes
msmakouz Feb 28, 2024
7e30fba
Merge remote-tracking branch 'origin/master' into feature/scopes
roxblnfk Mar 11, 2024
8a6d12d
Merge branch 'feature/scopes' into feature/http-scopes
roxblnfk Mar 11, 2024
8b2f4dd
Using phpdoc final instead of final keyword
msmakouz Mar 11, 2024
a7c5129
Add todo
msmakouz Mar 11, 2024
48ecd28
Remove the second Container parameter from the HTTP Pipeline
roxblnfk Mar 11, 2024
d082e02
Revert buildCore method
msmakouz Mar 11, 2024
99ae1ec
Add phpdoc
msmakouz Mar 11, 2024
f7ebfbe
Merge pull request #1085 from spiral/console-scopes
roxblnfk Mar 11, 2024
90b366c
Improve exceptions when CookieQueue is resolved
roxblnfk Mar 12, 2024
0dbf436
Improve exceptions when SessionInterface is resolved
roxblnfk Mar 12, 2024
6d5422f
Cleanup; move `CookieQueue` into `http` scope
roxblnfk Mar 12, 2024
a7d7103
Add proxy to a InvokerInterface in JobHandler (#1091)
msmakouz Mar 12, 2024
816620a
Add ServerRequestInterface binding
msmakouz Mar 13, 2024
466ffc5
Http Pipeline: fix CurrentRequest hydration
roxblnfk Mar 13, 2024
db49785
Http class: move event dispatcher into constructor
roxblnfk Mar 13, 2024
6561d86
Merge pull request #1080: HTTP scopes
roxblnfk Mar 13, 2024
078591a
Add contract for the new interceptors
roxblnfk Mar 15, 2024
58046d1
Add Target implementation
roxblnfk Mar 18, 2024
99e8f74
make interceptor pipeline compatible with both new and old interceptors
roxblnfk Mar 18, 2024
de7725e
Recompose files
roxblnfk Mar 19, 2024
bfda7e1
Add tests
roxblnfk Mar 19, 2024
bd3cbac
Fix psalm issues
roxblnfk Mar 19, 2024
52a1329
Add Spiral\Interceptors namespace; deprecate old classes and make ali…
roxblnfk Mar 21, 2024
b813426
Add new InterceptorPipeline and ReflectionHandler
roxblnfk Mar 21, 2024
b4fd411
Polishing
roxblnfk Mar 22, 2024
157114e
Add more tests
roxblnfk Mar 27, 2024
0d9dc72
Update phpunit config; add tests for AttributedTrait
roxblnfk Apr 23, 2024
bdc6541
Add tests for Target
roxblnfk Apr 23, 2024
d4fd254
Add tests for ReflectionHandler
roxblnfk Apr 23, 2024
830d2b6
Add tests for ActionResolver; cleanup; fix psalm issue in Interceptor…
roxblnfk Apr 23, 2024
394443e
Fix psalm issues
roxblnfk Apr 23, 2024
2f0d4f8
Integrate new interceptors part 1
roxblnfk Apr 24, 2024
c295b24
Merge remote-tracking branch 'refs/remotes/origin/master' into change…
msmakouz Apr 29, 2024
0b9bbd6
Integrate new interceptors part 2
roxblnfk Apr 29, 2024
8545a9c
Merge pull request #1103 from spiral/changes-from-master
roxblnfk Apr 29, 2024
f4002f2
Integrate new interceptors part 3 (router)
roxblnfk Apr 29, 2024
26e79ee
Fix tests
roxblnfk Apr 29, 2024
d814c57
Cover `Target::fromPair()` method; deprecate `\Spiral\Domain\Pipeline…
roxblnfk Apr 29, 2024
32797fe
Merge pull request #1095: New interceptors
roxblnfk Apr 29, 2024
e56f906
Merge branch 'refs/heads/master' into feature/scopes
roxblnfk Apr 29, 2024
6674166
Fix interceptor Target::fromPair : parent class is put into the path …
roxblnfk Apr 30, 2024
dc02fad
Fix integration of Interceptors and Scopes into the Console component
roxblnfk Apr 30, 2024
568f4fb
Add TestableKernel trait
msmakouz May 2, 2024
f6d01ec
Add stable version of spiral/testing
msmakouz May 7, 2024
218a472
Explode Target::fromReflection to ::fromReflectionFunction and ::from…
roxblnfk May 7, 2024
c1a7902
Fix psalm issues
roxblnfk May 7, 2024
12b822a
Add tests; update core and reflection handler
roxblnfk May 7, 2024
ad847fd
Fix integration with the framework
roxblnfk May 7, 2024
00d721c
Cleanup
roxblnfk May 7, 2024
703275a
Remove outdated tests
roxblnfk May 8, 2024
e6f66b2
Merge pull request #1106: Refactor interceptors target
roxblnfk May 8, 2024
189718f
Merge branch 'refs/heads/master' into feature/scopes
roxblnfk May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"Spiral\\Cookies\\": "src/Cookies/src",
"Spiral\\Core\\": [
"src/Core/src",
"src/Hmvc/src"
"src/Hmvc/src/Core"
],
"Spiral\\Csrf\\": "src/Csrf/src",
"Spiral\\Debug\\": "src/Debug/src",
Expand All @@ -90,6 +90,7 @@
"Spiral\\Files\\": "src/Files/src",
"Spiral\\Filters\\": "src/Filters/src",
"Spiral\\Http\\": "src/Http/src",
"Spiral\\Interceptors\\": "src/Hmvc/src/Interceptors",
"Spiral\\Logger\\": "src/Logger/src",
"Spiral\\Mailer\\": "src/Mailer/src",
"Spiral\\Models\\": "src/Models/src",
Expand Down Expand Up @@ -135,7 +136,7 @@
"rector/rector": "0.18.1",
"spiral/code-style": "^1.1",
"spiral/nyholm-bridge": "^1.2",
"spiral/testing": "^2.7",
"spiral/testing": "dev-feature/scopes as 2.8.0",
msmakouz marked this conversation as resolved.
Show resolved Hide resolved
"spiral/validator": "^1.3",
"google/protobuf": "^3.25",
"symplify/monorepo-builder": "^10.2.7",
Expand All @@ -158,7 +159,7 @@
"Spiral\\Tests\\Cookies\\": "src/Cookies/tests",
"Spiral\\Tests\\Core\\": [
"src/Core/tests",
"src/Hmvc/tests"
"src/Hmvc/tests/Core"
],
"Spiral\\Tests\\Csrf\\": "src/Csrf/tests",
"Spiral\\Tests\\Debug\\": "src/Debug/tests",
Expand All @@ -171,6 +172,7 @@
"Spiral\\Tests\\Filters\\": "src/Filters/tests",
"Spiral\\Tests\\Framework\\": "tests/Framework",
"Spiral\\Tests\\Http\\": "src/Http/tests",
"Spiral\\Tests\\Interceptors\\": "src/Hmvc/tests/Interceptors",
"Spiral\\Tests\\Logger\\": "src/Logger/tests",
"Spiral\\Tests\\Mailer\\": "src/Mailer/tests",
"Spiral\\Tests\\Models\\": "src/Models/tests",
Expand Down
1 change: 1 addition & 0 deletions src/AnnotatedRoutes/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^10.1",
"spiral/framework": "^3.1",
"spiral/testing": "^2.8",
"spiral/nyholm-bridge": "^1.2",
"vimeo/psalm": "^5.9"
},
Expand Down
35 changes: 0 additions & 35 deletions src/AnnotatedRoutes/tests/App/App.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/AnnotatedRoutes/tests/App/runtime/.gitignore

This file was deleted.

109 changes: 10 additions & 99 deletions src/AnnotatedRoutes/tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,124 +4,35 @@

namespace Spiral\Tests\Router;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Spiral\Tests\Router\App\App;
use Spiral\Testing\Attribute\TestScope;

class IntegrationTest extends TestCase
#[TestScope('http')]
final class IntegrationTest extends TestCase
{
private App $app;

public function setUp(): void
{
parent::setUp();
$this->app = $this->makeApp(['DEBUG' => true]);
}

public function testRoute(): void
{
$r = $this->get('/');
$this->assertStringContainsString('index', $r->getBody()->__toString());
$this->fakeHttp()->get('/')->assertBodySame('index');
}

public function testRoute2(): void
{
$r = $this->post('/');
$this->assertStringContainsString('method', $r->getBody()->__toString());
$this->fakeHttp()->post('/')->assertBodySame('method');
}

public function testRoute3(): void
{
$r = $this->get('/page/test');

$this->assertSame('page-test', $r->getBody()->__toString());
$this->fakeHttp()->get('/page/test')->assertBodySame('page-test');
}

public function testRoute4(): void
{
$r = $this->get('/page/about');

$this->assertSame('about', $r->getBody()->__toString());
$this->fakeHttp()->get('/page/about')->assertBodySame('about');
}

public function testRoutesWithoutNames(): void
{
$r = $this->get('/nameless');
$this->assertSame('index', $r->getBody()->__toString());

$r = $this->post('/nameless');
$this->assertSame('method', $r->getBody()->__toString());

$r = $this->get('/nameless/route');
$this->assertSame('route', $r->getBody()->__toString());
}

public function get(
$uri,
array $query = [],
array $headers = [],
array $cookies = []
): ResponseInterface {
return $this->app->getHttp()->handle($this->request($uri, 'GET', $query, $headers, $cookies));
}

public function getWithAttributes(
$uri,
array $attributes,
array $headers = []
): ResponseInterface {
$r = $this->request($uri, 'GET', [], $headers, []);
foreach ($attributes as $k => $v) {
$r = $r->withAttribute($k, $v);
}

return $this->app->getHttp()->handle($r);
}

public function post(
$uri,
array $data = [],
array $headers = [],
array $cookies = []
): ResponseInterface {
return $this->app->getHttp()->handle(
$this->request($uri, 'POST', [], $headers, $cookies)->withParsedBody($data)
);
}

public function request(
$uri,
string $method,
array $query = [],
array $headers = [],
array $cookies = []
): ServerRequestInterface {
$headers = array_merge([
'accept-language' => 'en'
], $headers);

/** @var ServerRequestFactoryInterface $factory */
$factory = $this->app->getContainer()->get(ServerRequestFactoryInterface::class);
$request = $factory->createServerRequest($method, $uri);

foreach ($headers as $name => $value) {
$request = $request->withAddedHeader($name, $value);
}

return $request
->withCookieParams($cookies)
->withQueryParams($query);
}

public function fetchCookies(array $header)
{
$result = [];
foreach ($header as $line) {
$cookie = explode('=', $line);
$result[$cookie[0]] = rawurldecode(substr($cookie[1], 0, strpos($cookie[1], ';')));
}

return $result;
$this->fakeHttp()->get('/nameless')->assertBodySame('index');
$this->fakeHttp()->post('/nameless')->assertBodySame('method');
$this->fakeHttp()->get('/nameless/route')->assertBodySame('route');
}
}
1 change: 1 addition & 0 deletions src/AnnotatedRoutes/tests/RouteLocatorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Spiral\Tests\Router;

use PHPUnit\Framework\TestCase;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\UriFactoryInterface;
use Spiral\Attributes\Factory;
Expand Down
34 changes: 23 additions & 11 deletions src/AnnotatedRoutes/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,37 @@

namespace Spiral\Tests\Router;

use PHPUnit\Framework\TestCase as BaseTestCase;
use Spiral\Boot\Environment;
use Spiral\Tests\Router\App\App;
use Spiral\Nyholm\Bootloader\NyholmBootloader;
use Spiral\Router\Bootloader\AnnotatedRoutesBootloader;
use Spiral\Testing\TestCase as BaseTestCase;

/**
* @requires function \Spiral\Framework\Kernel::init
*/
abstract class TestCase extends BaseTestCase
{
/**
* @throws \Throwable
*/
protected function makeApp(array $env): App
public function defineBootloaders(): array
{
$config = [
'root' => __DIR__ . '/App',
'app' => __DIR__ . '/App',
return [
NyholmBootloader::class,
AnnotatedRoutesBootloader::class,
];
}

public function rootDirectory(): string
{
return __DIR__;
}

public function defineDirectories(string $root): array
{
return \array_merge(parent::defineDirectories($root), ['app' => $root . '/App']);
}

protected function tearDown(): void
{
parent::tearDown();

return (App::create($config, false))->run(new Environment($env));
$this->cleanUpRuntimeDirectory();
}
}
20 changes: 11 additions & 9 deletions src/AuthHttp/src/Middleware/AuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
final class AuthMiddleware implements MiddlewareInterface
{
public const ATTRIBUTE = 'authContext';
public const TOKEN_STORAGE_ATTRIBUTE = 'tokenStorage';

/**
* @param ScopeInterface $scope Deprecated, will be removed in v4.0.
*/
public function __construct(
private readonly ScopeInterface $scope,
private readonly ActorProviderInterface $actorProvider,
private readonly TokenStorageInterface $tokenStorage,
private readonly TransportRegistry $transportRegistry,
private readonly ?EventDispatcherInterface $eventDispatcher = null
private readonly ?EventDispatcherInterface $eventDispatcher = null,
) {
}

Expand All @@ -39,12 +43,10 @@ public function process(Request $request, RequestHandlerInterface $handler): Res
{
$authContext = $this->initContext($request, new AuthContext($this->actorProvider, $this->eventDispatcher));

$response = $this->scope->runScope(
[
AuthContextInterface::class => $authContext,
TokenStorageInterface::class => $this->tokenStorage,
],
static fn () => $handler->handle($request->withAttribute(self::ATTRIBUTE, $authContext))
$response = $handler->handle(
$request
->withAttribute(self::ATTRIBUTE, $authContext)
->withAttribute(self::TOKEN_STORAGE_ATTRIBUTE, $this->tokenStorage),
);

return $this->closeContext($request, $response, $authContext);
Expand Down Expand Up @@ -85,15 +87,15 @@ private function closeContext(Request $request, Response $response, AuthContextI
return $transport->removeToken(
$request,
$response,
$authContext->getToken()->getID()
$authContext->getToken()->getID(),
);
}

return $transport->commitToken(
$request,
$response,
$authContext->getToken()->getID(),
$authContext->getToken()->getExpiresAt()
$authContext->getToken()->getExpiresAt(),
);
}
}
3 changes: 3 additions & 0 deletions src/AuthHttp/src/Middleware/AuthTransportMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ final class AuthTransportMiddleware implements MiddlewareInterface
{
private readonly AuthMiddleware $authMiddleware;

/**
* @param ScopeInterface $scope Deprecated, will be removed in v4.0.
*/
public function __construct(
string $transportName,
ScopeInterface $scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ final class AuthTransportWithStorageMiddleware implements MiddlewareInterface
{
private readonly MiddlewareInterface $authMiddleware;

/**
* @param ScopeInterface $scope Deprecated, will be removed in v4.0.
*/
public function __construct(
string $transportName,
ScopeInterface $scope,
Expand Down