Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Wrap 3rd Party library into package without modifying existing code
  • I would like to use 3rd party library in my project.
    In order to wrap it into package, I need to put all of its classes into namespace, but I would like to avoid modifying that library files to ease its updating.
    Is there any way to accomplish this?
  • So, there is no way to wrap it into package without modifying files?
  • You could add all the classnames and their paths manually to a package bootstrap file, that would work fine as well. But the bottom line is that if it doesn't keep to the fuel filesystem rules its not really a Fuel package and thus would have a better place in the vendor dir (which is why we added it in the first place).
  • Jemler, thank you for your responses.
    I understand way with vendor folder, but I really would like to keep 3rd party libraries in pacakage dir.
    I have ended with putting files into library folder of package.
    I have also created wrapper for that library to put its class into namespace and make it availble for autoloading. Library that I am using only have one class.
    <?php
    // packages/geoloqi/classes/sdk.php
    namespace Geoloqi;
    require_once realpath(__DIR__ . '/../library/geoloqi.php');
    class_alias('\Geoloqi', 'Geoloqi\SDK');
    
    My only concern that library class still available in global namespace, but I don't see a way to fix that without using eval.
  • Best solution is often: put it in app/vendor/lib-name and require its autoloader or init file manually with a normal require.

Howdy, Stranger!

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

In this Discussion