Skip to content
Extraits de code Groupes Projets
Valider 82a5a9fd rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Merge branch 'master' into 7276_update_command_progress

Conflicts:
	CHANGELOG.md
parents 25d1af26 f76ec249
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -26,8 +26,12 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API'
* `getHostByAddr()`
### Deprecations
* `API` classes should no longer have a protected constructor. Classes with a protected constructor will generate a notice in the logs and should expose a public constructor instead.
* Update classes should not declare static `getSql()` and `update()` methods anymore. It is still supported to use those, but developers should instead override the `Updates::getMigrationQueries()` and `Updates::doUpdate()` instance methods.
### New features
* `API` classes can now use dependency injection in their constructor to inject other instances.
### New commands
* There is now a command `core:purge-old-archive-data` that can be used to manually purge temporary, error-ed and invalidated archives from one or more archive tables.
......
......@@ -9,7 +9,8 @@
namespace Piwik\Plugin;
use Piwik\Singleton;
use Piwik\Container\StaticContainer;
use Psr\Log\LoggerInterface;
/**
* The base class of all API singletons.
......@@ -39,7 +40,58 @@ use Piwik\Singleton;
*
* @api
*/
abstract class API extends Singleton
abstract class API
{
private static $instances;
/**
* Returns the singleton instance for the derived class. If the singleton instance
* has not been created, this method will create it.
*
* @return static
*/
public static function getInstance() {
$class = get_called_class();
if (!isset(self::$instances[$class])) {
$container = StaticContainer::getContainer();
$refl = new \ReflectionClass($class);
if (!$refl->getConstructor() || $refl->getConstructor()->isPublic()) {
self::$instances[$class] = $container->get($class);
} else {
/** @var LoggerInterface $logger */
$logger = $container->get('Psr\Log\LoggerInterface');
// BC with API defining a protected constructor
$logger->notice('The API class {class} defines a protected constructor which is deprecated, make the constructor public instead', array('class' => $class));
self::$instances[$class] = new $class;
}
}
return self::$instances[$class];
}
/**
* Used in tests only
* @ignore
* @deprecated
*/
public static function unsetInstance()
{
$class = get_called_class();
unset(self::$instances[$class]);
}
/**
* Sets the singleton instance. For testing purposes.
* @ignore
* @deprecated
*/
public static function setSingletonInstance($instance)
{
$class = get_called_class();
self::$instances[$class] = $instance;
}
}
......@@ -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;
}
/**
......
......@@ -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;
}
/**
......
......@@ -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()
......
......@@ -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);
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter