Skip to content

Commit aafedde

Browse files
committed
- set the cookie params before the handler creation
1 parent 56022b0 commit aafedde

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

‎functions.php‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
<?php declare(strict_types=1);
2-
32
/*
43
* This file is part of the Koded package.
54
*
65
* (c) Mihail Binev <mihail@kodeart.com>
76
*
87
* Please view the LICENSE distributed with this source code
98
* for the full copyright and license information.
10-
*
119
*/
12-
1310
namespace Koded\Session;
1411

15-
use Koded\Stdlib\Interfaces\ConfigurationFactory;
12+
use Koded\Stdlib\Configuration;
1613
use SessionHandlerInterface;
1714

1815
/**
@@ -26,30 +23,27 @@
2623
function session(Session $instance = null): Session
2724
{
2825
static $session;
29-
3026
if ($instance) {
3127
return $session = $instance;
3228
}
33-
34-
return $session ?? $session = new PhpSession;
29+
return $session ??= new PhpSession;
3530
}
3631

3732
/**
3833
* Creates and registers a new session handler.
3934
*
40-
* @param ConfigurationFactory $configuration
35+
* @param Configuration $configuration
4136
*
4237
* @return SessionConfiguration The session configuration instance
4338
* @throws SessionException
4439
*/
45-
function session_register_custom_handler(ConfigurationFactory $configuration): SessionConfiguration
40+
function session_register_custom_handler(Configuration $configuration): SessionConfiguration
4641
{
4742
$configuration = new SessionConfiguration($configuration);
48-
4943
if (PHP_SESSION_ACTIVE !== session_status()) {
44+
session_set_cookie_params($configuration->cookieParameters());
5045
session_set_save_handler(session_create_custom_handler($configuration), false);
5146
}
52-
5347
return $configuration;
5448
}
5549

@@ -63,10 +57,8 @@ function session_register_custom_handler(ConfigurationFactory $configuration): S
6357
function session_create_custom_handler(SessionConfiguration $configuration): SessionHandlerInterface
6458
{
6559
$handler = __NAMESPACE__ . '\\Handler\\' . ucfirst($configuration->handler()) . 'Handler';
66-
6760
if (false === class_exists($handler, true)) {
68-
throw SessionException::forNotFoundHandler($handler);
61+
throw SessionException::forHandlerNotFound($handler);
6962
}
70-
7163
return new $handler($configuration);
7264
}

0 commit comments

Comments
 (0)