Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit a71acbd

Browse files
committed
👌 improve Session functionality for PHP8
Signed-off-by: otengkwame <[email protected]>
1 parent c725d73 commit a71acbd

File tree

11 files changed

+662
-647
lines changed

11 files changed

+662
-647
lines changed

framework/libraries/Session/SessionHandlerInterface.php renamed to framework/libraries/Session/CI_Session_driver_interface.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
23
/**
34
* CodeIgniter
45
*
56
* An open source application development framework for PHP
67
*
78
* This content is released under the MIT License (MIT)
89
*
9-
* Copyright (c) 2014 - 2019, British Columbia Institute of Technology
10+
* Copyright (c) 2022, CodeIgniter Foundation
1011
*
1112
* Permission is hereby granted, free of charge, to any person obtaining a copy
1213
* of this software and associated documentation files (the "Software"), to deal
@@ -28,27 +29,27 @@
2829
*
2930
* @package CodeIgniter
3031
* @author EllisLab Dev Team
31-
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32-
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (http://bcit.ca/)
32+
* @copyright Copyright (c) 2022, CodeIgniter Foundation (https://codeigniter.com/)
3333
* @license http://opensource.org/licenses/MIT MIT License
3434
* @link https://codeigniter.com
3535
* @since Version 3.0.0
3636
* @filesource
3737
*/
38-
defined('BASEPATH') OR exit('No direct script access allowed');
38+
defined('BASEPATH') or exit('No direct script access allowed');
3939

4040
/**
41-
* SessionHandlerInterface
41+
* CI_Session_driver_interface
4242
*
43-
* PHP 5.4 compatibility interface
43+
* A compatibility typeless SessionHandlerInterface alias
4444
*
4545
* @package CodeIgniter
4646
* @subpackage Libraries
4747
* @category Sessions
4848
* @author Andrey Andreev
4949
* @link https://codeigniter.com/userguide3/libraries/sessions.html
5050
*/
51-
interface SessionHandlerInterface {
51+
interface CI_Session_driver_interface
52+
{
5253

5354
public function open($save_path, $name);
5455
public function close();
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/**
4+
* CodeIgniter
5+
*
6+
* An open source application development framework for PHP
7+
*
8+
* This content is released under the MIT License (MIT)
9+
*
10+
* Copyright (c) 2022, CodeIgniter Foundation
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining a copy
13+
* of this software and associated documentation files (the "Software"), to deal
14+
* in the Software without restriction, including without limitation the rights
15+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the Software is
17+
* furnished to do so, subject to the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be included in
20+
* all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28+
* THE SOFTWARE.
29+
*
30+
* @package CodeIgniter
31+
* @author EllisLab Dev Team
32+
* @copyright Copyright (c) 2022, CodeIgniter Foundation (https://codeigniter.com/)
33+
* @license http://opensource.org/licenses/MIT MIT License
34+
* @link https://codeigniter.com
35+
* @since Version 3.0.0
36+
* @filesource
37+
*/
38+
defined('BASEPATH') or exit('No direct script access allowed');
39+
40+
/**
41+
* OldSessionWrapper
42+
*
43+
* PHP 8 Session handler compatibility wrapper, pre-PHP8 version
44+
*
45+
* @package CodeIgniter
46+
* @subpackage Libraries
47+
* @category Sessions
48+
* @author Andrey Andreev
49+
* @link https://codeigniter.com/userguide3/libraries/sessions.html
50+
*/
51+
class CI_SessionWrapper implements SessionHandlerInterface
52+
{
53+
54+
protected $driver;
55+
56+
public function __construct(CI_Session_driver_interface $driver)
57+
{
58+
$this->driver = $driver;
59+
}
60+
61+
public function open($save_path, $name)
62+
{
63+
return $this->driver->open($save_path, $name);
64+
}
65+
66+
public function close()
67+
{
68+
return $this->driver->close();
69+
}
70+
71+
public function read($id)
72+
{
73+
return $this->driver->read($id);
74+
}
75+
76+
public function write($id, $data)
77+
{
78+
return $this->driver->write($id, $data);
79+
}
80+
81+
public function destroy($id)
82+
{
83+
return $this->driver->destroy($id);
84+
}
85+
86+
public function gc($maxlifetime)
87+
{
88+
return $this->driver->gc($maxlifetime);
89+
}
90+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
/**
4+
* CodeIgniter
5+
*
6+
* An open source application development framework for PHP
7+
*
8+
* This content is released under the MIT License (MIT)
9+
*
10+
* Copyright (c) 2022, CodeIgniter Foundation
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining a copy
13+
* of this software and associated documentation files (the "Software"), to deal
14+
* in the Software without restriction, including without limitation the rights
15+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the Software is
17+
* furnished to do so, subject to the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be included in
20+
* all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28+
* THE SOFTWARE.
29+
*
30+
* @package CodeIgniter
31+
* @author EllisLab Dev Team
32+
* @copyright Copyright (c) 2022, CodeIgniter Foundation (https://codeigniter.com/)
33+
* @license http://opensource.org/licenses/MIT MIT License
34+
* @link https://codeigniter.com
35+
* @since Version 3.0.0
36+
* @filesource
37+
*/
38+
defined('BASEPATH') or exit('No direct script access allowed');
39+
40+
/**
41+
* PHP8SessionWrapper
42+
*
43+
* PHP 8 Session handler compatibility wrapper
44+
*
45+
* @package CodeIgniter
46+
* @subpackage Libraries
47+
* @category Sessions
48+
* @author Andrey Andreev
49+
* @link https://codeigniter.com/userguide3/libraries/sessions.html
50+
*/
51+
class CI_SessionWrapper implements SessionHandlerInterface
52+
{
53+
54+
protected CI_Session_driver_interface $driver;
55+
56+
public function __construct(CI_Session_driver_interface $driver)
57+
{
58+
$this->driver = $driver;
59+
}
60+
61+
public function open(string $save_path, string $name): bool
62+
{
63+
return $this->driver->open($save_path, $name);
64+
}
65+
66+
public function close(): bool
67+
{
68+
return $this->driver->close();
69+
}
70+
71+
#[\ReturnTypeWillChange]
72+
public function read(string $id): mixed
73+
{
74+
return $this->driver->read($id);
75+
}
76+
77+
public function write(string $id, string $data): bool
78+
{
79+
return $this->driver->write($id, $data);
80+
}
81+
82+
public function destroy(string $id): bool
83+
{
84+
return $this->driver->destroy($id);
85+
}
86+
87+
#[\ReturnTypeWillChange]
88+
public function gc(int $maxlifetime): mixed
89+
{
90+
return $this->driver->gc($maxlifetime);
91+
}
92+
}

0 commit comments

Comments
 (0)