Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
Removed the Session component
Browse files Browse the repository at this point in the history
  • Loading branch information
o-alquimista committed Oct 8, 2020
1 parent 3e6e6ef commit 2687353
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 352 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ It has its own router component and is heavily inspired by [Symfony](https://sym

2. Configure your web server so that its root directory is `<your-project-name>/public` and the fallback resource is `index.php`.

3. Make sure the timezone is set in your PHP configuration, or else the Session component will misbehave:
```
[Date]
date.timezone = UTC
```

4. Create `/config/pdo.ini` with the following lines to configure database connection details:
3. Create `/config/pdo.ini` with the following lines to configure database connection details:
```
driver = mysql
host = localhost
Expand All @@ -31,7 +25,7 @@ username = example
password = example
```

5. Add routes in the file `/config/routes.xml` and start building your first controller at `/src/Controller/`. You can also try our [Fragments application](https://github.com/o-alquimista/fragments-app) to get an idea of how things work.
4. Add routes in the file `/config/routes.xml` and start building your first controller at `/src/Controller/`. You can also try our [Fragments application](https://github.com/o-alquimista/fragments-app) to get an idea of how things work.

## License
Copyright 2019-2020 Douglas Silva (0x9fd287d56ec107ac)
Expand Down
18 changes: 5 additions & 13 deletions src/Fragments/Component/CsrfTokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

namespace Fragments\Component;

use Fragments\Component\SessionManagement\Session;
use Fragments\Bundle\Exception\AccessDeniedHttpException;

/**
Expand All @@ -31,13 +30,6 @@ class CsrfTokenManager
{
private const PREFIX = '_csrf/';

private $session;

public function __construct()
{
$this->session = new Session;
}

/**
* Get a new CSRF token.
*
Expand All @@ -47,12 +39,12 @@ public function getToken(string $id): string
{
$tokenName = self::PREFIX . $id;

if ($this->session->exists($tokenName)) {
return $this->session->get($tokenName);
if (isset($_SESSION[$tokenName])) {
return $_SESSION[$tokenName];
}

$value = $this->generate();
$this->session->set($tokenName, $value);
$_SESSION[$tokenName] = $value;

return $value;
}
Expand All @@ -64,11 +56,11 @@ public function isTokenValid(string $tokenReceived, string $targetId): bool
{
$targetId = self::PREFIX . $targetId;

if (false === $this->session->exists($targetId)) {
if (!isset($_SESSION[$targetId])) {
throw new AccessDeniedHttpException('The CSRF token identifier could not be found.');
}

$tokenStored = $this->session->get($targetId);
$tokenStored = $_SESSION[$targetId];
$tokenValid = hash_equals($tokenStored, $tokenReceived);

if ($tokenValid) {
Expand Down
20 changes: 7 additions & 13 deletions src/Fragments/Component/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,15 @@

namespace Fragments\Component;

use Fragments\Component\SessionManagement\Session;

class Feedback
{
private const BAG_NAME = 'feedbackBag';

private $session;
const BAG_NAME = 'feedbackBag';

public function __construct()
{
$this->session = new Session;

// If the bag doesn't exist yet, create it
if (false === $this->session->exists(self::BAG_NAME)) {
$this->session->set(self::BAG_NAME, []);
if (false === isset($_SESSION[self::BAG_NAME])) {
$_SESSION[self::BAG_NAME] = [];
}
}

Expand All @@ -44,18 +38,18 @@ public function __construct()
*/
public function add(string $type, string $message)
{
$bag = $this->session->get(self::BAG_NAME);
$bag = $_SESSION[self::BAG_NAME];
$bag[$type][] = $message;
$this->session->set(self::BAG_NAME, $bag);
$_SESSION[self::BAG_NAME] = $bag;
}

/**
* Retrieve all feedback messages at once and delete them.
*/
public function get(): array
{
$bag = $this->session->get(self::BAG_NAME);
$this->session->set(self::BAG_NAME, []);
$bag = $_SESSION[self::BAG_NAME];
$_SESSION[self::BAG_NAME] = [];

return $bag;
}
Expand Down

This file was deleted.

35 changes: 0 additions & 35 deletions src/Fragments/Component/SessionManagement/Init/SessionStrict.php

This file was deleted.

35 changes: 0 additions & 35 deletions src/Fragments/Component/SessionManagement/Init/SessionUnsafe.php

This file was deleted.

Loading

0 comments on commit 2687353

Please sign in to comment.