Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decide on hook naming convention + update existing hooks #613

Closed
mattab opened this issue Mar 18, 2009 · 10 comments
Closed

Decide on hook naming convention + update existing hooks #613

mattab opened this issue Mar 18, 2009 · 10 comments
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc. Critical Indicates the severity of an issue is very critical and the issue has a very high priority. worksforme The issue cannot be reproduced and things work as intended.

Comments

@mattab
Copy link
Member

mattab commented Mar 18, 2009

We need to decide on a hook naming convention for all Piwik hooks.
At first sight I would propose
- all hooks are either at the start or at the very end of a method. If current hooks are in the middle of a function, code should be refactored to put the hook either at start or end
- hooks are named Class.method for hooks at start of method, or Class.method.end for hooks at end of method.
- how to name hooks that make it possible to “replace” a php class?

Ideally we would generate an automatic documentation that would parse the calls to the Piwik_PostEvent function, and generate a simple page listing all existing hooks, as well as the phpdoc comment above the function call. See #5684

See also [drupal hooks documentation](http://api.drupal.org/api/file/modules/system/system.api.php/7/source)

@robocoder
Copy link
Contributor

isn't this a dupe of #264?

@mattab
Copy link
Member Author

mattab commented Jun 2, 2009

not a blocker for 0.4 but should be done in the next release

@robocoder
Copy link
Contributor

For consistency, I think:

* ArchiveProcessing_Day.compute
* ArchiveProcessing_Period.compute

Should be renamed to:

* ArchiveProcessing.Day.compute
* ArchiveProcessing.Period.compute

@robocoder
Copy link
Contributor

re: comment:5 - this would break third party plugins like GeoIP, UserLanguage, and EntryPage

@robocoder
Copy link
Contributor

re: hook documentation

Assuming it's possible with phpdoc, would it be easier if all standard hooks were defined in one place, e.g.,

class Piwik_Event
{
    /**
     * Authenticate API request
     *
     * @param $token_auth
     * @see Piwik_View::factory()
     * @link https://github.com/piwik/piwik/blob/master/core/API/Request.php#L107
     */
    const API_REQUEST_AUTHENTICATE = 'API.Request.authenticate';

    // ...
}

@mattab
Copy link
Member Author

mattab commented Aug 24, 2009

vipsoft, the problem with pre-defining hooks is that you then have to write them twice in the source code. It is better if you just can add the hook in one line. A simple grep script with pre-defined comment format would do the trick to automatically generate the documentation, wouldn't it - or should we use phpdoc?

@robocoder
Copy link
Contributor

The flip side is that misspelling a hook generates an error; whereas a typo in a string would go undetected.

@mattab
Copy link
Member Author

mattab commented Apr 1, 2010

For the automatic hook documentation, maybe we can use Zend_Reflection docbook retrieval features: http://framework.zend.com/manual/en/zend.reflection.reference.html

@mattab
Copy link
Member Author

mattab commented May 1, 2010

Vipsoft, you are right, your solution would work well, excuse my previous comment.

It would need to work also for hooks triggered in the Plugins code. Plugins can not add their hook to the core hook class, as technically they are loosely coupled. We would also need a way for plugins to define their own hooks, using the same class interface.

This solution would also make it easier to spot names that don't follow the naming standard.

It also makes #264 a lot easier of course, as we just need to parse the core hook class, and all the plugins hook classes.

@mattab
Copy link
Member Author

mattab commented Jul 22, 2010

Hook names make sense in Piwik atm, appart from ArchiveProcessing Anthon pointed out, but already used in plugins. Closing

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Critical Indicates the severity of an issue is very critical and the issue has a very high priority. worksforme The issue cannot be reproduced and things work as intended.
Projects
None yet
Development

No branches or pull requests

2 participants