From bbae3aecca789e3bde2878f05e8d82ad5d064fa6 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Tue, 10 Mar 2015 15:34:18 +1300 Subject: Dependency injection in API classes --- plugins/DBStats/API.php | 13 ++----------- plugins/Dashboard/API.php | 4 ++-- plugins/Insights/API.php | 6 ++---- plugins/UsersManager/API.php | 6 +++--- 4 files changed, 9 insertions(+), 20 deletions(-) (limited to 'plugins') diff --git a/plugins/DBStats/API.php b/plugins/DBStats/API.php index 30def6cf79..47417dbc35 100644 --- a/plugins/DBStats/API.php +++ b/plugins/DBStats/API.php @@ -12,12 +12,6 @@ use Piwik\Common; use Piwik\DataTable; use Piwik\Piwik; -/** - * - * @see plugins/DBStats/MySQLMetadataProvider.php - */ -require_once PIWIK_INCLUDE_PATH . '/plugins/DBStats/MySQLMetadataProvider.php'; - /** * DBStats API is used to request the overall status of the Mysql tables in use by Piwik. * @hideExceptForSuperUser @@ -30,12 +24,9 @@ class API extends \Piwik\Plugin\API */ private $metadataProvider; - /** - * Constructor. - */ - protected function __construct() + public function __construct(MySQLMetadataProvider $metadataProvider) { - $this->metadataProvider = new MySQLMetadataProvider(); + $this->metadataProvider = $metadataProvider; } /** diff --git a/plugins/Dashboard/API.php b/plugins/Dashboard/API.php index d8994c229e..f4637e862a 100644 --- a/plugins/Dashboard/API.php +++ b/plugins/Dashboard/API.php @@ -19,9 +19,9 @@ class API extends \Piwik\Plugin\API { private $dashboard = null; - protected function __construct() + public function __construct(Dashboard $dashboard) { - $this->dashboard = new Dashboard(); + $this->dashboard = $dashboard; } /** diff --git a/plugins/Insights/API.php b/plugins/Insights/API.php index 20cb649649..4b3228ffc2 100644 --- a/plugins/Insights/API.php +++ b/plugins/Insights/API.php @@ -39,11 +39,9 @@ class API extends \Piwik\Plugin\API */ private $model; - protected function __construct() + public function __construct(Model $model) { - parent::__construct(); - - $this->model = new Model(); + $this->model = $model; } private function getOverviewReports() diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index b1c7c227e3..ccb4dac126 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -45,9 +45,9 @@ class API extends \Piwik\Plugin\API private static $instance = null; - protected function __construct() + public function __construct(Model $model) { - $this->model = new Model(); + $this->model = $model; } /** @@ -71,7 +71,7 @@ class API extends \Piwik\Plugin\API self::$instance = $instance; } catch (Exception $e) { - self::$instance = new self; + self::$instance = StaticContainer::get('Piwik\Plugins\UsersManager\API'); StaticContainer::getContainer()->set('UsersManager_API', self::$instance); } -- cgit v1.2.3