8000 [HttpFoundation][Sessions] Removed native save handlers · Pull Request #4454 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation][Sessions] Removed native save handlers #4454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from May 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CHANGELOG
* [BC BREAK] following session options: 'lifetime', 'path', 'domain', 'secure',
'httponly' are now prefixed with cookie_ when dumped to the container
* Added `handler_id` configuration under `session` key to represent `session.handler`
service, defaults to `session.handler.native_file`.
service, defaults to `session.handler.file`.
* Added `gc_maxlifetime`, `gc_probability`, and `gc_divisor` to session
configuration. This means session garbage collection has a
`gc_probability`/`gc_divisor` chance of being run. The `gc_maxlifetime` defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parameter key="session.attribute_bag.class">Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag</parameter>
<parameter key="session.storage.native.class">Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage</parameter>
<parameter key="session.storage.mock_file.class">Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage</parameter>
<parameter key="session.handler.native_file.class">Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler</parameter>
<parameter key="session.handler.file.class">Symfony\Component\HttpFoundation\Session\Storage\Handler\FileSessionHandler</parameter>
<parameter key="session_listener.class">Symfony\Bundle\FrameworkBundle\EventListener\SessionListener</parameter>
</parameters>

Expand All @@ -34,7 +34,7 @@
<argument>%kernel.cache_dir%/sessions</argument>
</service>

<service id="session.handler.native_file" class="%session.handler.native_file.class%" public="false">
<service id="session.handler.file" class="%session.handler.file.class%" public="false">
<argument>%session.save_path%</argument>
</service>

Expand All @@ -45,5 +45,6 @@

<!-- for BC -->
<service id="session.storage.filesystem" alias="session.storage.mock_file" />
<service id="session.handler.native_file" alias="session.handler.file" />
</services>
</container>
5 changes: 1 addition & 4 deletions src/Symfony/Component/HttpFoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ CHANGELOG
* [BC BREAK] Moved all session related classes and interfaces into own namespace, as
`Symfony\Component\HttpFoundation\Session` and renamed classes accordingly.
Session handlers are located in the subnamespace `Symfony\Component\HttpFoundation\Session\Handler`.
* SessionHandlers must implement `\SessionHandlerInterface` or extend from the
`Symfony\Component\HttpFoundation\Storage\Handler\NativeSessionHandler` base class.
* SessionHandlers must implement `\SessionHandlerInterface`.
* Added internal storage driver proxy mechanism for forward compatibility with
PHP 5.4 `\SessionHandler` class.
* Added session handlers for PHP native MongoDb, Memcache, Memcached, Redis and SQLite session
save handlers.
* Added session handlers for custom Memcache, Memcached and Null session save handlers.
* [BC BREAK] Removed `NativeSessionStorage` and replaced with `NativeFileSessionHandler`.
* [BC BREAK] `SessionStorageInterface` methods removed: `write()`, `read()` and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;

/**
* FileSessionHandler.
*
* @author Drak <drak@zikula.org>
*/
class FileSessionHandler implements \SessionHandlerInterface
{
/**
* @var string
*/
private $savePath;

/**
* @var string
*/
private $prefix;

/**
* Constructor.
*
* @param string $savePath Path of directory to save session files.
*/
public function __construct($savePath = null, $prefix = 'sess_')
{
if (null === $savePath) {
$savePath = sys_get_temp_dir();
}

$this->savePath = $savePath;
if (false === is_dir($this->savePath)) {
mkdir($this->savePath, 0777, true);
}

$this->prefix = $prefix;
}

/**
* {@inheritdoc]
*/
public function open($savePath, $sessionName)
{
return true;
}

/**
* {@inheritdoc]
*/
public function close()
{
return true;
}

/**
* {@inheritdoc]
*/
public function read($id)
{
$file = $this->getPath().$id;

return is_readable($file) ? file_get_contents($file) : '';
}

/**
* {@inheritdoc]
*/
public function write($id, $data)
{
return false === file_put_contents($this->getPath().$id, $data) ? false : true;
}

/**
* {@inheritdoc]
*/
public function destroy($id)
{
$file = $this->getPath().$id;
if (is_file($file)) {
unlink($file);
}

return true;
}

/**
* {@inheritdoc]
*/
public function gc($maxlifetime)
{
foreach (glob($this->getPath().'*') as $file) {
if ((filemtime($file) + $maxlifetime) < time()) {
unlink($file);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone is using the global temp folder and that contains sessions from other system users that are under different uid/gid?
Should be silenced?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would postulate they should not be using a shared folder for this. The code only scans for sess_* and the other alternative is to change the session file prefix. I wouldn't silence here as you it would simply hide stuff that should not be happening (due to bad configuration).

}
}

return true;
}

private function getPath()
{
return $this->savePath.'/'.$this->prefix;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
0