Skip to content

Commit

Permalink
#107 - Add temporary extended session adapter class (phalcon/cphalcon…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Sep 1, 2019
1 parent aea0552 commit 5668c32
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/Phalcon/Session/Adapter/Beta2FixStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Phalcon\Session\Adapter;

/**
* Extended class for fixing phalcon/cphalcon#14265 issue
*
* @see https://github.com/phalcon/cphalcon/issues/14265
* @see https://github.com/phalcon/cphalcon/commit/b6132eebb0b4165e8a43d870336b84584208a6f8#diff-7569882dd2736f23d2142a34913e6d7f
*/
final class Beta2FixStream extends Stream
{
public function open($savePath, $sessionName): bool
{
return true;
}
}
33 changes: 27 additions & 6 deletions app/Providers/SessionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

use Phalcon\Di\DiInterface;
use Phalcon\Di\ServiceProviderInterface;
use Phalcon\Session\Adapter\Beta2FixStream;
use Phalcon\Session\Adapter\Noop;
use Phalcon\Session\Adapter\Stream as SessionAdapter;
use Phalcon\Session\Manager as SessionManager;
use Phalcon\Version;
use function Vokuro\config;

class SessionProvider implements ServiceProviderInterface
Expand All @@ -33,17 +36,35 @@ public function register(DiInterface $di): void
{
/** @var string $savePath */
$savePath = config('application.sessionSavePath');
$handler = $this->getSessionAdapter($savePath);

$di->set($this->providerName, function () use ($savePath) {
$files = new SessionAdapter([
'savePath' => $savePath,
]);

$di->set($this->providerName, function () use ($handler) {
$session = new SessionManager();
$session->setHandler($files);
$session->setHandler($handler);
$session->start();

return $session;
});
}

/**
* Remove current method after after next release of Phalcon 4
*
* @see https://github.com/phalcon/cphalcon/issues/14265
*
* @param string $savePath
* @return Noop
*/
protected function getSessionAdapter(string $savePath): Noop
{
$options = [
'savePath' => $savePath,
];

if (Version::get() === '4.0.0-beta.2') {
return new SessionAdapter($options);
}

return new Beta2FixStream($options);
}
}

0 comments on commit 5668c32

Please sign in to comment.