Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
}
],
"require": {
"php": ">=8.4.0",
"symfony/http-foundation": "7.2.5",
"psr/container": "2.0"
"php": ">=7.2.5",
"symfony/http-foundation": "~5.4"
},
"require-dev": {
"phpunit/phpunit": "12.1.2"
"phpunit/phpunit": "^9.5"
},
"minimum-stability": "stable",
"autoload": {
Expand All @@ -26,3 +25,4 @@
"test": "phpunit"
}
}

10 changes: 0 additions & 10 deletions index.php

This file was deleted.

27 changes: 14 additions & 13 deletions src/Adapter/SessionServiceAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,51 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

declare(strict_types=1);

namespace Mabs\Adapter;


use Mabs\Container\Container;
use Mabs\ServiceAdapterInterface;
use Mabs\Events;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
use Symfony\Component\HttpFoundation\Session\Session;
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\Cookie;

class SessionServiceAdapter implements ServiceAdapterInterface
{
public function load(ContainerInterface $container): void
public function load(Container $container)
{
$container['session.storage.options'] = [];
$container['session.storage.options'] = array();
$container['session.default_locale'] = 'en';
$container['session.storage.save_path'] = '/tmp';

$container['session.storage.handler'] = fn(Container $c): NativeFileSessionHandler =>
new NativeFileSessionHandler($c['session.storage.save_path']);
$container['session.storage.handler'] = function (Container $c) {
return new NativeFileSessionHandler($c['session.storage.save_path']);
};

$container['session.storage.native'] = fn(Container $c): NativeSessionStorage =>
new NativeSessionStorage(
$container['session.storage.native'] = function (Container $c) {
return new NativeSessionStorage(
$c['session.storage.options'],
$c['session.storage.handler']
);
};

$container['session'] = function (Container $app): Session {
$container['session'] = function (Container $app) {
if (!isset($app['session.storage'])) {
$app['session.storage'] = $app['session.storage.native'];
}
return new Session($app['session.storage']);
};
}

public function boot(ContainerInterface $container): void
public function boot(Container $container)
{
$container['event_dispatcher']->register(Events::MABS_ON_BOOT, [$this, 'onMabsBoot'], 128);
$container['event_dispatcher']->register(Events::MABS_ON_BOOT, array($this, 'onMabsBoot'), 128);
}

public function onMabsBoot(Container $container): void
public function onMabsBoot(Container $container)
{
$container['request']->setSession($container['session']);
}
Expand Down
Loading