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

Enhance compile #6

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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/AuraSessionModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ protected function configure()
{
$this->bind(Session::class)->toConstructor(Session::class, [
'cookies' => Cookie::class,
'delete_cookie' => DeleteCookie::class
'delete_cookie' => DeleteCookie::class,
]);
$this->bind()->annotatedWith(Cookie::class)->toProvider(CookieProvider::class);
$this->bind()->annotatedWith(DeleteCookie::class)->toInstance(null);
$this->bind()->annotatedWith(DeleteCookie::class)->toInstance([new DeleteCookieInvoker(), '__invoke']);
$this->bind(SegmentFactory::class);
$this->bind(CsrfTokenFactory::class);
$this->bind(RandvalInterface::class)->to(Randval::class);
Expand Down
27 changes: 27 additions & 0 deletions src/DeleteCookieInvoker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Ray.AuraSessionModule package.
*/

namespace Ray\AuraSessionModule;

use function setcookie;
use function time;

final class DeleteCookieInvoker
{
/** @param array{path: string, domain: string} $params */
public function __invoke(string $name, array $params): void
{
setcookie(
$name,
'',
time() - 42000,
$params['path'],
$params['domain']
);
}
}
apple-x-co marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 11 additions & 1 deletion tests/AuraSessionModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;

use function serialize;

class AuraSessionModuleTest extends TestCase
{
public function testAuraSessionModule()
public function testAuraSessionModule(): void
{
$injector = new Injector(new AuraSessionModule());
$session = $injector->getInstance(Session::class);
$this->assertInstanceOf(Session::class, $session);
}

public function testSerialize(): void
{
$injector = new Injector(new AuraSessionModule());
$session = $injector->getInstance(Session::class);
$serialized = serialize($session);
$this->assertIsString($serialized);
}
apple-x-co marked this conversation as resolved.
Show resolved Hide resolved
}
Loading