dwoo-project / dwoo

[UNMAINTAINED] php template engine
http://dwoo.org
GNU Lesser General Public License v3.0
167 stars 58 forks source link

new compiler bypasses loader for plugins #11

Closed themightychris closed 7 years ago

themightychris commented 10 years ago

I'm working on porting an application from Dwoo 1 to Dwoo 2 and have run into the problem that the Compiler has a lot of hard-coded references to filesystem locations in its plugin handling. getPluginType specifically is causing me problems.

My application is loaded dynamically and not served from a traditional filesystem tree, and in Dwoo 1 I was able to just implement a custom ILoader to handle loading plugins. The compiler seems to step on the Loader's toes a lot now and makes assumptions about here to find the built-in plugins.

I can work on tackling this myself but was wondering if you had any high-level feedback first on how the compiler might more fully delegate plugin handling to the loader?

emulienfou commented 10 years ago

Can you show me an example of you code working on Dwoo 1. I think this part is not working yet in Dwoo 2, but i just want to see what you try to do ?

Thanks

themightychris commented 10 years ago

The code I had working in Dwoo 1 isn't that interesting, basically just:

<?php

class My_Dwoo_Loader implements Dwoo_ILoader
{
    public function loadPlugin($class, $forceRehash = true)
    {
        // some irrelevant voodoo here
        $pluginPath = '/tmp/some/place/1234';

        require($pluginPath);
    }
}

$Dwoo->getLoader()->loadPlugin() gets a plugin name and by the time it returns that plugin is defined. That part still works fine in Dwoo 2

My problem is that various methods in Dwoo\Compiler try to root around inside Core::DWOO_DIRECTORY to determine things about the built-in plugins without going through the Loader. My framework is loading Dwoo\Core (and all other classes) from a dynamically compiled cache and Dwoo can't assume that the full original package tree is on disk relative to the file Dwoo\Core was loaded from.

My next step would be to override all the infringing ICompiler methods, but I think it would be better if the compiler delegated these responsibilities entirely to the Loader like Dwoo 1... maybe by adding an additional method to ILoader for getting plugin metadata if needed

emulienfou commented 10 years ago

Hi, i understand what are your tying to do but this does not work anymore for Dwoo. In Dwoo 2 all the plugins are part of the Dwoo library so you cannot change or move the plugins directory.

Otherwise you can add new plugins located in an other directory (in you framework; for example) by telling Dwoo where to load them. To do that, in my own framework i create a function to do what you want, in near future I adding this code inside Dwoo, the code is available inside the setPluginDirectory method.

Best regards