Arbit - project tracking

Dwoo

#66: How to write plugins

Issue revisions

  • new by emanuel at 2010-M-23 13:05
  • closed by Jordi Boggiano at 2010-M-24 12:18
  • closed by Jordi Boggiano at 2010-M-24 12:20
Type support support
State closed closed
Priority low low
Resolution fixed fixed
Assigned to Nobody
Scheduled for
Affected versions 1.1.1
Affected components Plugins
Last change Wednesday 24 March 2010 12:20:34 UTC by Jordi Boggiano
Short description
-----------------

1. Can I put my plugin outside of plugins/personal directory?

I will like to have application specific plugins.


2. The class name of plugin must start with "Dwoo_"?

I want to use a name like AppName_
Maybe you can implement something like Zend Framework 
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_ROOT_PATH . '/library/AppName/Controller/Action/Helper', 'AppName_Controller_Action_Helper');


3. I want to write a plugin that is extending foreach plugin... but to have different paramteres... I run PHP in strict mode and I getting an warning that I should have the same parameters. Can you tell me what is the best way to extend a plugin:

    public function init($from, $id, $parent=0, $offset=-1, $count=0, $item=null, $name='default', $implode=null) {
        parent::init($from, null, $item, $name, $implode);
    }
  • Jordi Boggiano at Wednesday 24 March 2010 12:18:50 UTC

    1. Yes, you can use $dwoo->getLoader()->addPluginDirectory() to add other directories to the autoloaded plugin paths. It will scan all files though so those directories should only contain dwoo plugins, and files must be called funcName.php

    2. No, but it's easier if it does since Dwoo will autoload those from the plugin directories.

    For function-plugins, they can be called just function foo() and you can call them from the templates, for block plugins and plugins written as classes, it's more tricky.

    Check out http://wiki.dwoo.org/index.php/WritingPlugins for default naming docs, if you want to name them differently, you need to either implement your own Dwoo_Loader that will load them automatically, or you need to add them all by hand to the Dwoo instance with $dwoo->addPlugin, see http://dwoo.org/_phpdoc/Dwoo/Dwoo.html#addPlugin

    1. Extending foreach is really difficult if you don't have a good understanding of what's happening at compile time. Maybe you can write a plugin that will manipulate an array so you call use it together with foreach like: {foreach transform($array) foo}{$foo.bar}{/foreach} ? Extending plugins is a bit tricky because of the function signature since php in strict mode complains about that, you can however copy it in your own plugin directory and even call it foreach and it will override the default dwoo one.

    I hope this helps.

  • Jordi Boggiano at Wednesday 24 March 2010 12:20:34 UTC

    Trying to fix the markup of the original post

  • emanuel at Friday 26 March 2010 06:19:46 UTC

    Thank you Jordi... this was very helpful. For extension of foreach: I had copy & paste from foreach plugin and modified a lot... (I needed 2 nested foreach so in the final extending was not an option).

  • emanuel at Friday 26 March 2010 08:57:16 UTC

    One note... $dwoo->getLoader()->addPluginDirectory() should be $dwoo->getLoader()->addDirectory()

    Also if anybody is using Dwoo_Adapters_ZendFramework_View you can get the loader by doing $viewAdapter->getEngine()->getLoader()