Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 4 extend core class process clarification
#3

(This post was last modified: 04-09-2024, 09:37 AM by Semsion.)

Thank you for your response, but the new session file / function still isn't being hit. Please see the changes made below and advise if you meant another way.

app/Libraries/Session.php is now just a clone of vendor/codeigniter4/framework/system/Session/Session.php - but with the namespace App\Libraries, and some debug added for testing (a var_dump in the get function, triggered by running vendor/bin/phpunit in the terminal, which calls get() via a unit test).

app/Config/Services.php now looks like the below (the forum code formatter appears broken on responses):

PHP Code:
namespace Config;

 use 
CodeIgniter\Config\BaseService;
 
// use App\Libraries\Session;
 
use Config\Session as SessionConfig;
 use 
Config\Services as AppServices;
 use 
CodeIgniter\Session\Handlers\DatabaseHandler;
 use 
CodeIgniter\Session\Handlers\Database\MySQLiHandler;
 use 
CodeIgniter\Session\Handlers\Database\PostgreHandler;

 class 
Services extends BaseService
 
{
 public static function 
get($getShared true)
 {
 if (
$getShared) {
 return static::
getSharedInstance('get');
 }

 
$config ??= config(SessionConfig::class);

 
$logger AppServices::logger();

 
$driverName $config->driver;

 if (
$driverName === DatabaseHandler::class) {
 
$DBGroup $config->DBGroup ?? config(Database::class)->defaultGroup;
 
$db Database::connect($DBGroup);

 
$driver $db->getPlatform();

 if (
$driver === 'MySQLi') {
 
$driverName MySQLiHandler::class;
 } elseif (
$driver === 'Postgre') {
 
$driverName PostgreHandler::class;
 }
 }

 
$driver = new $driverName($configAppServices::request()->getIPAddress());
 
$driver->setLogger($logger);

 return new \
App\Libraries\Session($driver, new SessionConfig());
 } 
Reply


Messages In This Thread
RE: Codeigniter 4 extend core class process clarification - by Semsion - 04-09-2024, 09:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB