Welcome Guest, Not a member yet? Register   Sign In
Extending a framework (non-core) library
#8

OK, so I thought I'd run this buy you and see if this is right. Haven't actually tried it yet...

In my Config/Services file I copied the session method from system/Config/Services, then replaced "\CodeIgniter\Session\Session" with "\Universal\Auth\Adapters\CI4\SessionExtension" :

PHP Code:
public static function session(\Config\App $config null$getShared true)
{
 
   if ($getShared)
 
   {
 
       return self::getSharedInstance('session'$config);
 
   }

 
   if (! is_object($config))
 
   {
 
       $config config(App::class);
 
   }

 
   $logger self::logger(true);

 
   $driverName $config->sessionDriver;
 
   $driver     = new $driverName($config);
 
   $driver->setLogger($logger);

 
   $session = new \Universal\Auth\Adapters\CI4\SessionExtension($driver$config);
 
   $session->setLogger($logger);

 
   if (session_status() == PHP_SESSION_NONE)
 
   {
 
       $session->start();
 
   }

 
   return $session;


Then my SessionExtension class extends the CI class:

PHP Code:
<?php

namespace Universal\Auth\Adapters\CI4;

use 
CodeIgniter\Session\Session;

class 
SessionExtension extends Session {

    public 
$pre_regenerated_session_id NULL;
    public 
$regenerated_session_id     NULL;

    
/**
     * Class constructor
     */
    
public function __construct(\SessionHandlerInterface $driver$config)
    {
        
parent::__construct($driver$config);
    }

    
// ------------------------------------------------------------------------
    
    /**
     * Regenerates the session ID.
     *
     * @param bool $destroy Should old session data be destroyed?
     */
    
public function regenerate(bool $destroy false)
    {
        
$this->pre_regenerated_session_id session_id();

        
$_SESSION['__ci_last_regenerate'] = time();
        
session_regenerate_id($destroy);

        
$this->regenerated_session_id session_id();

        return 
$this->regenerated_session_id;
    }

    
//--------------------------------------------------------------------



Seems like it would work. I'll be testing in a couple of days when I think I've got it all ready.
Reply


Messages In This Thread
RE: Extending a framework (non-core) library - by skunkbad - 09-16-2018, 09:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB