Welcome Guest, Not a member yet? Register   Sign In
HMVC loading driver across modules
#1

Have the following (simplified) setup:

/modules/backend/libraries/Queue/Queue.php
/modules/backend/libraries/Queue/drivers/Queue_a.php
/modules/backend/libraries/Queue/drivers/Queue_b.php

/modules/admin/controllers/Test.php

Am attempting to use Queue driver library inside of Test controller - ie across modules.
The basic load of driver library works, but the driver library is unable to find/load its child drivers/drivername.


This works in Test.php if Queue::add is a stub (ie not doing anything)

PHP Code:
function test()
{
   
$this->load->library('backend/queue','queue');
   
$this->queue->add('test message');



But, when the library then tries to load an individual driver (e.g. to add an item into a queue), the load fails: (in Queue/Queue.php)

PHP Code:
function add($payload='')
{
   
//...ignore code that picks which driver to use - assume its queue_a
   
$this->queue_a->add_message($payload); //this fails, Queue_a.php cannot be found to load


The problem seems to be that HMVC overrides the core Loader.php file - but the code in core/libraries/Driver.php that locates individual driver child classes is not HMVC aware, and does not use the Loader class.

My first thought for solution is to extend core/libraries/Driver.php in new file MX_Driver.php:

PHP Code:
public function __get($child)
{
 
   //establish path of child driver     
    
$lib_name get_class($this);
 
   $reflector = new ReflectionClass($lib_name);
 
   $class_path  dirname($reflector->getFileName());
 
   $lib_path dirname($class_path);
 
   $module_path dirname($lib_path);

    
//temp add the path for CI loader to find
 
   $this->CI->load->add_package_path($module_path);
 
   // Try to load the driver
 
   return $this->load_driver($child);
 
   // Reset things to clean up
 
   $this->load->remove_package_path($module_path);




Have a feeling this has been solved before however?
Reply


Messages In This Thread
HMVC loading driver across modules - by reanvdm - 04-22-2016, 08:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB