From d6bb157b73667980f05a4a24b7b11f3957bc4404 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Sun, 2 Jun 2024 22:11:24 -0400 Subject: [PATCH] Add configuration for session, add Odan Session classes. --- app/.phpactor.json | 4 ++ app/composer.json | 4 +- app/composer.lock | 56 ++++++++++++++++++- app/src/Bootstrap.php | 16 ++++++ .../DatabaseConnectionSchema.php | 1 - app/src/Configuration/SessionSchema.php | 22 ++++++++ .../Controller/Channel/CreateChannelPage.php | 15 +++++ app/src/Domain/Entity/Channel.php | 6 +- app/src/Domain/Entity/User.php | 6 +- app/templates/channel/create.twig | 28 ++++++++++ 10 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 app/.phpactor.json create mode 100644 app/src/Configuration/SessionSchema.php create mode 100644 app/src/Controller/Channel/CreateChannelPage.php create mode 100644 app/templates/channel/create.twig diff --git a/app/.phpactor.json b/app/.phpactor.json new file mode 100644 index 0000000..a078d1d --- /dev/null +++ b/app/.phpactor.json @@ -0,0 +1,4 @@ +{ + "$schema": "/phpactor.schema.json", + "prophecy.enabled": true +} \ No newline at end of file diff --git a/app/composer.json b/app/composer.json index 611ed93..741e89c 100644 --- a/app/composer.json +++ b/app/composer.json @@ -10,8 +10,8 @@ "league/flysystem": "^3.27", "league/config": "^1.2", "monolog/monolog": "^3.6", - "middlewares/php-session": "^3.1", - "slim/flash": "^0.4.0" + "slim/flash": "^0.4.0", + "odan/session": "^6.1" }, "require-dev": { "phpunit/phpunit": "^11.1", diff --git a/app/composer.lock b/app/composer.lock index 32988ac..7a1700b 100644 --- a/app/composer.lock +++ b/app/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2b7ce82429ac8209451138f3a4803fd0", + "content-hash": "ef0dabb2ed1f62b79526b77f3db35cd4", "packages": [ { "name": "dflydev/dot-access-data", @@ -819,6 +819,60 @@ }, "time": "2018-02-13T20:26:39+00:00" }, + { + "name": "odan/session", + "version": "6.1.0", + "source": { + "type": "git", + "url": "https://github.com/odan/session.git", + "reference": "b30e66903ab2cfa012c1d6c49b9bb11caa4c9f57" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/odan/session/zipball/b30e66903ab2cfa012c1d6c49b9bb11caa4c9f57", + "reference": "b30e66903ab2cfa012c1d6c49b9bb11caa4c9f57", + "shasum": "" + }, + "require": { + "php": "^8.0", + "psr/http-message": "^1", + "psr/http-server-handler": "^1", + "psr/http-server-middleware": "^1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3", + "middlewares/utils": "^3", + "nyholm/psr7": "^1.5", + "phpstan/phpstan": "^1", + "phpunit/phpunit": "^7 || ^8 || ^9 || ^10", + "squizlabs/php_codesniffer": "^3", + "symfony/console": "6.0.*", + "symfony/event-dispatcher": "6.0.*", + "symfony/filesystem": "6.0.*", + "symfony/finder": "6.0.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Odan\\Session\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A Slim session handler", + "homepage": "https://github.com/odan/session", + "keywords": [ + "session", + "slim" + ], + "support": { + "issues": "https://github.com/odan/session/issues", + "source": "https://github.com/odan/session/tree/6.1.0" + }, + "time": "2023-01-22T10:40:26+00:00" + }, { "name": "php-di/invoker", "version": "2.3.4", diff --git a/app/src/Bootstrap.php b/app/src/Bootstrap.php index 2de0523..ff42027 100644 --- a/app/src/Bootstrap.php +++ b/app/src/Bootstrap.php @@ -7,6 +7,7 @@ use Slim\Factory\AppFactory; use League\Config\Configuration; +use Psr\Container\ContainerInterface; use DI\Container; use DI\ContainerBuilder; @@ -16,11 +17,15 @@ use Slim\Views\TwigMiddleware; use Slovocast\Routes; use Slovocast\Configuration\SiteInformationSchema; use Slovocast\Configuration\DatabaseConnectionSchema; +use Slovocast\Configuration\SessionSchema; use Psr\Log\LoggerInterface; use Monolog\Logger; use Monolog\Handler\StreamHandler; use Monolog\Level; +use Odan\Session\PhpSession; +use Odan\Session\SessionInterface; +use Odan\Session\SessionManagerInterface; class Bootstrap { @@ -36,6 +41,7 @@ class Bootstrap // set all configuration details $config->addSchema('site', SiteInformationSchema::getSchema()); $config->addSchema('database', DatabaseConnectionSchema::getSchema()); + $config->addSchema('session', SessionSchema::getSchema()); $config->merge([ 'site' => [ @@ -45,6 +51,9 @@ class Bootstrap 'podcast', 'hosting', 'indie', 'independent', 'easy' ] ], + 'session' => [ + 'name' => 'slovocast' + ] ]); return $config; @@ -74,6 +83,13 @@ class Bootstrap new StreamHandler(__DIR__ . '/var/logs', Level::Warning) ); return $logger; + }, + SessionManagerInterface::class => function (ContainerInterface $container) { + return $container->get(SessionInterface::class); + }, + SessionInterface::class => function (ContainerInterface $container) { + $options = $container->get('config')->get('session'); + return new PhpSession($options); } ]); diff --git a/app/src/Configuration/DatabaseConnectionSchema.php b/app/src/Configuration/DatabaseConnectionSchema.php index d57d598..757d1eb 100644 --- a/app/src/Configuration/DatabaseConnectionSchema.php +++ b/app/src/Configuration/DatabaseConnectionSchema.php @@ -18,5 +18,4 @@ class DatabaseConnectionSchema 'password' => Expect::string()->nullable() ]); } - } diff --git a/app/src/Configuration/SessionSchema.php b/app/src/Configuration/SessionSchema.php new file mode 100644 index 0000000..8388b88 --- /dev/null +++ b/app/src/Configuration/SessionSchema.php @@ -0,0 +1,22 @@ + Expect::string()->default('slovocast'), + 'lifetime' => Expect::int()->min(0)->max(65535)->default(7200), + 'path' => Expect::string()->nullable(), + 'domain' => Expect::string()->nullable(), + 'secure' => Expect::bool()->default(false), + 'httponly' => Expect::bool()->default(false), + 'cache_limiter' => Expect::string()->nullable() + ]); + } +} diff --git a/app/src/Controller/Channel/CreateChannelPage.php b/app/src/Controller/Channel/CreateChannelPage.php new file mode 100644 index 0000000..595f573 --- /dev/null +++ b/app/src/Controller/Channel/CreateChannelPage.php @@ -0,0 +1,15 @@ +render('channel/create.twig'); + } +} diff --git a/app/src/Domain/Entity/Channel.php b/app/src/Domain/Entity/Channel.php index c7f6cc5..ab44ee4 100644 --- a/app/src/Domain/Entity/Channel.php +++ b/app/src/Domain/Entity/Channel.php @@ -86,15 +86,15 @@ class Channel $props['explicit'] ?? false ); - if ($props['id']) { + if (isset($props['id'])) { $channel->setId($props['id']); } - if ($props['createdAt']) { + if (isset($props['createdAt'])) { $channel->setCreatedAt($props['createdAt']); } - if ($props['updatedAt']) { + if (isset($props['updatedAt'])) { $channel->setUpdatedAt($props['updatedAt']); } diff --git a/app/src/Domain/Entity/User.php b/app/src/Domain/Entity/User.php index b8e2b09..7b45ded 100644 --- a/app/src/Domain/Entity/User.php +++ b/app/src/Domain/Entity/User.php @@ -55,15 +55,15 @@ class User { $user = new self($props['email'], $props['password'], $props['name']); - if (array_key_exists('id', $props)) { + if (isset($props['id'])) { $user->setId($props['id']); } - if (array_key_exists('createdAt', $props)) { + if (isset($props['createdAt'])) { $user->setCreatedAt($props['createdAt']); } - if (array_key_exists('updatedAt', $props)) { + if (isset($props['updatedAt'])) { $user->setUpdatedAt($props['updatedAt']); } diff --git a/app/templates/channel/create.twig b/app/templates/channel/create.twig new file mode 100644 index 0000000..d914423 --- /dev/null +++ b/app/templates/channel/create.twig @@ -0,0 +1,28 @@ +{% extends 'layouts/skeleton.twig' %} + +{% block content %} +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+{% endblock %}