Add configuration for session, add Odan Session classes.

This commit is contained in:
Dave Smith-Hayes 2024-06-02 22:11:24 -04:00
parent c5feb240c3
commit d6bb157b73
10 changed files with 148 additions and 10 deletions

4
app/.phpactor.json Normal file
View File

@ -0,0 +1,4 @@
{
"$schema": "/phpactor.schema.json",
"prophecy.enabled": true
}

View File

@ -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",

56
app/composer.lock generated
View File

@ -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",

View File

@ -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);
}
]);

View File

@ -18,5 +18,4 @@ class DatabaseConnectionSchema
'password' => Expect::string()->nullable()
]);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Slovocast\Configuration;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
class SessionSchema
{
public static function getSchema(): Schema
{
return Expect::structure([
'name' => 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()
]);
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Slovocast\Controller\Channel;
use Psr\Http\Message\ResponseInterface as Response;
use Slovocast\Controller\Controller;
class CreateChannelPage extends Controller
{
public function respond(): Response
{
// set up the form key
return $this->render('channel/create.twig');
}
}

View File

@ -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']);
}

View File

@ -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']);
}

View File

@ -0,0 +1,28 @@
{% extends 'layouts/skeleton.twig' %}
{% block content %}
<div>
<form action="/channel/create" method="post">
<input name="form_key" type="hidden" value="{{ form_key }}">
<div>
<label for="name">Name<br>
<input name="name" type="text" required>
</div>
<div>
<label for="email">Email<br>
<input name="email" type="text" required>
</div>
<div>
<label for="password">Password<br>
<input name="password" type="password" required>
</div>
<div>
<label for="check_password">Confirm Password<br>
<input name="check_password" type="password" required>
</div>
<div>
<input type="submit" label="Submit">
</div>
</form>
</div>
{% endblock %}