ezsystems/ezjscore — pull request #12 by jdespatis (2011-12-22 21:18:16+00:00)
Title: upgrade css/js optimizer to ezpEvent logic

The Pull is speaking: "Don't merge me, I'm buggy!"...

It's just a pull to start a discussion, because I have 2 problems with current ezp logic

First and foremost, there's an event response/output to trigger some callbacks whenever the html is pushed to the client, thanks to ezpEvent

This feature is really nice, and even so nice that it may be interesting to put those ezpEvent everywhere!

And why not in ezjscore, whenever it wants to push css or js to the client (just like html indeed)?

=> So I would say it would be interesting to create 2 new events: response/outputcss and response/outputjs (or even a more cosmetic response/output/css, response/output/js), just like the current response/output (which could be renamed into response/output/html)

Of course, feel free to tell me if you find first this idea stupid, but even if it is, it's interesting to read below

You can quickly look at the pull to understand how it can easily be done

BUT it's buggy, in fact it's currently impossible to call a filter with more than one argument, which is the value that the filter may alter

1/ Here I find this logic to be too restrictive, it would be nice to call a filter with a value, and maybe another param, for example the context (in this pull, the second param needed would be the packLevel), and in the long run as many params as possible
=> so why not add some logic of func_get_args() in the ezpEvent::filter() function ? the ezpEvent::notify() already supports an array as param where it's possible to push many arguments, but it doesn't alter the value, which is what I need here

2/ and second, imagine now this pull is correct (it would if ezpEvent::filter() could support many args). I have still a problem...
Ok, the code would work, it could minify css and js
But imagine a developer wants then to create another extension that bundles custom minifiers for css and js, and he doesn't want the default js/css minifier of ezjscore to be triggered at all

=> how can he/she deletes those lines? :
```Listeners[]=response/outputcss@ezjscCssOptimizer::optimize
Listeners[]=response/outputjs@ezjscJavascriptOptimizer::optimize```

and put his/her classes ?
Of course, it's impossible to do Listeners[]= to empty (because it would empty all callbacks for all filters)
The developer would only want to empty the callbacks triggered by response/outputcss, in order to put his/her callbacks

If the syntax was:
```Listeners[response/outputcss]=ezjscCssOptimizer::optimize```

Then the developer could empty Listeners[response/outputcss] and afterwards put his/her classes. But of course this syntax is too limitative as it's impossible to put more than one callback to an event. It's just to explain the problem I have to tackle with

=> You see a simple solution ?

(the first I can see if for the developer to have his/her extension loaded first, and detach asap all other callbacks for the response/outputcss for example, but not totally sure it would work, because this detach may occur too late, after the foreach of ezpEvent::filter())
Whatever, this trick is more complex then just performing the common Setting[]= to empty the array and feed it from the start

Any idea on this logic for settings Listeners in site.ini ?