1
0
mirror of https://github.com/flarum/core.git synced 2025-10-11 15:04:25 +02:00
Files
php-flarum/src/Http/AbstractServer.php
Toby Zerner 387109002e Rework sessions, remember cookies, and auth again
- Use Symfony's Session component to work with sessions, instead of a custom database model. Separate the concept of access tokens from sessions once again.
- Extract common session/remember cookie logic into SessionAuthenticator and Rememberer classes.
- Extract AuthenticateUserTrait into a new AuthenticationResponseFactory class.
- Fix forgot password process.
2015-12-05 15:11:25 +10:30

56 lines
1.2 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Http;
use Flarum\Foundation\Application;
use Zend\Diactoros\Server;
use Flarum\Foundation\AbstractServer as BaseAbstractServer;
use Zend\Stratigility\MiddlewareInterface;
abstract class AbstractServer extends BaseAbstractServer
{
public function listen()
{
$app = $this->getApp();
$this->collectGarbage($app);
$server = Server::createServer(
$this->getMiddleware($app),
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$server->listen();
}
/**
* @param Application $app
* @return MiddlewareInterface
*/
abstract protected function getMiddleware(Application $app);
private function collectGarbage()
{
if ($this->hitsLottery()) {
AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete();
}
}
private function hitsLottery()
{
return mt_rand(1, 100) <= 2;
}
}