-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Joey Smith <jsmith@webinertia.net> Signed-off-by: Joey Smith <jsmith@webinertia.net>
- Loading branch information
Showing
11 changed files
with
305 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"local>webinertia/webinertia:renovate-config" | ||
] | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Laminas\Session\Config\SessionConfig; | ||
use Psr\Container\ContainerInterface; | ||
|
||
class ConfigFactory implements FactoryInterface | ||
{ | ||
/** @param string $requestedName */ | ||
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): SessionConfig | ||
{ | ||
$config = $container->get('config')['session_config'] ?? []; | ||
$class = $requestedName(); | ||
$class->setOptions($config); | ||
return $class; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
use Laminas\Session\Config\ConfigInterface; | ||
use Laminas\Session\ManagerInterface; | ||
use Laminas\Session\Storage\SessionArrayStorage; | ||
use Laminas\Session\Validator\RemoteAddr; | ||
use Laminas\Session\Validator\HttpUserAgent; | ||
|
||
final class ConfigProvider | ||
{ | ||
public function getDependencyConfig(): array | ||
{ | ||
return [ | ||
'factories' => [ | ||
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, | ||
]; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
use Laminas\Session\AbstractContainer; | ||
|
||
class Container extends AbstractContainer | ||
{ | ||
/** @var string $context */ | ||
protected $context; | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
use Webinertia\Session\Container; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Laminas\Session\SessionManager; | ||
use Psr\Container\ContainerInterface; | ||
|
||
class ContainerFactory implements FactoryInterface | ||
{ | ||
/** @param string $requestedName*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): Container | ||
{ | ||
return new $requestedName('App_Context', $container->get(SessionManager::class)); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
final class Module | ||
{ | ||
public function getConfig(): array | ||
{ | ||
$configProvider = new ConfigProvider(); | ||
return [ | ||
'service_manager' => $configProvider->getDependencyConfig(), | ||
'session_config' => $configProvider->getSessionConfig(), | ||
'session_containers' => $configProvider->getSessionContainerConfig(), | ||
'session_storage' => $configProvider->getSessionStorageConfig(), | ||
'session_validators' => $configProvider->getSessionValidatorConfig(), | ||
]; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
use Laminas\Db\Adapter\AdapterInterface; | ||
use Laminas\Db\TableGateway\TableGateway; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Laminas\Session\SaveHandler\DbTableGateway; | ||
use Laminas\Session\SaveHandler\DbTableGatewayOptions; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
|
||
final class SaveHandlerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param string $requestedName | ||
* @param null|mixed[] $options | ||
* @throws NotFoundExceptionInterface | ||
* @throws ContainerExceptionInterface | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): DbTableGateway | ||
{ | ||
$config = $container->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) | ||
); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
use Webinertia\Session\Container; | ||
|
||
interface SessionContainerAwareInterface | ||
{ | ||
public function setSessionContainer(Container $container); | ||
|
||
public function getSessionContainer(): Container; | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webinertia\Session; | ||
|
||
use Webinertia\Session\Container; | ||
|
||
trait SessionContainerAwareTrait | ||
{ | ||
/** @var Container $sessionContainer */ | ||
protected $sessionContainer; | ||
|
||
public function setSessionContainer(Container $container) | ||
{ | ||
$this->sessionContainer = $container; | ||
} | ||
|
||
public function getSessionContainer(): Container | ||
{ | ||
return $this->sessionContainer; | ||
} | ||
} |
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 Webinertia\Session; | ||
|
||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Laminas\Session\Config\ConfigInterface; | ||
use Laminas\Session\Config\SessionConfig; | ||
use Laminas\Session\SessionManager; | ||
use Psr\Container\ContainerInterface; | ||
|
||
class SessionManagerFactory implements FactoryInterface | ||
{ | ||
/** @param string $requestedName */ | ||
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): SessionManager | ||
{ | ||
// $config = $container->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() | ||
); | ||
} | ||
} |