diff --git a/core/API/Proxy.php b/core/API/Proxy.php index 43d07bc25f66e5987c73244160eb99e9cbd40c6b..f504bdeb8f608f92a3710f47b770c0c79c58b3be 100644 --- a/core/API/Proxy.php +++ b/core/API/Proxy.php @@ -14,6 +14,7 @@ namespace Piwik\API; use Exception; use Piwik\Common; use Piwik\Piwik; +use Piwik\Singleton; use ReflectionClass; use ReflectionMethod; @@ -28,7 +29,7 @@ use ReflectionMethod; * @package Piwik * @subpackage Piwik_API */ -class Proxy +class Proxy extends Singleton { // array of already registered plugins names protected $alreadyRegistered = array(); @@ -39,12 +40,6 @@ class Proxy // when a parameter doesn't have a default value we use this private $noDefaultValue; - /** - * Singleton instance - * @var \Piwik\API\Proxy|null - */ - static private $instance = null; - /** * protected constructor */ @@ -53,19 +48,6 @@ class Proxy $this->noDefaultValue = new NoDefaultValue(); } - /** - * Singleton, returns instance - * - * @return \Piwik\API\Proxy - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Returns array containing reflection meta data for all the loaded classes * eg. number of parameters, method names, etc. diff --git a/core/Config.php b/core/Config.php index 1ed8ddee47cc874674d2339eeb18c3eff55891fc..c7a5ad9d272b354663841299d74dfbfb744de594 100644 --- a/core/Config.php +++ b/core/Config.php @@ -42,23 +42,8 @@ use Exception; * @package Piwik * @subpackage Piwik_Config */ -class Config +class Config extends Singleton { - private static $instance = null; - - /** - * Returns the singleton Piwik_Config - * - * @return \Piwik\Config - * @api - */ - public static function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } /** * Contains configuration files values @@ -298,7 +283,7 @@ class Config // must be called here, not in init(), since setTestEnvironment() calls init(). (this avoids // infinite recursion) - Piwik::postTestEvent('Config.createConfigSingleton', array(self::$instance)); + Piwik::postTestEvent('Config.createConfigSingleton', array( $this->getInstance() )); } // check cache for merged section diff --git a/core/DataTable/Manager.php b/core/DataTable/Manager.php index b32463b17604f77cf972140a22de6ff632bb280d..0ae03ede891d65190aaf27919779cab901a9a6ba 100644 --- a/core/DataTable/Manager.php +++ b/core/DataTable/Manager.php @@ -14,6 +14,7 @@ namespace Piwik\DataTable; use Exception; use Piwik\Common; use Piwik\DataTable; +use Piwik\Singleton; /** * The DataTable_Manager registers all the instanciated DataTable and provides an @@ -23,23 +24,8 @@ use Piwik\DataTable; * @package Piwik * @subpackage DataTable */ -class Manager +class Manager extends Singleton { - static private $instance = null; - - /** - * Returns instance - * - * @return \Piwik\DataTable\Manager - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Array used to store the DataTable * diff --git a/core/Db/Schema.php b/core/Db/Schema.php index 015899928c722335322b6093bbad7a32028a7be3..5ce1d55d622cb6f6412352c7405fa5f7a4838fdc 100644 --- a/core/Db/Schema.php +++ b/core/Db/Schema.php @@ -11,6 +11,7 @@ namespace Piwik\Db; use Piwik\Config; +use Piwik\Singleton; /** * Schema abstraction @@ -20,14 +21,8 @@ use Piwik\Config; * @package Piwik * @subpackage Piwik_Db */ -class Schema +class Schema extends Singleton { - /** - * Singleton instance - * - * @var \Piwik\Db\Schema - */ - static private $instance = null; /** * Type of database schema @@ -36,18 +31,6 @@ class Schema */ private $schema = null; - /** - * Returns the singleton Schema - * - * @return \Piwik\Db\Schema - */ - static public function getInstance() - { - if (self::$instance === null) { - self::$instance = new self; - } - return self::$instance; - } /** * Get schema class name diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php index 66cef418efe3b27cf41bc5a9b4d0add33798ab82..c57cea990edcabf1de6d4210407e83514b997e51 100644 --- a/core/EventDispatcher.php +++ b/core/EventDispatcher.php @@ -17,29 +17,13 @@ use Piwik\Plugin; * This class allows code to post events from anywhere in Piwik and for * plugins to associate callbacks to be executed when events are posted. */ -class EventDispatcher +class EventDispatcher extends Singleton { // implementation details for postEvent const EVENT_CALLBACK_GROUP_FIRST = 0; const EVENT_CALLBACK_GROUP_SECOND = 1; const EVENT_CALLBACK_GROUP_THIRD = 2; - /** - * Singleton instance. - */ - private static $instance = null; - - /** - * Returns the singleton EventDispatcher instance. Creates it if necessary. - */ - public static function getInstance() - { - if (self::$instance === null) { - self::$instance = new EventDispatcher(); - } - return self::$instance; - } - /** * Array of observers (callbacks attached to events) that are not methods * of plugin classes. diff --git a/core/FrontController.php b/core/FrontController.php index f93a607ee9a28c17bd0f35da3351ca92544139b0..8b42c87a9850a04da3c77dbfd6352be963ef0e0a 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -27,7 +27,7 @@ use Piwik\Session; * @package Piwik * @subpackage FrontController */ -class FrontController +class FrontController extends Singleton { /** * Set to false and the Front Controller will not dispatch the request @@ -36,8 +36,6 @@ class FrontController */ public static $enableDispatch = true; - private static $instance = null; - protected function prepareDispatch($module, $action, $parameters) { if (is_null($module)) { @@ -91,19 +89,6 @@ class FrontController return array($module, $action, $parameters, $controller); } - /** - * returns singleton - * - * @return \Piwik\FrontController - */ - public static function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Dispatches the request to the right plugin and executes the requested action on the plugin controller. * diff --git a/core/Log.php b/core/Log.php index 026f63c839c510c66ca1115f14260d5038e386a3..23017acd59404708b7b0c7891736446a13acc568 100644 --- a/core/Log.php +++ b/core/Log.php @@ -26,7 +26,7 @@ use Piwik\Db; * The logging utility can be configured by manipulating the INI config options in the * [log] section. */ -class Log +class Log extends Singleton { // log levels const NONE = 0; @@ -50,35 +50,6 @@ class Log const GET_AVAILABLE_WRITERS_EVENT = 'Log.getAvailableWriters'; - /** - * The singleton Log instance. - * - * @var Log - */ - private static $instance = null; - - /** - * Returns the singleton Log instance or creates it if it doesn't exist. - * - * @return Log - */ - public static function getInstance() - { - if (self::$instance === null) { - self::$instance = new Log(); - } - return self::$instance; - } - - /** - * Unsets the singleton instance so it will be re-created the next time getInstance() is - * called. For testing purposes only. - */ - public static function clearInstance() - { - self::$instance = null; - } - /** * The current logging level. Everything of equal or greater priority will be logged. * Everything else will be ignored. @@ -120,7 +91,7 @@ class Log /** * Constructor. */ - private function __construct() + protected function __construct() { $logConfig = Config::getInstance()->log; $this->setCurrentLogLevelFromConfig($logConfig); diff --git a/core/Menu/MenuAbstract.php b/core/Menu/MenuAbstract.php index edd53161ba259ff9de7b631a83c8f3a8e8897917..b8f5b11e1ac8ba7f72103866890f8ff3cf6413e7 100644 --- a/core/Menu/MenuAbstract.php +++ b/core/Menu/MenuAbstract.php @@ -12,11 +12,12 @@ namespace Piwik\Menu; use Piwik\Common; use Piwik\Plugins\SitesManager\API; +use Piwik\Singleton; /** * @package Piwik_Menu */ -abstract class MenuAbstract +abstract class MenuAbstract extends Singleton { protected $menu = null; diff --git a/core/Menu/MenuAdmin.php b/core/Menu/MenuAdmin.php index 4a29db3e29848b89f2b9c7f1e2630810665c8257..eb3576d37ed00a23813cfd7d9b2dd51a112e7502 100644 --- a/core/Menu/MenuAdmin.php +++ b/core/Menu/MenuAdmin.php @@ -17,19 +17,6 @@ use Piwik\Piwik; */ class MenuAdmin extends MenuAbstract { - static private $instance = null; - - /** - * @return MenuAdmin - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Adds a new AdminMenu entry. * diff --git a/core/Menu/MenuMain.php b/core/Menu/MenuMain.php index 2485f18294562a1794fddf9f1d6a4a9d9cbe38f5..4146559fcdf2ff83daff012c3ab021fd14701bee 100644 --- a/core/Menu/MenuMain.php +++ b/core/Menu/MenuMain.php @@ -17,19 +17,6 @@ use Piwik\Piwik; */ class MenuMain extends MenuAbstract { - static private $instance = null; - - /** - * @return MenuAbstract - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Returns if the URL was found in the menu. * diff --git a/core/Menu/MenuTop.php b/core/Menu/MenuTop.php index 29f056367a896f6faff724d157bfddee4250925a..ab2d31279938da5659ce8026de4cfcd13da4c2bd 100644 --- a/core/Menu/MenuTop.php +++ b/core/Menu/MenuTop.php @@ -17,20 +17,6 @@ use Piwik\Piwik; */ class MenuTop extends MenuAbstract { - static private $instance = null; - - /** - * @return MenuTop - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - - /** * Adds a new entry to the TopMenu. * diff --git a/core/Plugin/API.php b/core/Plugin/API.php new file mode 100644 index 0000000000000000000000000000000000000000..e10baf788878da70ea8ac5972543d98501006ad9 --- /dev/null +++ b/core/Plugin/API.php @@ -0,0 +1,18 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik + * @package Piwik_PluginArchiver + */ + +namespace Piwik\Plugin; + +use Piwik\Singleton; + +abstract class API extends Singleton +{ +} diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php index f54c068d0dd820d13b2e5eb320b2c91175d7073c..99d5a9668d2e89aca25e5891e6a35cada78101f5 100644 --- a/core/Plugin/Controller.php +++ b/core/Plugin/Controller.php @@ -24,7 +24,6 @@ use Piwik\Period\Month; use Piwik\Period; use Piwik\Period\Range; use Piwik\Piwik; -use Piwik\Plugins\API\API; use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Plugins\UsersManager\API as APIUsersManager; @@ -207,7 +206,7 @@ abstract class Controller $idSite = Common::getRequestVar('idSite'); $period = Common::getRequestVar('period'); $date = Common::getRequestVar('date'); - $meta = API::getInstance()->getReportMetadata($idSite, $period, $date); + $meta = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite, $period, $date); $columns = array_merge($columnsToDisplay, $selectableColumns); $translations = array_combine($columns, $columns); @@ -452,10 +451,10 @@ abstract class Controller $view->isSuperUser = Access::getInstance()->isSuperUser(); $view->hasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess(); $view->isCustomLogo = Config::getInstance()->branding['use_custom_logo']; - $view->logoHeader = API::getInstance()->getHeaderLogoUrl(); - $view->logoLarge = API::getInstance()->getLogoUrl(); - $view->logoSVG = API::getInstance()->getSVGLogoUrl(); - $view->hasSVGLogo = API::getInstance()->hasSVGLogo(); + $view->logoHeader = \Piwik\Plugins\API\API::getInstance()->getHeaderLogoUrl(); + $view->logoLarge = \Piwik\Plugins\API\API::getInstance()->getLogoUrl(); + $view->logoSVG = \Piwik\Plugins\API\API::getInstance()->getSVGLogoUrl(); + $view->hasSVGLogo = \Piwik\Plugins\API\API::getInstance()->hasSVGLogo(); $view->enableFrames = Config::getInstance()->General['enable_framed_pages'] || @Config::getInstance()->General['enable_framed_logins']; diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index d7add95fdbb165641ddd8e35c7dc1bc9ecb91165..7dbb4f86c4a13a14f66c7f2e4727e1f4e43310d3 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -16,6 +16,7 @@ use Piwik\EventDispatcher; use Piwik\Filesystem; use Piwik\Option; use Piwik\Plugin; +use Piwik\Singleton; use Piwik\Translate; use Piwik\Updater; @@ -27,7 +28,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/EventDispatcher.php'; * @package Piwik * @subpackage Manager */ -class Manager +class Manager extends Singleton { protected $pluginsToLoad = array(); @@ -69,21 +70,6 @@ class Manager // If a plugin hooks onto at least an event starting with "Tracker.", we load the plugin during tracker const TRACKER_EVENT_PREFIX = 'Tracker.'; - static private $instance = null; - - /** - * Returns the singleton Manager - * - * @return Manager - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Update Plugins config * diff --git a/core/Registry.php b/core/Registry.php index 5fe90370b948e1b258840ee55fbd978aa3c6e798..88ecc1ce95780c8fb8e9be8d5d7484b0105dda06 100644 --- a/core/Registry.php +++ b/core/Registry.php @@ -15,24 +15,15 @@ namespace Piwik; * * @package Piwik */ -class Registry +class Registry extends Singleton { - private static $instance; private $data; - private function __construct() + protected function __construct() { $this->data = array(); } - public static function getInstance() - { - if (self::$instance == null) { - self::$instance = new Registry(); - } - return self::$instance; - } - public static function isRegistered($key) { return self::getInstance()->hasKey($key); @@ -48,11 +39,6 @@ class Registry self::getInstance()->setKey($key, $value); } - public static function unsetInstance() - { - self::$instance = null; - } - public function setKey($key, $value) { $this->data[$key] = $value; diff --git a/core/Singleton.php b/core/Singleton.php new file mode 100644 index 0000000000000000000000000000000000000000..7e7679c67aa63d7be9d7680bc990d1ca1afdc449 --- /dev/null +++ b/core/Singleton.php @@ -0,0 +1,37 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik + * @package Piwik + */ + +namespace Piwik; + +class Singleton +{ + + protected static $instances; + + protected function __construct() { } + + final private function __clone() { } + + public static function getInstance() { + $class = get_called_class(); + + if (!isset(self::$instances[$class])) { + self::$instances[$class] = new $class; + } + return self::$instances[$class]; + } + + public static function unsetInstance() + { + $class = get_called_class(); + unset(self::$instances[$class]); + } +} diff --git a/piwik.php b/piwik.php index 018fb2fa6eabf4f274faf2bfa5802c0de7dc2a9f..fa98df9076f170657f6e0654ec1833863b36d769 100644 --- a/piwik.php +++ b/piwik.php @@ -36,6 +36,7 @@ if (!defined('PIWIK_INCLUDE_PATH')) { @ignore_user_abort(true); require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; +require_once PIWIK_INCLUDE_PATH . '/core/Singleton.php'; require_once PIWIK_INCLUDE_PATH . '/core/Plugin/Manager.php'; require_once PIWIK_INCLUDE_PATH . '/core/Plugin.php'; require_once PIWIK_INCLUDE_PATH . '/core/Common.php'; diff --git a/plugins/API/API.php b/plugins/API/API.php index 0673e55a2dd82a8d39f09b5983ed828025660be1..5bd4a6c89891ebb3fb02585fd2d140d03dcbe523 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -46,21 +46,8 @@ require_once PIWIK_INCLUDE_PATH . '/core/Config.php'; * * @package Piwik_API */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\API\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Get Piwik version * @return string diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php index e9c9d4c810b8e90bb00f7a5a82d6a4aa4c37fa2b..84ceca80acbe790bcbc9a055f03ececbe1c827fd 100644 --- a/plugins/Actions/API.php +++ b/plugins/Actions/API.php @@ -36,21 +36,8 @@ use Piwik\Tracker\Action; * Note: pageName, pageUrl, outlinkUrl, downloadUrl parameters must be URL encoded before you call the API. * @package Actions */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\Actions\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Returns the list of metrics (pages, downloads, outlinks) * diff --git a/plugins/Annotations/API.php b/plugins/Annotations/API.php index b18a2264f9f37dd23c125837f3c408fc025bfe1e..7863d0ff5c8a6bb55e9758a52f4ac9520605c28d 100755 --- a/plugins/Annotations/API.php +++ b/plugins/Annotations/API.php @@ -30,23 +30,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Annotations/AnnotationList.php'; * * @package Annotations */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * Returns this API's singleton instance. - * - * @return \Piwik\Plugins\Annotations\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Create a new annotation for a site. * diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php index 909a178738fff35f2da1a8785dcb77773476b546..ab3ff062a8f31dd293468f626a823cc81412c9fb 100644 --- a/plugins/CoreAdminHome/API.php +++ b/plugins/CoreAdminHome/API.php @@ -27,21 +27,8 @@ use Piwik\TaskScheduler; /** * @package CoreAdminHome */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\CoreAdminHome\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Will run all scheduled tasks due to run at this time. * diff --git a/plugins/CoreConsole/templates/api/API.php b/plugins/CoreConsole/templates/api/API.php index 74e8abb13ab188c414c057e1a0bbb08ad69d5e68..bc3da69fb217d10c1bf36e7a96cac476d84fc8be 100644 --- a/plugins/CoreConsole/templates/api/API.php +++ b/plugins/CoreConsole/templates/api/API.php @@ -15,22 +15,8 @@ namespace Piwik\Plugins\PLUGINNAME; * * @package Piwik_PLUGINNAME */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\PLUGINNAME\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - - return self::$instance; - } - /** * Example method. Please remove if you do not need this API method. * You can call this API method like this: diff --git a/plugins/CustomVariables/API.php b/plugins/CustomVariables/API.php index 8c87124099d54df7746cb6a3a1f69f2ef0d5927e..522a05cf8171db19c6704581e43032aa8e0f589e 100644 --- a/plugins/CustomVariables/API.php +++ b/plugins/CustomVariables/API.php @@ -22,21 +22,8 @@ use Piwik\Tracker\Action; * * @package CustomVariables */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\CustomVariables\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * @param int $idSite * @param string $period diff --git a/plugins/DBStats/API.php b/plugins/DBStats/API.php index 1e3224cf2fe425158a1ee016a9f6f84afc18d8b7..af71b4cf424bc637d1f50c3bec43d54c3739ae5f 100644 --- a/plugins/DBStats/API.php +++ b/plugins/DBStats/API.php @@ -24,22 +24,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/DBStats/MySQLMetadataProvider.php'; * * @package DBStats */ -class API +class API extends \Piwik\Plugin\API { - /** Singleton instance of this class. */ - static private $instance = null; - - /** - * Gets or creates the DBStats API singleton. - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * The MySQLMetadataProvider instance that fetches table/db status information. */ @@ -48,7 +34,7 @@ class API /** * Constructor. */ - public function __construct() + protected function __construct() { $this->metadataProvider = new MySQLMetadataProvider(); } diff --git a/plugins/Dashboard/API.php b/plugins/Dashboard/API.php index a6acf6c26a2d8866d3558653b4ce2f1fc0b63291..1841775211031ffe790a777f783f677b04dd976f 100644 --- a/plugins/Dashboard/API.php +++ b/plugins/Dashboard/API.php @@ -17,32 +17,15 @@ use Piwik\WidgetsList; * * @package Piwik_API */ -class API +class API extends \Piwik\Plugin\API { - /** - * @var \Piwik\Plugins\Dashboard\API - */ - static private $instance = null; - private $dashboard = null; - public function __construct() + protected function __construct() { $this->dashboard = new Dashboard(); } - /** - * @return \Piwik\Plugins\Dashboard\API - */ - static public function getInstance() - { - if (null == self::$instance) { - self::$instance = new self; - } - - return self::$instance; - } - /** * Get each dashboard that belongs to a user including the containing widgets that are placed within each dashboard. * If the user has not created any dashboard yet, the default dashboard will be returned. diff --git a/plugins/DevicesDetection/API.php b/plugins/DevicesDetection/API.php index f899b0ce7802c29530133af68f8b5443daf262de..0c466ef0b65c9a233fd9960918ef22d041f68ef9 100644 --- a/plugins/DevicesDetection/API.php +++ b/plugins/DevicesDetection/API.php @@ -19,23 +19,8 @@ use Piwik\Piwik; /** * The DevicesDetection API lets you access reports on your visitors devices, brands, models, Operating system, Browsers. */ -class API +class API extends \Piwik\Plugin\API { - - static private $instance = null; - - /** - * - * @return \Piwik\Plugins\DevicesDetection\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * @param string $name * @param int $idSite diff --git a/plugins/ExampleAPI/API.php b/plugins/ExampleAPI/API.php index a6c012a6440da41b174aebb4bc1644bb306991de..5d9809334b994d6e587f96272c4ec200c69cb43e 100644 --- a/plugins/ExampleAPI/API.php +++ b/plugins/ExampleAPI/API.php @@ -21,42 +21,8 @@ use Piwik\Version; * Please see the <a href='http://dev.piwik.org/trac/browser/trunk/plugins/ExampleAPI/API.php#L1' target='_blank'>source code in in the file plugins/ExampleAPI/API.php</a> for more documentation. * @package Piwik_ExampleAPI */ -class API +class API extends \Piwik\Plugin\API { - /** - * * This is an example of a basic API file. Each plugin can have one public API. - * Each public function in this class will be available to be called via the API. - * Protected and private members will not be callable. - * Functions can be called internally using the PHP objects directly, or via the - * Piwik Web APIs, using HTTP requests. For more information, check out: - * http://piwik.org/docs/analytics-api/calling-techniques - * - * Parameters are passed automatically from the GET request to the API functions. - * - * Common API uses include: - * - requesting stats for a given date and period, for one or several websites - * - creating, editing, deleting entities (Goals, Websites, Users) - * - any logic that could be useful to a larger scope than the Controller (make a setting editable for example) - * - * It is highly recommended that all the plugin logic is done inside API implementations, and the - * Controller and other objects would all call the API internally using, eg. - * API::getInstance()->getSum(1, 2); - * - */ - static private $instance = null; - - /** - * Singleton - * @return \Piwik\Plugins\ExampleAPI\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Get Piwik version * @return string diff --git a/plugins/ExampleUI/API.php b/plugins/ExampleUI/API.php index 5827acac67d0e5c7ca9b4740709e8dab59f90869..681e2afb4b0c727b6c7f54f9d2902e2177fc4647 100644 --- a/plugins/ExampleUI/API.php +++ b/plugins/ExampleUI/API.php @@ -21,24 +21,10 @@ use Piwik\Period\Range; * * @package ExampleUI */ -class API +class API extends \Piwik\Plugin\API { public static $disableRandomness = false; - private static $instance = null; - - /** - * @return \Piwik\Plugins\ExampleUI\API - */ - public static function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - - return self::$instance; - } - public function getTemperaturesEvolution($date, $period) { $temperatures = array(); diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php index d61af046260c10aa57db317d21a0985338d9e434..34b3083f88e5f41cf05242d087b91e9a0573170a 100644 --- a/plugins/Goals/API.php +++ b/plugins/Goals/API.php @@ -41,21 +41,8 @@ use Piwik\Tracker\GoalManager; * * @package Goals */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\Goals\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Returns all Goals for a given website, or list of websites * diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index 48a28f1f7bfa012eb4b53ad0b1c0d66380342e65..ce0b600f6b43c66f64f11e50a1f4d54e3bfec6fb 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -33,7 +33,7 @@ use Piwik\Translate; * * @package ImageGraph */ -class API +class API extends \Piwik\Plugin\API { const FILENAME_KEY = 'filename'; const TRUNCATE_KEY = 'truncate'; @@ -104,20 +104,6 @@ class API const DEFAULT_NB_ROW_EVOLUTIONS = 5; const MAX_NB_ROW_LABELS = 10; - static private $instance = null; - - /** - * @return \Piwik\Plugins\ImageGraph\API - */ - static public function getInstance() - { - if (self::$instance == null) { - $c = __CLASS__; - self::$instance = new $c(); - } - return self::$instance; - } - public function get( $idSite, $period, diff --git a/plugins/LanguagesManager/API.php b/plugins/LanguagesManager/API.php index 64a58ccdf21b186e0c34945ee2a635b9ec680175..6309ff5a397c1f5c79da1e68c871ebd663a78c12 100644 --- a/plugins/LanguagesManager/API.php +++ b/plugins/LanguagesManager/API.php @@ -28,21 +28,8 @@ use Piwik\Piwik; * * @package LanguagesManager */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\LanguagesManager\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - protected $availableLanguageNames = null; protected $languageNames = null; diff --git a/plugins/Live/API.php b/plugins/Live/API.php index 04083c86ba256bc43a0f16248df3456e5d5db849..56f6338192aba76e83aa5556af4f867e02e5afff 100644 --- a/plugins/Live/API.php +++ b/plugins/Live/API.php @@ -57,25 +57,12 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Live/Visitor.php'; * See also the documentation about <a href='http://piwik.org/docs/real-time/' target='_blank'>Real time widget and visitor level reports</a> in Piwik. * @package Live */ -class API +class API extends \Piwik\Plugin\API { const VISITOR_PROFILE_MAX_VISITS_TO_AGGREGATE = 100; const VISITOR_PROFILE_MAX_VISITS_TO_SHOW = 10; const VISITOR_PROFILE_DATE_FORMAT = '%day% %shortMonth% %longYear%'; - static private $instance = null; - - /** - * @return \Piwik\Plugins\Live\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * This will return simple counters, for a given website ID, for visits over the last N minutes * diff --git a/plugins/MobileMessaging/API.php b/plugins/MobileMessaging/API.php index 3c369785a889b2c5c1d4f4a7e431f43a2200918b..0aa7e3b924bc1521a47708ff72b689c21a42b106 100644 --- a/plugins/MobileMessaging/API.php +++ b/plugins/MobileMessaging/API.php @@ -24,24 +24,11 @@ use Piwik\Plugins\ScheduledReports\API as APIScheduledReports; * - send SMS * @package MobileMessaging */ -class API +class API extends \Piwik\Plugin\API { const VERIFICATION_CODE_LENGTH = 5; const SMS_FROM = 'Piwik'; - static private $instance = null; - - /** - * @return \Piwik\Plugins\MobileMessaging\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * @param string $provider * @return SMSProvider diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php index d92af8e82c69082f72a1eb9e4e69bf0efd5ff119..763a1e28d3cb639b7764ad65d0862dce6ca4ba11 100755 --- a/plugins/MultiSites/API.php +++ b/plugins/MultiSites/API.php @@ -26,7 +26,7 @@ use Piwik\TaskScheduler; /** * The MultiSites API lets you request the key metrics (visits, page views, revenue) for all Websites in Piwik. */ -class API +class API extends \Piwik\Plugin\API { const METRIC_TRANSLATION_KEY = 'translation'; const METRIC_EVOLUTION_COL_NAME_KEY = 'evolution_column_name'; @@ -63,26 +63,6 @@ class API ) ); - /** - * The singleton instance of this class. - */ - static private $instance = null; - - /** - * Returns the singleton instance of this class. The instance is created - * if it hasn't been already. - * - * @return \Piwik\Plugins\MultiSites\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - - return self::$instance; - } - /** * Returns a report displaying the total visits, actions and revenue, as * well as the evolution of these values, of all existing sites over a diff --git a/plugins/Overlay/API.php b/plugins/Overlay/API.php index 0c736932f1f09b1d8108fbb2b5263ae6e3b7dae1..334cd712b309e7f56d1cd882dd52d20af5594611 100644 --- a/plugins/Overlay/API.php +++ b/plugins/Overlay/API.php @@ -20,23 +20,8 @@ use Piwik\Plugins\SitesManager\SitesManager; use Piwik\Plugins\Transitions\API as APITransitions; use Piwik\Tracker\Action; -class API +class API extends \Piwik\Plugin\API { - - private static $instance = null; - - /** - * Get Singleton instance - * @return \Piwik\Plugins\Overlay\API - */ - public static function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Get translation strings */ diff --git a/plugins/Provider/API.php b/plugins/Provider/API.php index 106fbd5883f551774ae088a4ae8414d6fe8ac5ee..ae53d0f2f823a5e5c5bca69cbf8f8cbf936da671 100644 --- a/plugins/Provider/API.php +++ b/plugins/Provider/API.php @@ -24,18 +24,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Provider/functions.php'; * * @package Provider */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - public function getProvider($idSite, $period, $date, $segment = false) { Piwik::checkUserHasViewAccess($idSite); diff --git a/plugins/Referrers/API.php b/plugins/Referrers/API.php index 1599546b4f614ccee9f3f83b54c09e01ee61b67a..15d4785771e04a9113b8325a512aacbe7589168a 100644 --- a/plugins/Referrers/API.php +++ b/plugins/Referrers/API.php @@ -30,18 +30,8 @@ use Piwik\Piwik; * Check out the widget <a href='http://demo.piwik.org/index.php?module=Widgetize&action=iframe&moduleToWidgetize=Referrers&actionToWidgetize=getKeywordsForPage&idSite=7&period=day&date=2011-02-15&disableLink=1' target='_blank'>"Top keywords used to find this page"</a> that you can easily re-use on your website. * @package Referrers */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * @param string $name * @param int $idSite diff --git a/plugins/SEO/API.php b/plugins/SEO/API.php index f23875812a93890deb18ee41faffb7a81f833041..4111c6d5f7c24a1b473d1c8a169fdd3454d7114e 100644 --- a/plugins/SEO/API.php +++ b/plugins/SEO/API.php @@ -24,21 +24,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Referrers/functions.php'; * * @package SEO */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\SEO\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Returns SEO statistics for a URL. * diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php index 4feb8dfcb52347724728ea4708d18045eb2f508e..4980870aa9ce882f6aedd03964b589e09eeaaf21 100644 --- a/plugins/ScheduledReports/API.php +++ b/plugins/ScheduledReports/API.php @@ -35,7 +35,7 @@ use Zend_Mime; * * @package ScheduledReports */ -class API +class API extends \Piwik\Plugin\API { const VALIDATE_PARAMETERS_EVENT = 'ScheduledReports.validateReportParameters'; const GET_REPORT_PARAMETERS_EVENT = 'ScheduledReports.getReportParameters'; @@ -66,19 +66,6 @@ class API const REPORT_TRUNCATE = 23; - static private $instance = null; - - /** - * @return \Piwik\Plugins\ScheduledReports\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * Creates a new report and schedules it. * diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php index 62fd909bc18e8dcc454840879de95285a202708f..85a69f0710faffe4759ec1e749ed0a8462710acf 100644 --- a/plugins/SegmentEditor/API.php +++ b/plugins/SegmentEditor/API.php @@ -22,23 +22,10 @@ use Piwik\Segment; * * @package SegmentEditor */ -class API +class API extends \Piwik\Plugin\API { const DEACTIVATE_SEGMENT_EVENT = 'SegmentEditor.deactivate'; - static private $instance = null; - - /** - * @return \Piwik\Plugins\SegmentEditor\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - protected function checkSegmentValue($definition, $idSite) { // unsanitize so we don't record the HTML entitied segment diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index c78e0a9d2c001ac702969f3973054495d1e6b7fb..e1b367d9c3505fb856469aac4fc0678402d5129b 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -43,22 +43,9 @@ use Piwik\UrlHelper; * See also the documentation about <a href='http://piwik.org/docs/manage-websites/' target='_blank'>Managing Websites</a> in Piwik. * @package SitesManager */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; const DEFAULT_SEARCH_KEYWORD_PARAMETERS = 'q,query,s,search,searchword,k,keyword'; - - /** - * @return \Piwik\Plugins\SitesManager\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - const OPTION_EXCLUDED_IPS_GLOBAL = 'SitesManager_ExcludedIpsGlobal'; const OPTION_DEFAULT_TIMEZONE = 'SitesManager_DefaultTimezone'; const OPTION_DEFAULT_CURRENCY = 'SitesManager_DefaultCurrency'; diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index e6fe8256174bbbb695ae2c5a16d800c1f1a54256..f48ca9d9a75ec470344c5220209add3c552385bd 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -34,19 +34,8 @@ use Piwik\Tracker\Action; /** * @package Transitions */ -class API +class API extends \Piwik\Plugin\API { - - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - public function getTransitionsForPageTitle($pageTitle, $idSite, $period, $date, $segment = false, $limitBeforeGrouping = false) { return $this->getTransitionsForAction($pageTitle, 'title', $idSite, $period, $date, $segment, $limitBeforeGrouping); diff --git a/plugins/UserCountry/API.php b/plugins/UserCountry/API.php index 85ff3973c4837e135deb6dbc417d5233540af3ae..79ac0cb6ec3113b21a0a24833fc6d043145a10fe 100644 --- a/plugins/UserCountry/API.php +++ b/plugins/UserCountry/API.php @@ -28,18 +28,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php'; * The UserCountry API lets you access reports about your visitors' Countries and Continents. * @package UserCountry */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - public function getCountry($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable(Archiver::COUNTRY_RECORD_NAME, $idSite, $period, $date, $segment); diff --git a/plugins/UserSettings/API.php b/plugins/UserSettings/API.php index 1fc12059c1d8f595b24e1dde5efab28ede781faa..90dd4752c788263113dfd79c04840d256d7f4f26 100644 --- a/plugins/UserSettings/API.php +++ b/plugins/UserSettings/API.php @@ -26,18 +26,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php'; * * @package UserSettings */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - protected function getDataTable($name, $idSite, $period, $date, $segment) { Piwik::checkUserHasViewAccess($idSite); diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 34bca9c465653ee13ccaa0a6ff09bc9ec3ee4df5..c71995b72832cb0655e8313248801cbd3821766b 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -34,7 +34,7 @@ use Piwik\Tracker\Cache; * See also the documentation about <a href='http://piwik.org/docs/manage-users/' target='_blank'>Managing Users</a> in Piwik. * @package UsersManager */ -class API +class API extends \Piwik\Plugin\API { const PREFERENCE_DEFAULT_REPORT = 'defaultReport'; const PREFERENCE_DEFAULT_REPORT_DATE = 'defaultReportDate'; diff --git a/plugins/VisitFrequency/API.php b/plugins/VisitFrequency/API.php index 18142916d7fd37448baaac4a38f3090104e8990f..fa4007f30996a32369a5f478a5fc877c3b58eae7 100644 --- a/plugins/VisitFrequency/API.php +++ b/plugins/VisitFrequency/API.php @@ -19,21 +19,11 @@ use Piwik\SegmentExpression; * VisitFrequency API lets you access a list of metrics related to Returning Visitors. * @package VisitFrequency */ -class API +class API extends \Piwik\Plugin\API { const RETURNING_VISITOR_SEGMENT = "visitorType==returning"; const COLUMN_SUFFIX = "_returning"; - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - /** * @param int $idSite * @param string $period diff --git a/plugins/VisitTime/API.php b/plugins/VisitTime/API.php index f87708e4efe7727d4404dd97b38616051a0e84d1..fe5c70bd057f231cc155826cb6d955e0169388e3 100644 --- a/plugins/VisitTime/API.php +++ b/plugins/VisitTime/API.php @@ -26,18 +26,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/VisitTime/functions.php'; * * @package VisitTime */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - protected function getDataTable($name, $idSite, $period, $date, $segment) { Piwik::checkUserHasViewAccess($idSite); diff --git a/plugins/VisitorInterest/API.php b/plugins/VisitorInterest/API.php index 1cb1fc3a1e6af9f433b9c66ea693562d9af3456c..68b6c44715ee5763c8fd71a1293f357e0b3fad06 100644 --- a/plugins/VisitorInterest/API.php +++ b/plugins/VisitorInterest/API.php @@ -21,18 +21,8 @@ use Piwik\Piwik; * * @package VisitorInterest */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - protected function getDataTable($name, $idSite, $period, $date, $segment, $column = Metrics::INDEX_NB_VISITS) { Piwik::checkUserHasViewAccess($idSite); diff --git a/plugins/VisitsSummary/API.php b/plugins/VisitsSummary/API.php index 3578d8f411b6f054de832ee63e2199e024bcd598..c0f32f39f10a5d06f0d7fae11e22337ef492f935 100644 --- a/plugins/VisitsSummary/API.php +++ b/plugins/VisitsSummary/API.php @@ -21,21 +21,8 @@ use Piwik\SettingsPiwik; * * @package VisitsSummary */ -class API +class API extends \Piwik\Plugin\API { - static private $instance = null; - - /** - * @return \Piwik\Plugins\VisitsSummary\API - */ - static public function getInstance() - { - if (self::$instance == null) { - self::$instance = new self; - } - return self::$instance; - } - public function get($idSite, $period, $date, $segment = false, $columns = false) { Piwik::checkUserHasViewAccess($idSite); diff --git a/tests/PHPUnit/Core/LogTest.php b/tests/PHPUnit/Core/LogTest.php index 706c8f16a6413c20ab1694c78c1022cb8dd2895e..ead7b7488d268fa3b0bb578a21ea090d80101fc3 100644 --- a/tests/PHPUnit/Core/LogTest.php +++ b/tests/PHPUnit/Core/LogTest.php @@ -67,7 +67,7 @@ dummy backtrace' Config::getInstance()->log['string_message_format'] = self::STRING_MESSAGE_FORMAT; Config::getInstance()->log['logger_file_path'] = self::getDefaultLogFileLocation(); @unlink(self::getLogFileLocation()); - Log::clearInstance(); + Log::unsetInstance(); Error::$debugBacktraceForTests = ExceptionHandler::$debugBacktraceForTests = "dummy backtrace"; } @@ -75,7 +75,7 @@ dummy backtrace' { parent::tearDown(); - Log::clearInstance(); + Log::unsetInstance(); @unlink(self::getLogFileLocation()); Error::$debugBacktraceForTests = ExceptionHandler::$debugBacktraceForTests = null; }