[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Session Package 4 * 5 * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Session\Handler; 10 11 use Joomla\Session\HandlerInterface; 12 13 /** 14 * Filesystem session storage handler 15 * 16 * @since 2.0.0 17 */ 18 class FilesystemHandler extends \SessionHandler implements HandlerInterface 19 { 20 /** 21 * Constructor 22 * 23 * @param string $path Path of directory to save session files. Leave null to use the PHP configured path. 24 * 25 * @since 2.0.0 26 * @throws \InvalidArgumentException 27 * @throws \RuntimeException 28 */ 29 public function __construct(string $path = '') 30 { 31 $pathConfig = ini_get('session.save_path'); 32 33 // If the paths are empty, then we can't use this handler 34 if (empty($path) && empty($pathConfig)) 35 { 36 throw new \InvalidArgumentException('Invalid argument $path'); 37 } 38 39 // If path is empty or equal to the the PHP configured path, set only the handler and use the PHP path directly 40 if (empty($path) || $path === $pathConfig) 41 { 42 if (!headers_sent()) 43 { 44 ini_set('session.save_handler', 'files'); 45 } 46 47 return; 48 } 49 50 $baseDir = $path; 51 52 if ($count = substr_count($path, ';')) 53 { 54 if ($count > 2) 55 { 56 throw new \InvalidArgumentException(sprintf('Invalid argument $path "%s"', $path)); 57 } 58 59 // Characters after the last semi-colon are the path 60 $baseDir = ltrim(strrchr($path, ';'), ';'); 61 } 62 63 // Create the directory if it doesn't exist 64 if (!is_dir($baseDir)) 65 { 66 if (!mkdir($baseDir, 0755)) 67 { 68 throw new \RuntimeException(sprintf('Could not create session directory "%s"', $baseDir)); 69 } 70 } 71 72 if (!headers_sent()) 73 { 74 ini_set('session.save_path', $path); 75 ini_set('session.save_handler', 'files'); 76 } 77 } 78 79 /** 80 * Test to see if the HandlerInterface is available 81 * 82 * @return boolean True on success, false otherwise 83 * 84 * @since 2.0.0 85 */ 86 public static function isSupported(): bool 87 { 88 return true; 89 } 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |