Jump to content

providing 3rd party libraries with plugins


Recommended Posts

Let's say I have several PHP classes (each one in a separate file, located in the '/myPlugin/libs' directory) and I'm using those classes in the plugin hooks (after including them with require_once). However, the external .php files are not included in the plugin's .xml file.

Since those external classes are used in several hooks, I would really like to avoid hardcoding them into each of the hooks. For now, I have to manually upload the 'libs' catalogue via FTP everytime I install the plugin... not very user-friendly, is it? ;)

What is the most elegant and convenient way to include a 3rd party library within a plugin?

Link to comment
Share on other sites

We did this with exec commands in install/upgrade steps. As example

// example
public function step1() {
    $srv = $_SERVER['DOCUMENT_ROOT'];
    $tmp_dir = \sys_get_temp_dir();
    `rm -rf $tmp_dir/plugin_repo_name`;
    `git clone https://user@our.git.server.example.com/project_name/plugin_repo_name.git $tmp_dir/plugin_repo_name`;
    `cp -r $tmp_dir/plugin_repo_name/upload/* $srv/`;

    return true;

So our repo contain plugin_name.xml which we upload when want to install and upload folder, which contain any path, for your example it may be such as:



In this way created a lot of plugins, which need to copy uploads folder via ftp with hands. In our way we do it automatically with setup/upgrade. Ofcouse, if your php settings allow exec function which is not good for secure (in our schema we have nginx location '/admin' which is closed from world and open only for office IP's and backend for this location is different php-fpm daemon with different php.ini settings, which allow exec).

Hope our experience will help you) I am know this way is not clear. But create application type for very simply functionality is not better as i think.

Good example of this working is creating new login handler. Now you can't create login handler file in /system/Login/YourHandler.php via plugin or application. It must be dedical file, not a hook. So, you need to put them manually or with the this method. Additionally you can put your helpful class (LoginOpenId, for example) only to git folder. And all your files guaranteed placed to right places and all will works well.

IPS had many places, which devs must create dedical new files, not a hooks. Other examples is adding new sharer service (we add Vk), create new external widgets and more-more...

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...