Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Extending Email Package
  • I've tried extending the email package both from the /app/classes and /packages/mypackage folders but can't seem to get my head around the name spacing. My intention is to extend the functionality of the original Email class so that it can be used exactly as it would normally. I.e. $email = \Email::forge(); as opposed to $email = \MyEmail::forge(); therefore allowing the application to work with or without the additional functionality I wish to add. I have achieved the same with the \Log class with no problems so I suspect the problem is the fact that it's a package I'm trying to extend which is the problem. My aim with the email package is to add to the functionality of Email_Driver::send() but I keep finding myself with class not found fatal errors. For example, extending it from /app/classes and including in /app/bootstrap.php using
    abstract class Email_Driver extends \Email\Email_Driver
    

    I get the following
    ErrorException [ Error ]: Class 'Email\Email_Driver' not found
    

    Clearly I'm doing something wrong and misunderstanding the namespaces so if someone could point me int he right direction for both extending from the /app/classes folder and the /packages/mypackage folders that'd be massively appreciated. Ben
  • As for the /app/classes directory, I realised my mistake. I'd left the bootstrap.php add_classes() call as 'Email' as opposed to 'Email_Driver'!
    Autoloader::add_classes(array(
     // Add classes you want to override here
     'Email_Driver' => APPPATH.'classes/email.php',
    ));
    

    Anyway, if someone could explain how to extend the email package from a package that'd be much appreciated!
  • I have manged to sort this with the help of Frank de Jonge on IRC! The problem was such that I was loading the Email package too late and therefore it wasn't there when I tried to extend it or it was overwriting Email in the \ namespace. The gist is as follows /packages/mypackage/bootstrap.php
    <?php
    
    \Package::load('email'); // This is the important bit which I was missing
    
    Autoloader::add_core_namespace('Mymodule', true);
    
    Autoloader::add_classes(array(
     'Mymodule\\Email_Driver' => __DIR__.'/classes/driver.php',
    ));
    
    /* End of file bootstrap.php */
    

    /packages/mypackage/classes/driver.php
    <?php
    
    namespace Ben;
    
    abstract class Email_Driver extends \Email\Email_Driver {
    
     public static function _init()
     {
      \Debug::dump("it's alive!");
     }
    }
    
    /* End of file driver.php */
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion