Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Adding 3rd party libraries
  • What's the accepted place for adding a 3rd party library? It's not really a package, and to me it doesn't really fit in classes since the classes dir more or less seems to be for extending core classes. So where would you guys recommend putting it? I am more or less intending to make a wrapper around IPBWI to handle logins and other things. Eventually I'll be using part of this to create an Auth Driver, and I'll probably be using it with my models as well.
  • No matter where you want to put it, it needs to comply with the Fuel file and class naming rules. Which is virtually never the case with 3rd party classes. Since you have to modify the code anyway, and write a wrapper, the best place is in the packages folder.
  • Thanks. Once again, great framework.. :D
  • Okay, I've actually rewritten IPBWI so that it now has the right file structure and naming convention. It's actually a proper package now. It works beautifully. I'm now onto the auth driver creation part of things. Now I need a way to instantiate the package class only one time inside of my driver. Is this possible?
  • Not sure what you mean. Normally, you have a base class that uses one more drivers. The base class can have a static _init() method, which is called when the class is loaded by the autoloader. If you want you can use that to load a (default) driver, create an instance, etc. This way you don't load the driver and create the instance before the base class is loaded, so only when you now you're going to need it. You have have a peek at for example the Session or Cache class, which do something similar.
  • Unfortunately, both the Session and Cache classes are using a __construct method, not a static _init method, so they aren't good examples of what I'm trying to accomplish. I can't initialize class vars inside of a static method, and I don't think I want to use a static var to store this either. I basically want to instantiate my package's class and then save the instantiated object as a property of my driver class. Thoughts?
  • It's difficult to answer without knowing what the code looks like. For classes with a single driver instance, you would do something like
    class Baseclass
    {
        protected static $instance = null;
    
        public static function _init()
        {
            // load your class driver here
            $driver = 'Driver_Class_Name';
    
            static::$instance = new $driver;
        }
    
        public static function classmethod()
        {
            return static::$instance->drivermethod();
        }
    }
    
    Classes with multiple instances use a factory() method to generate and return the instance, and optionally an instance() method to return a previously instantiated driver object.

Howdy, Stranger!

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

In this Discussion