diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ad68c7a --- /dev/null +++ b/composer.json @@ -0,0 +1,71 @@ +{ + "name": "webinertia/webinertia-session", + "description": "Provides concrete factories for Laminas session", + "license": "BSD-3-Clause", + "keywords": [ + "webinertia", + "webinertia-mvc", + "laminas", + "laminas-mvc" + ], + "homepage": "https://github.com/webinertia/webinertia-session/discussions", + "authors": [ + { + "name": "Joey Smith", + "email": "jsmith@webinertia.net", + "homepage": "https://webinertia.net/" + } + ], + "suggest": { + "laminas/laminas-component-installer" : "^3.0, required for configuration injection" + }, + "require": { + "php": "~8.1.0 || ~8.2.0", + "laminas/laminas-session": "^2.16.0" + }, + "require-dev": { + "laminas/laminas-coding-standard": "^2.4.0", + "phpunit/phpunit": "10.2.2", + "psalm/plugin-phpunit": "^0.18.4", + "phpstan/phpstan": "1.10.19", + "laminas/laminas-test": "^4.8", + "phpstan/extension-installer": "^1.2", + "slam/phpstan-laminas-framework": "^1.4" + }, + "extra": { + "laminas": { + "component": "Webinertia\\Session", + "config-provider": "Webinertia\\Session\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Webinertia\\Session\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "WebinertiaTest\\SessionTest\\": "test/" + } + }, + "scripts": { + "check": [ + "@cs-check", + "@phpstan", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "static-analysis": "psalm --shepherd --stats", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "phpstan": "php vendor/bin/phpstan analyse --xdebug" + }, + "config": { + "allow-plugins": { + "composer/package-versions-deprecated": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true + } + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..e12634a --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>webinertia/webinertia:renovate-config" + ] +} diff --git a/src/ConfigFactory.php b/src/ConfigFactory.php new file mode 100644 index 0000000..97da186 --- /dev/null +++ b/src/ConfigFactory.php @@ -0,0 +1,21 @@ +get('config')['session_config'] ?? []; + $class = $requestedName(); + $class->setOptions($config); + return $class; + } +} diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php new file mode 100644 index 0000000..b2c813a --- /dev/null +++ b/src/ConfigProvider.php @@ -0,0 +1,51 @@ + [ + ConfigInterface::class => ConfigFactory::class, + ManagerInterface::class => SessionManagerFactory::class, + ], + ]; + } + + public function getSessionConfig(): array + { + return [ + 'use_cookies' => true, + ]; + } + + public function getSessionContainerConfig(): array + { + return [Container::class]; + } + + public function getSessionStorageConfig(): array + { + return [ + 'type' => SessionArrayStorage::class, + ]; + } + + public function getSessionValidatorConfig(): array + { + return [ + RemoteAddr::class, + HttpUserAgent::class, + ]; + } +} \ No newline at end of file diff --git a/src/Container.php b/src/Container.php new file mode 100644 index 0000000..9108a6a --- /dev/null +++ b/src/Container.php @@ -0,0 +1,13 @@ +get(SessionManager::class)); + } +} diff --git a/src/Module.php b/src/Module.php new file mode 100644 index 0000000..83b87e7 --- /dev/null +++ b/src/Module.php @@ -0,0 +1,20 @@ + $configProvider->getDependencyConfig(), + 'session_config' => $configProvider->getSessionConfig(), + 'session_containers' => $configProvider->getSessionContainerConfig(), + 'session_storage' => $configProvider->getSessionStorageConfig(), + 'session_validators' => $configProvider->getSessionValidatorConfig(), + ]; + } +} \ No newline at end of file diff --git a/src/SaveHandlerFactory.php b/src/SaveHandlerFactory.php new file mode 100644 index 0000000..a520744 --- /dev/null +++ b/src/SaveHandlerFactory.php @@ -0,0 +1,40 @@ +get('config')['db']; + // db options + $dbOptions = [ + 'idColumn' => 'id', + 'nameColumn' => 'name', + 'modifiedColumn' => 'modified', + 'lifetimeColumn' => 'lifetime', + 'dataColumn' => 'data', + ]; + return new DbTableGateway( + new TableGateway($config['sessions_table_name'], $container->get(AdapterInterface::class)), + new DbTableGatewayOptions($dbOptions) + ); + } +} diff --git a/src/SessionContainerAwareInterface.php b/src/SessionContainerAwareInterface.php new file mode 100644 index 0000000..a7a7a0a --- /dev/null +++ b/src/SessionContainerAwareInterface.php @@ -0,0 +1,14 @@ +sessionContainer = $container; + } + + public function getSessionContainer(): Container + { + return $this->sessionContainer; + } +} diff --git a/src/SessionManagerFactory.php b/src/SessionManagerFactory.php new file mode 100644 index 0000000..39f5669 --- /dev/null +++ b/src/SessionManagerFactory.php @@ -0,0 +1,27 @@ +has('config') ? $container->get('config') : []; + // $config = $config['session_config'] ?? []; + + // $sessionConfig = ! empty($config['config_class']) ? new $config['config_class']() : new SessionConfig(); + // $sessionConfig->setOptions($config); + return new $requestedName( + $container->has(ConfigInterface::class) ? $container->get(ConfigInterface::class) : new SessionConfig() + ); + } +}