Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#620 closed New feature (fixed)

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

Reported by: matt Owned by: vipsoft
Priority: major Milestone: Piwik 0.4.1
Component: Core Keywords:
Cc: Sensitive:

Description (last modified by matt)

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.

Change History (14)

comment:1 Changed 5 years ago by matt (mattab)

  • Description modified (diff)

comment:2 Changed 5 years ago by vipsoft (robocoder)

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();

comment:3 Changed 5 years ago by vipsoft (robocoder)

  • Summary changed from Piwik should use autoload to automatically load all classes intead of using require_once to Piwik should use autoload (lazy load) classes instead of using require_once

comment:4 Changed 5 years ago by vipsoft (robocoder)

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

comment:5 Changed 5 years ago by matt (mattab)

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.

comment:6 Changed 5 years ago by sunrise

comment:7 Changed 5 years ago by vipsoft (robocoder)

  • Owner set to vipsoft
  • Status changed from new to assigned

comment:8 Changed 5 years ago by vipsoft (robocoder)

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

comment:9 Changed 5 years ago by vipsoft (robocoder)

  • Milestone changed from 3- Surviving The Wild to 1 - Piwik 0.4.1

comment:10 Changed 5 years ago by vipsoft (robocoder)

  • Resolution set to fixed
  • Status changed from assigned to closed

(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

comment:11 Changed 5 years ago by vipsoft (robocoder)

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

comment:12 Changed 5 years ago by vipsoft (robocoder)

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

comment:13 Changed 5 years ago by alivenk

comment:14 Changed 5 years ago by domtop

Note: See TracTickets for help on using tickets.