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

Piwik should use autoload (lazy load) classes instead of using require_once #620

Closed
mattab opened this issue Mar 22, 2009 · 7 comments
Closed
Assignees
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Milestone

Comments

@mattab
Copy link
Member

mattab commented Mar 22, 2009

Piwik should use autoload to automatically load the classes.

This would simplify the code, would make loading pages faster, as unecessary includes wouldn’t be loaded, and would greatly increase reusability of the code.

For example, Zend does it via`
Zend_Loader::registerAutoload();`
see the code on http://www.google.com/codesearch/p?hl=en#1oUPVh-C1Wg/trunk/eval/gx/zendframework/library/Zend/Loader.php&q=%22spl_autoload_register(array($class,%27autoload%27))%3B&l=32

Once implemented we can remove all require_once from all .php files.
The includes for the Piwik_\* (core/PluginsFunctions/*) shortcut functions would still be required and could all be merged in one include file.

@robocoder
Copy link
Contributor

Reference: http://www.zendframework.com/manual/en/performance.classloading.html

Suggests it would be as easy as adding this to index.php and piwik.php:

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

@robocoder
Copy link
Contributor

Silly me... RTFM, we would still have to define an autoloader callback to map classes in our namespace to actual files.

@mattab
Copy link
Member Author

mattab commented May 29, 2009

vipsoft, this ticket means:

  • using autoloading for all zend classes (if this is not already the case) by calling their autoloader
  • adding an autoloader in Piwik (can we somehow reuse the zend one?) and keep it as simple as possible (as in zend). This will most likely mean that a few classes will have to be moved/renamed. most classes should be OK as we used a similar structure to the zend structure.

@robocoder
Copy link
Contributor

(In [1220]) refs #620 - class renaming for consistency

@robocoder
Copy link
Contributor

(In [1221]) fixes #801, fixes #620 - implement autoloader; remove require_once
FrontController.php from ./index.php to test autoloader; add "false"
parameter to all class_exists() calls to not trigger autoloader

@robocoder
Copy link
Contributor

Confirming that [1220] was a global search and replace, including tests/*.

@robocoder
Copy link
Contributor

(In [1224]) refs #620, refs #803 - refactor autoloader into core/Loader.php (class
Piwik_Loader); remove unnecessary require_once in core/Common.php

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Projects
None yet
Development

No branches or pull requests

2 participants