Search code examples
javascriptphpelfinder

elFinder override 'rm' PHP


I am using elFinder to manage assets for a web site and it's default functionality works great; however I need to add some additional logic to several of the PHP functions which resides in on of my Controllers.

The place that I would like the logic to be added is <elfinder_Dir>/PHP/elFinderVolumeLocalFileSystem.php specifically in the function _unlink($path) before a file is actually removed I would like to call out to another class to destroy the database entries for this asset.

The original function looks like this:

protected function _unlink($path) {
    return @unlink($path);
} 

When I try to add code like the following:

protected function _unlink($path) {
    var_dump($path);
    return @unlink($path);
} 

OR

//top of file...
use controllers\ResourceManager;

//OR
//include <pathToResourceManager>

//...

protected function _unlink($path) {
    ResourceManager::delteFromDB();
    return @unlink($path);
}

I receive this alert on the screen:

MalformedBackend

I also noticed that when that message is given, the header in my "Network" tab shows a Response Header Content-type of text/html instead of application/json as expected by the JS portion of elFinder.

Why is the header Content-type being changed when I add custom logic? Is there a better way to add this functionality to the project?


Solution

  • The answer to my question turned out to be pretty straight forward.

    1) error_reporting(0); was squashing all of my errors related to using the proper namespace-ing for my files, I changed this to error_reporting(E_ALL) so I could see the real problem.

    2) The files needed to be added to a namespace, since I used the same namespace I did not have any extra include_once() calls.

    Next I had to add replace this line:

    $class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : '');
    

    With:

    $class = __NAMESPACE__ . '\\elFinderVolume'.(isset($o['driver']) ? $o['driver'] : '');
    

    Which allows the driver (which is now in the namespace) to be loaded properly.

    Once these changes were made, all is well, I can add my own logic where I please.