Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; Chris@0: Chris@0: /** Chris@0: * Native session handler using PHP's built in file storage. Chris@0: * Chris@0: * @author Drak Chris@0: */ Chris@0: class NativeFileSessionHandler extends NativeSessionHandler Chris@0: { Chris@0: /** Chris@0: * @param string $savePath Path of directory to save session files Chris@0: * Default null will leave setting as defined by PHP. Chris@0: * '/path', 'N;/path', or 'N;octal-mode;/path Chris@0: * Chris@0: * @see http://php.net/session.configuration.php#ini.session.save-path for further details. Chris@0: * Chris@0: * @throws \InvalidArgumentException On invalid $savePath Chris@14: * @throws \RuntimeException When failing to create the save directory Chris@0: */ Chris@0: public function __construct($savePath = null) Chris@0: { Chris@0: if (null === $savePath) { Chris@0: $savePath = ini_get('session.save_path'); Chris@0: } Chris@0: Chris@0: $baseDir = $savePath; Chris@0: Chris@0: if ($count = substr_count($savePath, ';')) { Chris@0: if ($count > 2) { Chris@0: throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath)); Chris@0: } Chris@0: Chris@0: // characters after last ';' are the path Chris@0: $baseDir = ltrim(strrchr($savePath, ';'), ';'); Chris@0: } Chris@0: Chris@0: if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) { Chris@0: throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $baseDir)); Chris@0: } Chris@0: Chris@0: ini_set('session.save_path', $savePath); Chris@0: ini_set('session.save_handler', 'files'); Chris@0: } Chris@0: }