diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-09-03 04:51:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 04:51:18 +0300 |
commit | 3565da78bff718f201247fc2f692c0be29220fde (patch) | |
tree | e8268373b284c293c307935a8bfa20d5cd920b48 | |
parent | 21cafb0533d07acbe0a574e23bd972b20d72aa90 (diff) |
Updates php-di to 6.2.1 (#16311)
58 files changed, 550 insertions, 196 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 438a974f0b..0d6f3804ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,6 +143,10 @@ These are only recommendations (because we will keep backward compatibility for * The following dimensions have been removed and replaced with versions that measure seconds: visitor_days_since_first, visitor_days_since_last, visitor_days_since_order * The _idvc, _idts, _viewts and _ects tracker parameters are no longer used, the values are calculated server side. Note: tracking these values server side means replaying log data in the past will result in inaccurate values for these dimensions. +* The Dependency Injection library PHP-DI was updated. [Some definitions need to be updated]((https://php-di.org/doc/migration/6.0.html)): + * The Method `\DI\object()` has been removed. You can use `\DI\autowire()` or `\DI\create()` instead. + * The Method `\DI\link()` has been removed. Use `\DI\get()` instead. + * Defining global observer functions in config now requires the functions to be wrapped in `\DI\value()`, unless they are a factory. ## Matomo 3.14.0 diff --git a/DIObject.php b/DIObject.php new file mode 100644 index 0000000000..8e3f47f9e0 --- /dev/null +++ b/DIObject.php @@ -0,0 +1,27 @@ +<?php + +namespace DI; + +/** + * This file aims to circumvent problems when updating to Matomo 4. + * Matomo 4 includes a newer version of PHP-DI, which does not include \DI\object() any longer + * To not run into any problems with plugins still using that we forward this method to \DI\autowire + */ + +if (!function_exists("\DI\object")) { + + function object() + { + return call_user_func_array("\DI\autowire", func_get_args()); + } + +} + +if (!function_exists("\DI\link")) { + + function link() + { + return call_user_func_array("\DI\get", func_get_args()); + } + +}
\ No newline at end of file diff --git a/composer.json b/composer.json index dc10812627..c5654d51ac 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "monolog/monolog": "~1.11", "mustangostang/spyc": "~0.6.0", "pear/pear_exception": "~1.0.0", - "php-di/php-di": "^5.0.0", + "php-di/php-di": "^6.0.0", "phpmailer/phpmailer": "^6.1", "piwik/device-detector": "~3.0", "psr/log": "~1.0", diff --git a/composer.lock b/composer.lock index 97f76a5e2a..de4ca48f22 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "700bebdcb248d636e79ee338ad6f86f3", + "content-hash": "c12681ad667b4670e55f110ac8b778a4", "packages": [ { "name": "composer/ca-bundle", @@ -135,38 +135,6 @@ "time": "2016-02-25T22:23:39+00:00" }, { - "name": "container-interop/container-interop", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/container-interop/container-interop.git", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "shasum": "" - }, - "require": { - "psr/container": "^1.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Interop\\Container\\": "src/Interop/Container/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", - "homepage": "https://github.com/container-interop/container-interop", - "abandoned": "psr/container", - "time": "2017-02-14T19:40:03+00:00" - }, - { "name": "davaxi/sparkline", "version": "1.2.2", "source": { @@ -931,6 +899,67 @@ "time": "2019-09-10T13:16:29+00:00" }, { + "name": "opis/closure", + "version": "3.5.6", + "source": { + "type": "git", + "url": "https://github.com/opis/closure.git", + "reference": "e8d34df855b0a0549a300cb8cb4db472556e8aa9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/opis/closure/zipball/e8d34df855b0a0549a300cb8cb4db472556e8aa9", + "reference": "e8d34df855b0a0549a300cb8cb4db472556e8aa9", + "shasum": "" + }, + "require": { + "php": "^5.4 || ^7.0" + }, + "require-dev": { + "jeremeamia/superclosure": "^2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Opis\\Closure\\": "src/" + }, + "files": [ + "functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marius Sarca", + "email": "marius.sarca@gmail.com" + }, + { + "name": "Sorin Sarca", + "email": "sarca_sorin@hotmail.com" + } + ], + "description": "A library that can be used to serialize closures (anonymous functions) and arbitrary objects.", + "homepage": "https://opis.io/closure", + "keywords": [ + "anonymous functions", + "closure", + "function", + "serializable", + "serialization", + "serialize" + ], + "time": "2020-08-11T08:46:50+00:00" + }, + { "name": "pear/archive_tar", "version": "1.4.9", "source": { @@ -1144,20 +1173,20 @@ }, { "name": "php-di/invoker", - "version": "1.3.3", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/PHP-DI/Invoker.git", - "reference": "1f4ca63b9abc66109e53b255e465d0ddb5c2e3f7" + "reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/1f4ca63b9abc66109e53b255e465d0ddb5c2e3f7", - "reference": "1f4ca63b9abc66109e53b255e465d0ddb5c2e3f7", + "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/540c27c86f663e20fe39a24cd72fa76cdb21d41a", + "reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a", "shasum": "" }, "require": { - "container-interop/container-interop": "~1.1" + "psr/container": "~1.0" }, "require-dev": { "athletic/athletic": "~0.1.8", @@ -1183,56 +1212,51 @@ "invoke", "invoker" ], - "time": "2016-07-14T13:09:58+00:00" + "time": "2017-03-20T19:28:22+00:00" }, { "name": "php-di/php-di", - "version": "5.4.6", + "version": "6.2.1", "source": { "type": "git", "url": "https://github.com/PHP-DI/PHP-DI.git", - "reference": "3f9255659595f3e289f473778bb6c51aa72abbbd" + "reference": "6875fe557c244b3830862c072c7719ca4ac2efe4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/3f9255659595f3e289f473778bb6c51aa72abbbd", - "reference": "3f9255659595f3e289f473778bb6c51aa72abbbd", + "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/6875fe557c244b3830862c072c7719ca4ac2efe4", + "reference": "6875fe557c244b3830862c072c7719ca4ac2efe4", "shasum": "" }, "require": { - "container-interop/container-interop": "~1.2", - "php": ">=5.5.0", - "php-di/invoker": "^1.3.2", + "opis/closure": "^3.5.5", + "php": ">=7.2.0", + "php-di/invoker": "^2.0", "php-di/phpdoc-reader": "^2.0.1", - "psr/container": "~1.0" + "psr/container": "^1.0" }, "provide": { - "container-interop/container-interop-implementation": "^1.0", "psr/container-implementation": "^1.0" }, - "replace": { - "mnapoli/php-di": "*" - }, "require-dev": { "doctrine/annotations": "~1.2", - "doctrine/cache": "~1.4", - "mnapoli/phpunit-easymock": "~0.2.0", - "ocramius/proxy-manager": "~1.0|~2.0", - "phpbench/phpbench": "@dev", - "phpunit/phpunit": "~4.5" + "friendsofphp/php-cs-fixer": "^2.4", + "mnapoli/phpunit-easymock": "^1.2", + "ocramius/proxy-manager": "~2.0.2", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "^8.5" }, "suggest": { "doctrine/annotations": "Install it if you want to use annotations (version ~1.2)", - "doctrine/cache": "Install it if you want to use the cache (version ~1.4)", - "ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~1.0 or ~2.0)" + "ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~2.0)" }, "type": "library", "autoload": { "psr-4": { - "DI\\": "src/DI/" + "DI\\": "src/" }, "files": [ - "src/DI/functions.php" + "src/functions.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -1240,13 +1264,27 @@ "MIT" ], "description": "The dependency injection container for humans", - "homepage": "http://php-di.org/", + "homepage": "https://php-di.org/", "keywords": [ + "PSR-11", "container", + "container-interop", "dependency injection", - "di" + "di", + "ioc", + "psr11" ], - "time": "2017-12-03T08:20:27+00:00" + "funding": [ + { + "url": "https://github.com/mnapoli", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/php-di/php-di", + "type": "tidelift" + } + ], + "time": "2020-06-18T09:54:32+00:00" }, { "name": "php-di/phpdoc-reader", @@ -2104,6 +2142,65 @@ "time": "2020-05-29T17:27:14+00:00" }, { + "name": "jeremeamia/superclosure", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/jeremeamia/super_closure.git", + "reference": "5707d5821b30b9a07acfb4d76949784aaa0e9ce9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jeremeamia/super_closure/zipball/5707d5821b30b9a07acfb4d76949784aaa0e9ce9", + "reference": "5707d5821b30b9a07acfb4d76949784aaa0e9ce9", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^1.2|^2.0|^3.0|^4.0", + "php": ">=5.4", + "symfony/polyfill-php56": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0|^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-4": { + "SuperClosure\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia", + "role": "Developer" + } + ], + "description": "Serialize Closure objects, including their context and binding", + "homepage": "https://github.com/jeremeamia/super_closure", + "keywords": [ + "closure", + "function", + "lambda", + "parser", + "serializable", + "serialize", + "tokenizer" + ], + "abandoned": "opis/closure", + "time": "2018-03-21T22:21:57+00:00" + }, + { "name": "lox/xhprof", "version": "dev-master", "source": { @@ -2197,6 +2294,58 @@ "time": "2020-06-29T13:22:24+00:00" }, { + "name": "nikic/php-parser", + "version": "v4.4.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120", + "reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "0.0.5", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2020-04-10T16:34:50+00:00" + }, + { "name": "phar-io/manifest", "version": "1.0.3", "source": { @@ -3469,6 +3618,142 @@ "time": "2016-10-03T07:35:21+00:00" }, { + "name": "symfony/polyfill-php56", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php56.git", + "reference": "e3c8c138280cdfe4b81488441555583aa1984e23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/e3c8c138280cdfe4b81488441555583aa1984e23", + "reference": "e3c8c138280cdfe4b81488441555583aa1984e23", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-util": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php56\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-12T16:47:27+00:00" + }, + { + "name": "symfony/polyfill-util", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-util.git", + "reference": "4afb4110fc037752cf0ce9869f9ab8162c4e20d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/4afb4110fc037752cf0ce9869f9ab8162c4e20d7", + "reference": "4afb4110fc037752cf0ce9869f9ab8162c4e20d7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Util\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony utilities for portability of PHP codes", + "homepage": "https://symfony.com", + "keywords": [ + "compat", + "compatibility", + "polyfill", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-12T16:14:59+00:00" + }, + { "name": "symfony/var-dumper", "version": "v2.6.13", "target-dir": "Symfony/Component/VarDumper", diff --git a/config/environment/dev.php b/config/environment/dev.php index f0d1514d17..0b3109e9d1 100644 --- a/config/environment/dev.php +++ b/config/environment/dev.php @@ -2,11 +2,11 @@ return array( - 'Matomo\Cache\Backend' => DI\object('Matomo\Cache\Backend\ArrayCache'), + 'Matomo\Cache\Backend' => DI\autowire('Matomo\Cache\Backend\ArrayCache'), - 'Piwik\Translation\Loader\LoaderInterface' => DI\object('Piwik\Translation\Loader\LoaderCache') - ->constructor(DI\get('Piwik\Translation\Loader\DevelopmentLoader')), - 'Piwik\Translation\Loader\DevelopmentLoader' => DI\object() + 'Piwik\Translation\Loader\LoaderInterface' => DI\autowire('Piwik\Translation\Loader\LoaderCache') + ->constructorParameter('loader', DI\get('Piwik\Translation\Loader\DevelopmentLoader')), + 'Piwik\Translation\Loader\DevelopmentLoader' => DI\create() ->constructor(DI\get('Piwik\Translation\Loader\JsonFileLoader')), ); diff --git a/config/environment/test.php b/config/environment/test.php index 13c5c390cd..63af43d95b 100644 --- a/config/environment/test.php +++ b/config/environment/test.php @@ -1,6 +1,6 @@ <?php -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Piwik\Common; use Piwik\Tests\Framework\Mock\FakeAccess; use Piwik\Tests\Framework\Mock\TestConfig; @@ -98,29 +98,29 @@ return array( 'observers.global' => DI\add(array( - array('AssetManager.getStylesheetFiles', function (&$stylesheets) { + array('AssetManager.getStylesheetFiles', DI\value(function (&$stylesheets) { $useOverrideCss = \Piwik\Container\StaticContainer::get('test.vars.useOverrideCss'); if ($useOverrideCss) { $stylesheets[] = 'tests/resources/screenshot-override/override.css'; } - }), + })), - array('AssetManager.getJavaScriptFiles', function (&$jsFiles) { + array('AssetManager.getJavaScriptFiles', DI\value(function (&$jsFiles) { $useOverrideJs = \Piwik\Container\StaticContainer::get('test.vars.useOverrideJs'); if ($useOverrideJs) { $jsFiles[] = 'tests/resources/screenshot-override/override.js'; } - }), + })), - array('Updater.checkForUpdates', function () { + array('Updater.checkForUpdates', \DI\value(function () { try { @\Piwik\Filesystem::deleteAllCacheOnUpdate(); } catch (Exception $ex) { // pass } - }), + })), - array('Test.Mail.send', function (\PHPMailer\PHPMailer\PHPMailer $mail) { + array('Test.Mail.send', \DI\value(function (\PHPMailer\PHPMailer\PHPMailer $mail) { $outputFile = PIWIK_INCLUDE_PATH . '/tmp/' . Common::getRequestVar('module', '') . '.' . Common::getRequestVar('action', '') . '.mail.json'; $outputContent = str_replace("=\n", "", $mail->Body ?: $mail->AltBody); $outputContent = str_replace("=0A", "\n", $outputContent); @@ -132,6 +132,6 @@ return array( 'contents' => $outputContent ); file_put_contents($outputFile, json_encode($outputContents)); - }), + })), )), ); diff --git a/config/environment/ui-test.php b/config/environment/ui-test.php index 8b46ede218..aae19a5bb6 100644 --- a/config/environment/ui-test.php +++ b/config/environment/ui-test.php @@ -21,7 +21,7 @@ return array( // removes port from all URLs to the test Piwik server so UI tests will pass no matter // what port is used - array('Request.dispatch.end', function (&$result) { + array('Request.dispatch.end', DI\value(function (&$result) { $request = $_GET + $_POST; $apiblacklist = StaticContainer::get('tests.ui.url_normalizer_blacklist.api'); @@ -50,11 +50,11 @@ return array( // remove PIWIK_INCLUDE_PATH from result so tests don't change based on the machine used $result = str_replace(realpath(PIWIK_INCLUDE_PATH), '', $result); - }), + })), - array('Controller.RssWidget.rssPiwik.end', function (&$result, $parameters) { + array('Controller.RssWidget.rssPiwik.end', DI\value(function (&$result, $parameters) { $result = ""; - }), + })), \Piwik\Tests\Framework\XssTesting::getJavaScriptAddEvent(), ]), diff --git a/config/global.php b/config/global.php index 9b199520dc..bd51022f7f 100644 --- a/config/global.php +++ b/config/global.php @@ -1,10 +1,8 @@ <?php -use Interop\Container\ContainerInterface; -use Interop\Container\Exception\NotFoundException; +use Psr\Container\ContainerInterface; use Matomo\Cache\Eager; use Piwik\SettingsServer; -use Piwik\Config; return array( @@ -61,7 +59,7 @@ return array( } else { try { $backend = $c->get('ini.Cache.backend'); - } catch (NotFoundException $ex) { + } catch (\DI\NotFoundException $ex) { $backend = 'chained'; // happens if global.ini.php is not available } } @@ -74,12 +72,12 @@ return array( 'entities.idNames' => DI\add(array('idGoal', 'idDimension')), - 'Psr\Log\LoggerInterface' => DI\object('Psr\Log\NullLogger'), + 'Psr\Log\LoggerInterface' => DI\create('Psr\Log\NullLogger'), - 'Piwik\Translation\Loader\LoaderInterface' => DI\object('Piwik\Translation\Loader\LoaderCache') - ->constructor(DI\get('Piwik\Translation\Loader\JsonFileLoader')), + 'Piwik\Translation\Loader\LoaderInterface' => DI\autowire('Piwik\Translation\Loader\LoaderCache') + ->constructorParameter('loader', DI\get('Piwik\Translation\Loader\JsonFileLoader')), - 'DeviceDetector\Cache\Cache' => DI\object('Piwik\DeviceDetector\DeviceDetectorCache')->constructor(86400), + 'DeviceDetector\Cache\Cache' => DI\autowire('Piwik\DeviceDetector\DeviceDetectorCache')->constructor(86400), 'observers.global' => array(), @@ -146,7 +144,7 @@ return array( '*.travis.yml', )), - 'Piwik\EventDispatcher' => DI\object()->constructorParameter('observers', DI\get('observers.global')), + 'Piwik\EventDispatcher' => DI\autowire()->constructorParameter('observers', DI\get('observers.global')), 'login.whitelist.ips' => function (ContainerInterface $c) { /** @var Piwik\Config\ $config */ @@ -174,17 +172,17 @@ return array( return $ipsResolved; }, - 'Piwik\Tracker\VisitorRecognizer' => DI\object() + 'Piwik\Tracker\VisitorRecognizer' => DI\autowire() ->constructorParameter('trustCookiesOnly', DI\get('ini.Tracker.trust_visitors_cookies')) ->constructorParameter('visitStandardLength', DI\get('ini.Tracker.visit_standard_length')) ->constructorParameter('lookbackNSecondsCustom', DI\get('ini.Tracker.window_look_back_for_visitor')), - 'Piwik\Tracker\Settings' => DI\object() + 'Piwik\Tracker\Settings' => DI\autowire() ->constructorParameter('isSameFingerprintsAcrossWebsites', DI\get('ini.Tracker.enable_fingerprinting_across_websites')), 'archiving.performance.logger' => null, - \Piwik\CronArchive\Performance\Logger::class => DI\object()->constructorParameter('logger', DI\get('archiving.performance.logger')), + \Piwik\CronArchive\Performance\Logger::class => DI\autowire()->constructorParameter('logger', DI\get('archiving.performance.logger')), \Piwik\Concurrency\LockBackend::class => \DI\get(\Piwik\Concurrency\LockBackend\MySqlLockBackend::class), diff --git a/core/CliMulti/RequestCommand.php b/core/CliMulti/RequestCommand.php index bcdea2b5cc..49c521f31f 100644 --- a/core/CliMulti/RequestCommand.php +++ b/core/CliMulti/RequestCommand.php @@ -69,9 +69,9 @@ class RequestCommand extends ConsoleCommand if ($input->getOption('superuser')) { StaticContainer::addDefinitions(array( 'observers.global' => \DI\add(array( - array('Environment.bootstrapped', function () { + array('Environment.bootstrapped', \DI\value(function () { Access::getInstance()->setSuperUserAccess(true); - }) + })) )), )); } diff --git a/core/Container/ContainerFactory.php b/core/Container/ContainerFactory.php index 2d8d91dbc2..e556b721ae 100644 --- a/core/Container/ContainerFactory.php +++ b/core/Container/ContainerFactory.php @@ -10,7 +10,6 @@ namespace Piwik\Container; use DI\Container; use DI\ContainerBuilder; -use Doctrine\Common\Cache\ArrayCache; use Piwik\Application\Kernel\GlobalSettingsProvider; use Piwik\Application\Kernel\PluginList; use Piwik\Plugin\Manager; @@ -66,7 +65,6 @@ class ContainerFactory $builder = new ContainerBuilder(); $builder->useAnnotations(false); - $builder->setDefinitionCache(new ArrayCache()); // INI config $builder->addDefinitions(new IniConfigDefinitionSource($this->settings)); diff --git a/core/Container/IniConfigDefinitionSource.php b/core/Container/IniConfigDefinitionSource.php index a880cf58d0..753261f9d4 100644 --- a/core/Container/IniConfigDefinitionSource.php +++ b/core/Container/IniConfigDefinitionSource.php @@ -8,7 +8,7 @@ namespace Piwik\Container; -use DI\Definition\Exception\DefinitionException; +use DI\Definition\Exception\InvalidDefinition; use DI\Definition\Source\DefinitionSource; use DI\Definition\ValueDefinition; use Piwik\Application\Kernel\GlobalSettingsProvider; @@ -56,14 +56,30 @@ class IniConfigDefinitionSource implements DefinitionSource $section = $this->getSection($sectionName); if ($configKey === null) { - return new ValueDefinition($name, $section); + $value = new ValueDefinition($section); + $value->setName($name); + return $value; } if (! array_key_exists($configKey, $section)) { return null; } - return new ValueDefinition($name, $section[$configKey]); + $value = new ValueDefinition($section[$configKey]); + $value->setName($name); + return $value; + } + + public function getDefinitions(): array + { + $result = []; + foreach ($this->config as $section) { + $value = new ValueDefinition($this->getSection($section)); + $value->setName($section); + + $result[$section] = $value; + } + return $result; } private function parseEntryName($name) @@ -84,7 +100,7 @@ class IniConfigDefinitionSource implements DefinitionSource $section = $this->config->getSection($sectionName); if (!is_array($section)) { - throw new DefinitionException(sprintf( + throw new InvalidDefinition(sprintf( 'IniFileChain did not return an array for the config section %s', $section )); diff --git a/core/Container/StaticContainer.php b/core/Container/StaticContainer.php index 1100eb930b..7baf5b57d6 100644 --- a/core/Container/StaticContainer.php +++ b/core/Container/StaticContainer.php @@ -74,7 +74,7 @@ class StaticContainer * * @param string $name Container entry name. * @return mixed - * @throws \DI\NotFoundException + * @throws \DI\NotFoundException|\DI\DependencyException */ public static function get($name) { diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index 3a59a74f0b..6cb9edbcc3 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -8,8 +8,8 @@ */ namespace Piwik; +use DI\DependencyException; use Exception; -use Interop\Container\Exception\ContainerException; use Piwik\API\Request; use Piwik\API\ResponseBuilder; use Piwik\Container\ContainerDoesNotExistException; @@ -159,7 +159,7 @@ class ExceptionHandler 'exception' => $exception, 'ignoreInScreenWriter' => true, ]); - } catch (ContainerException $ex) { + } catch (DependencyException $ex) { // ignore (occurs if exception is thrown when resolving DI entries) } catch (ContainerDoesNotExistException $ex) { // ignore diff --git a/core/bootstrap.php b/core/bootstrap.php index c777270728..028f7dcae6 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -43,6 +43,8 @@ require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; // Composer autoloader require_once PIWIK_VENDOR_PATH . '/autoload.php'; +require_once PIWIK_INCLUDE_PATH . '/DIObject.php'; + \Piwik\Plugin\Manager::initPluginDirectories(); /** diff --git a/plugins/CoreAdminHome/tests/Integration/SetConfigTest.php b/plugins/CoreAdminHome/tests/Integration/SetConfigTest.php index ea54968f14..09da98f6ee 100644 --- a/plugins/CoreAdminHome/tests/Integration/SetConfigTest.php +++ b/plugins/CoreAdminHome/tests/Integration/SetConfigTest.php @@ -8,7 +8,7 @@ namespace Piwik\Plugins\CoreAdminHome\tests\Integration\Commands; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Piwik\Application\Kernel\GlobalSettingsProvider; use Piwik\Config; use Piwik\Tests\Framework\TestCase\ConsoleCommandTestCase; diff --git a/plugins/CoreAdminHome/tests/Integration/TasksTest.php b/plugins/CoreAdminHome/tests/Integration/TasksTest.php index c0df9eb7e8..e98791a131 100644 --- a/plugins/CoreAdminHome/tests/Integration/TasksTest.php +++ b/plugins/CoreAdminHome/tests/Integration/TasksTest.php @@ -239,9 +239,9 @@ class TasksTest extends IntegrationTestCase { return [ 'observers.global' => \DI\add([ - ['Mail.send', function (Mail $mail) { + ['Mail.send', \DI\value(function (Mail $mail) { $this->mail = $mail; - }], + })], ]), ]; } diff --git a/plugins/CoreConsole/tests/System/ArchiveCronTest.php b/plugins/CoreConsole/tests/System/ArchiveCronTest.php index 3b71dcd7ba..c0228b450e 100644 --- a/plugins/CoreConsole/tests/System/ArchiveCronTest.php +++ b/plugins/CoreConsole/tests/System/ArchiveCronTest.php @@ -7,7 +7,7 @@ */ namespace Piwik\Plugins\CoreConsole\tests\System; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Piwik\Archive\ArchiveInvalidator; use Piwik\Common; use Piwik\Config; diff --git a/plugins/CoreHome/config/config.php b/plugins/CoreHome/config/config.php index 8f1c9c9e72..a9931ee15e 100644 --- a/plugins/CoreHome/config/config.php +++ b/plugins/CoreHome/config/config.php @@ -2,7 +2,7 @@ return array( - 'Piwik\Plugins\CoreHome\Tracker\VisitRequestProcessor' => DI\object() + 'Piwik\Plugins\CoreHome\Tracker\VisitRequestProcessor' => DI\autowire() ->constructorParameter('visitStandardLength', DI\get('ini.Tracker.visit_standard_length')) ->constructorParameter('trackerAlwaysNewVisitor', DI\get('ini.Debug.tracker_always_new_visitor')), diff --git a/plugins/CorePluginsAdmin/config/test.php b/plugins/CorePluginsAdmin/config/test.php index 71cc69dda5..04726f428a 100644 --- a/plugins/CorePluginsAdmin/config/test.php +++ b/plugins/CorePluginsAdmin/config/test.php @@ -2,7 +2,7 @@ return array( 'observers.global' => DI\add(array( - array('Request.dispatchCoreAndPluginUpdatesScreen', function () { + array('Request.dispatchCoreAndPluginUpdatesScreen', \DI\value(function () { $pluginName = 'TagManager'; $unloadTagManager = \Piwik\Container\StaticContainer::get('test.vars.unloadTagManager'); $tagManagerTeaser = new \Piwik\Plugins\CorePluginsAdmin\Model\TagManagerTeaser(\Piwik\Piwik::getCurrentUserLogin()); @@ -14,6 +14,6 @@ return array( } $tagManagerTeaser->reset(); } - }), + })), )) ); diff --git a/plugins/CoreUpdater/config/config.php b/plugins/CoreUpdater/config/config.php index b9c87c9f63..2113866d28 100644 --- a/plugins/CoreUpdater/config/config.php +++ b/plugins/CoreUpdater/config/config.php @@ -1,7 +1,7 @@ <?php return array( - 'Piwik\Plugins\CoreUpdater\Updater' => DI\object() + 'Piwik\Plugins\CoreUpdater\Updater' => DI\autowire() ->constructorParameter('tmpPath', DI\get('path.tmp')), 'diagnostics.optional' => DI\add(array( diff --git a/plugins/CoreUpdater/tests/Fixtures/FailUpdateHttpsFixture.php b/plugins/CoreUpdater/tests/Fixtures/FailUpdateHttpsFixture.php index b748f1de95..7817e89f1d 100644 --- a/plugins/CoreUpdater/tests/Fixtures/FailUpdateHttpsFixture.php +++ b/plugins/CoreUpdater/tests/Fixtures/FailUpdateHttpsFixture.php @@ -18,7 +18,7 @@ class FailUpdateHttpsFixture extends Fixture public function provideContainerConfig() { return array( - 'Piwik\Plugins\CoreUpdater\Updater' => \DI\object('Piwik\Plugins\CoreUpdater\tests\Mock\UpdaterMock'), + 'Piwik\Plugins\CoreUpdater\Updater' => \DI\autowire('Piwik\Plugins\CoreUpdater\tests\Mock\UpdaterMock'), ); } } diff --git a/plugins/CustomAlerts b/plugins/CustomAlerts -Subproject cf95d21e2bbc849e24a3f0bb26d109dc4c08402 +Subproject f54e16745ecabbf053dac7e4312a153fd671abc diff --git a/plugins/CustomJsTracker/tests/Integration/TrackerUpdaterTest.php b/plugins/CustomJsTracker/tests/Integration/TrackerUpdaterTest.php index 73fceb8d47..487b5f37e4 100644 --- a/plugins/CustomJsTracker/tests/Integration/TrackerUpdaterTest.php +++ b/plugins/CustomJsTracker/tests/Integration/TrackerUpdaterTest.php @@ -236,9 +236,9 @@ var myArray = []; { return [ 'observers.global' => \DI\add([ - ['CustomJsTracker.trackerJsChanged', function ($path) { + ['CustomJsTracker.trackerJsChanged', \DI\value(function ($path) { $this->trackerJsChangedEventPath = $path; - }], + })], ]), ]; } diff --git a/plugins/DBStats/config/test.php b/plugins/DBStats/config/test.php index f14acb17b0..c8f33d76f0 100644 --- a/plugins/DBStats/config/test.php +++ b/plugins/DBStats/config/test.php @@ -2,6 +2,6 @@ return array( - 'Piwik\Plugins\DBStats\MySQLMetadataDataAccess' => \DI\object('Piwik\Plugins\DBStats\tests\Mocks\MockDataAccess'), + 'Piwik\Plugins\DBStats\MySQLMetadataDataAccess' => \DI\create('Piwik\Plugins\DBStats\tests\Mocks\MockDataAccess'), );
\ No newline at end of file diff --git a/plugins/DeviceDetectorCache b/plugins/DeviceDetectorCache -Subproject e958911eedd8b422ba4f6d67af5fd959c7a928f +Subproject af676a4800d8695d6e7b5dbb28ac82f53515421 diff --git a/plugins/Diagnostics/config/config.php b/plugins/Diagnostics/config/config.php index 7e4c6e92b8..3dbefaf339 100644 --- a/plugins/Diagnostics/config/config.php +++ b/plugins/Diagnostics/config/config.php @@ -28,28 +28,28 @@ return array( DI\get('Piwik\Plugins\Diagnostics\Diagnostic\CronArchivingCheck'), DI\get(CronArchivingLastRunCheck::class), DI\get('Piwik\Plugins\Diagnostics\Diagnostic\DatabaseAbilitiesCheck'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\DbOverSSLCheck'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\DbMaxPacket'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\ForceSSLCheck'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\DbOverSSLCheck'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\DbMaxPacket'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\ForceSSLCheck'), ), 'diagnostics.informational' => array( - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\MatomoInformational'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\PhpInformational'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\DatabaseInformational'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\ConfigInformational'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\ServerInformational'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\ReportInformational'), - Di\get('Piwik\Plugins\Diagnostics\Diagnostic\UserInformational'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\MatomoInformational'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\PhpInformational'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\DatabaseInformational'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\ConfigInformational'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\ServerInformational'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\ReportInformational'), + DI\get('Piwik\Plugins\Diagnostics\Diagnostic\UserInformational'), ), // Allows other plugins to disable diagnostics that were previously registered 'diagnostics.disabled' => array(), - 'Piwik\Plugins\Diagnostics\DiagnosticService' => DI\object() + 'Piwik\Plugins\Diagnostics\DiagnosticService' => DI\autowire() ->constructor(DI\get('diagnostics.required'), DI\get('diagnostics.optional'), DI\get('diagnostics.informational'), DI\get('diagnostics.disabled')), - 'Piwik\Plugins\Diagnostics\Diagnostic\MemoryLimitCheck' => DI\object() + 'Piwik\Plugins\Diagnostics\Diagnostic\MemoryLimitCheck' => DI\autowire() ->constructorParameter('minimumMemoryLimit', DI\get('ini.General.minimum_memory_limit')), - 'Piwik\Plugins\Diagnostics\Diagnostic\WriteAccessCheck' => DI\object() + 'Piwik\Plugins\Diagnostics\Diagnostic\WriteAccessCheck' => DI\autowire() ->constructorParameter('tmpPath', DI\get('path.tmp')), ); diff --git a/plugins/Intl/config/config.php b/plugins/Intl/config/config.php index 11e540614e..afe4ec2e39 100644 --- a/plugins/Intl/config/config.php +++ b/plugins/Intl/config/config.php @@ -1,5 +1,5 @@ <?php return array( - 'Piwik\Intl\Data\Provider\DateTimeFormatProvider' => DI\object('Piwik\Plugins\Intl\DateTimeFormatProvider') + 'Piwik\Intl\Data\Provider\DateTimeFormatProvider' => DI\autowire('Piwik\Plugins\Intl\DateTimeFormatProvider') );
\ No newline at end of file diff --git a/plugins/Login/config/config.php b/plugins/Login/config/config.php index f87d76ccd9..435c1d5d57 100644 --- a/plugins/Login/config/config.php +++ b/plugins/Login/config/config.php @@ -1,5 +1,5 @@ <?php return array( - 'Piwik\Auth' => DI\object('Piwik\Plugins\Login\Auth') + 'Piwik\Auth' => DI\create('Piwik\Plugins\Login\Auth') );
\ No newline at end of file diff --git a/plugins/Login/config/test.php b/plugins/Login/config/test.php index 30717d24d5..9342d07d9c 100644 --- a/plugins/Login/config/test.php +++ b/plugins/Login/config/test.php @@ -1,6 +1,6 @@ <?php return array( - 'Piwik\Plugins\Login\SystemSettings' => DI\decorate(function ($settings, \Interop\Container\ContainerInterface $c) { + 'Piwik\Plugins\Login\SystemSettings' => DI\decorate(function ($settings, \Psr\Container\ContainerInterface $c) { /** @var \Piwik\Plugins\Login\SystemSettings $settings */ \Piwik\Access::doAsSuperUser(function () use ($settings, $c) { @@ -13,7 +13,7 @@ return array( return $settings; }), - 'Piwik\Plugins\Login\Security\BruteForceDetection' => DI\decorate(function ($detection, \Interop\Container\ContainerInterface $c) { + 'Piwik\Plugins\Login\Security\BruteForceDetection' => DI\decorate(function ($detection, \Psr\Container\ContainerInterface $c) { /** @var \Piwik\Plugins\Login\Security\BruteForceDetection $detection */ if ($c->get('test.vars.bruteForceBlockIps')) { diff --git a/plugins/Login/tests/Integration/PasswordResetterTest.php b/plugins/Login/tests/Integration/PasswordResetterTest.php index b600d031c4..b6014aecff 100644 --- a/plugins/Login/tests/Integration/PasswordResetterTest.php +++ b/plugins/Login/tests/Integration/PasswordResetterTest.php @@ -192,7 +192,7 @@ class PasswordResetterTest extends IntegrationTestCase { return [ 'observers.global' => \DI\add([ - ['Test.Mail.send', function (PHPMailer $mail) { + ['Test.Mail.send', \DI\value(function (PHPMailer $mail) { $body = $mail->createBody(); $body = preg_replace("/=[\r\n]+/", '', $body); preg_match('/resetToken=[\s]*3D([a-zA-Z0-9=\s]+)<\/p>/', $body, $matches); @@ -201,7 +201,7 @@ class PasswordResetterTest extends IntegrationTestCase $capturedToken = preg_replace('/=\s*/', '', $capturedToken); $this->capturedToken = $capturedToken; } - }], + })], ]), ]; } diff --git a/plugins/MarketingCampaignsReporting b/plugins/MarketingCampaignsReporting -Subproject 923b74cc81072417f46529ad407e27e1b88e3b7 +Subproject 93fb3f7572a19bb62735b98bd6906f76db9580f diff --git a/plugins/Marketplace/config/config.php b/plugins/Marketplace/config/config.php index 2ccbe4e719..ac6a1bb0df 100644 --- a/plugins/Marketplace/config/config.php +++ b/plugins/Marketplace/config/config.php @@ -1,6 +1,6 @@ <?php -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Piwik\Plugins\Marketplace\Api\Service; use Piwik\Plugins\Marketplace\LicenseKey; diff --git a/plugins/Marketplace/config/test.php b/plugins/Marketplace/config/test.php index 8c21be15f8..94dba1508e 100644 --- a/plugins/Marketplace/config/test.php +++ b/plugins/Marketplace/config/test.php @@ -1,6 +1,6 @@ <?php -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Piwik\Plugins\Marketplace\tests\Framework\Mock\Consumer as MockConsumer; use Piwik\Plugins\Marketplace\LicenseKey; use Piwik\Plugins\Marketplace\tests\Framework\Mock\Service as MockService; diff --git a/plugins/Monolog/config/cli.php b/plugins/Monolog/config/cli.php index 146943120b..45c67f4d5c 100644 --- a/plugins/Monolog/config/cli.php +++ b/plugins/Monolog/config/cli.php @@ -1,6 +1,6 @@ <?php -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Monolog\Logger; use Piwik\Plugins\Monolog\Handler\FailureLogMessageDetector; use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter; diff --git a/plugins/Monolog/config/config.php b/plugins/Monolog/config/config.php index 7bb9ec6f0f..315c481366 100644 --- a/plugins/Monolog/config/config.php +++ b/plugins/Monolog/config/config.php @@ -1,6 +1,6 @@ <?php -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Monolog\Logger; use Piwik\Log; use Piwik\Plugins\Monolog\Handler\FileHandler; @@ -8,7 +8,7 @@ use Piwik\Plugins\Monolog\Handler\LogCaptureHandler; return array( - 'Monolog\Logger' => DI\object('Monolog\Logger') + 'Monolog\Logger' => DI\create('Monolog\Logger') ->constructor('piwik', DI\get('log.handlers'), DI\get('log.processors')), 'Psr\Log\LoggerInterface' => DI\get('Monolog\Logger'), @@ -94,15 +94,15 @@ return array( DI\get('Piwik\Plugins\Monolog\Processor\TokenProcessor'), ), - 'Piwik\Plugins\Monolog\Handler\FileHandler' => DI\object() + 'Piwik\Plugins\Monolog\Handler\FileHandler' => DI\create() ->constructor(DI\get('log.file.filename'), DI\get('log.level.file')) ->method('setFormatter', DI\get('log.lineMessageFormatter.file')), - 'Piwik\Plugins\Monolog\Handler\DatabaseHandler' => DI\object() + 'Piwik\Plugins\Monolog\Handler\DatabaseHandler' => DI\create() ->constructor(DI\get('log.level.database')) ->method('setFormatter', DI\get('log.lineMessageFormatter')), - 'Piwik\Plugins\Monolog\Handler\WebNotificationHandler' => DI\object() + 'Piwik\Plugins\Monolog\Handler\WebNotificationHandler' => DI\create() ->constructor(DI\get('log.level.screen')) ->method('setFormatter', DI\get('log.lineMessageFormatter')), @@ -173,12 +173,12 @@ return array( return $logPath; }), - 'Piwik\Plugins\Monolog\Formatter\LineMessageFormatter' => DI\object('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter') + 'Piwik\Plugins\Monolog\Formatter\LineMessageFormatter' => DI\create('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter') ->constructor(DI\get('log.short.format')), - 'log.lineMessageFormatter' => DI\object('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter') + 'log.lineMessageFormatter' => DI\create('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter') ->constructor(DI\get('log.short.format')), - 'log.lineMessageFormatter.file' => DI\object('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter') + 'log.lineMessageFormatter.file' => DI\autowire('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter') ->constructor(DI\get('log.trace.format')) ->constructorParameter('allowInlineLineBreaks', false), @@ -207,6 +207,6 @@ return array( return [$fileHandler]; }, - 'archiving.performance.logger' => DI\object(Logger::class) + 'archiving.performance.logger' => DI\create(Logger::class) ->constructor('matomo.archiving.performance', DI\get('archiving.performance.handlers'), DI\get('log.processors')), ); diff --git a/plugins/Monolog/config/tracker.php b/plugins/Monolog/config/tracker.php index 6b5301441e..5b7c9ef5ac 100644 --- a/plugins/Monolog/config/tracker.php +++ b/plugins/Monolog/config/tracker.php @@ -1,6 +1,6 @@ <?php -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; function isTrackerDebugEnabled(ContainerInterface $c) { diff --git a/plugins/ScheduledReports/config/config.php b/plugins/ScheduledReports/config/config.php index 5a2215e3b9..9bdb5ddfbe 100644 --- a/plugins/ScheduledReports/config/config.php +++ b/plugins/ScheduledReports/config/config.php @@ -12,13 +12,13 @@ use Piwik\Plugins\ScheduledReports\ReportEmailGenerator\AttachedFileReportEmailG use Piwik\Plugins\ScheduledReports\ReportEmailGenerator\HtmlReportEmailGenerator; return [ - ReportEmailGenerator::class . '.pdf' => DI\object(AttachedFileReportEmailGenerator::class) + ReportEmailGenerator::class . '.pdf' => DI\autowire(AttachedFileReportEmailGenerator::class) ->constructorParameter('attachedFileExtension', '.pdf') ->constructorParameter('attachedFileMimeType', 'application/pdf'), - ReportEmailGenerator::class . '.csv' => DI\object(AttachedFileReportEmailGenerator::class) + ReportEmailGenerator::class . '.csv' => DI\autowire(AttachedFileReportEmailGenerator::class) ->constructorParameter('attachedFileExtension', '.csv') ->constructorParameter('attachedFileMimeType', 'application/csv'), - ReportEmailGenerator::class . '.html' => DI\object(HtmlReportEmailGenerator::class), + ReportEmailGenerator::class . '.html' => DI\create(HtmlReportEmailGenerator::class), ]; diff --git a/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/AttachedFileReportEmailGeneratorTest.php b/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/AttachedFileReportEmailGeneratorTest.php index 623fa75eb8..38653743bf 100644 --- a/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/AttachedFileReportEmailGeneratorTest.php +++ b/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/AttachedFileReportEmailGeneratorTest.php @@ -157,10 +157,10 @@ Content-Transfer-Encoding: quoted-printable { return [ 'observers.global' => \DI\add([ - ['Test.Mail.send', function (PHPMailer $mail) { + ['Test.Mail.send', \DI\value(function (PHPMailer $mail) { $this->mail = $mail; $this->mail->preSend(); - }], + })], ]), ]; } diff --git a/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/HtmlReportEmailGeneratorTest.php b/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/HtmlReportEmailGeneratorTest.php index 55c44383a3..b212ec9082 100644 --- a/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/HtmlReportEmailGeneratorTest.php +++ b/plugins/ScheduledReports/tests/Integration/ReportEmailGenerator/HtmlReportEmailGeneratorTest.php @@ -63,10 +63,10 @@ class HtmlReportEmailGeneratorTest extends IntegrationTestCase { return [ 'observers.global' => \DI\add([ - ['Test.Mail.send', function (PHPMailer $mail) { + ['Test.Mail.send', \DI\value(function (PHPMailer $mail) { $this->mail = $mail; $this->mail->preSend(); - }], + })], ]), ]; } diff --git a/plugins/ScheduledReports/tests/Integration/ReportEmailGeneratorTest.php b/plugins/ScheduledReports/tests/Integration/ReportEmailGeneratorTest.php index dad7af3b85..9250be3e7d 100644 --- a/plugins/ScheduledReports/tests/Integration/ReportEmailGeneratorTest.php +++ b/plugins/ScheduledReports/tests/Integration/ReportEmailGeneratorTest.php @@ -129,9 +129,9 @@ class ReportEmailGeneratorTest extends IntegrationTestCase { return [ 'observers.global' => \DI\add([ - ['Test.Mail.send', function (PHPMailer $mail) { + ['Test.Mail.send', \DI\value(function (PHPMailer $mail) { $this->mail = $mail; - }], + })], ]), ]; } diff --git a/plugins/TagManager b/plugins/TagManager -Subproject 855166ea6e4391cd774df4c335a42428de99422 +Subproject 551bc847c1e2e716ff554f626331995ae8a605d diff --git a/plugins/Tour/config/test.php b/plugins/Tour/config/test.php index 1d43a00f1e..4d640af4ec 100644 --- a/plugins/Tour/config/test.php +++ b/plugins/Tour/config/test.php @@ -2,7 +2,7 @@ return array( 'observers.global' => DI\add(array( - array('API.Tour.getChallenges.end', function (&$challenges) { + array('API.Tour.getChallenges.end', DI\value(function (&$challenges) { $completeAllChanges = \Piwik\Container\StaticContainer::get('test.vars.completeAllChallenges'); if ($completeAllChanges) { foreach ($challenges as &$challenge) { @@ -17,6 +17,6 @@ return array( $challenge['isCompleted'] = false; } } - }), + })), )) ); diff --git a/plugins/TwoFactorAuth/config/test.php b/plugins/TwoFactorAuth/config/test.php index 617eb132cd..5fc0fda2d0 100644 --- a/plugins/TwoFactorAuth/config/test.php +++ b/plugins/TwoFactorAuth/config/test.php @@ -1,8 +1,8 @@ <?php return array( - 'Piwik\Plugins\TwoFactorAuth\Dao\TwoFaSecretRandomGenerator' => DI\object('Piwik\Plugins\TwoFactorAuth\Dao\TwoFaSecretStaticGenerator'), - 'Piwik\Plugins\TwoFactorAuth\Dao\RecoveryCodeRandomGenerator' => DI\object('Piwik\Plugins\TwoFactorAuth\Dao\RecoveryCodeStaticGenerator'), + 'Piwik\Plugins\TwoFactorAuth\Dao\TwoFaSecretRandomGenerator' => DI\create('Piwik\Plugins\TwoFactorAuth\Dao\TwoFaSecretStaticGenerator'), + 'Piwik\Plugins\TwoFactorAuth\Dao\RecoveryCodeRandomGenerator' => DI\create('Piwik\Plugins\TwoFactorAuth\Dao\RecoveryCodeStaticGenerator'), 'Piwik\Plugins\TwoFactorAuth\TwoFactorAuthentication' => DI\decorate(function ($previous) { /** @var Piwik\Plugins\TwoFactorAuth\TwoFactorAuthentication $previous */ diff --git a/plugins/UsersManager/tests/Integration/APITest.php b/plugins/UsersManager/tests/Integration/APITest.php index dcc235a563..5ce6ba2bd0 100644 --- a/plugins/UsersManager/tests/Integration/APITest.php +++ b/plugins/UsersManager/tests/Integration/APITest.php @@ -1017,11 +1017,11 @@ class APITest extends IntegrationTestCase 'Piwik\Access' => new FakeAccess(), 'usersmanager.user_preference_names' => \DI\add(['randomDoesNotExist', 'RandomNOTREQUESTED', 'preferenceName']), 'observers.global' => \DI\add([ - ['Access.Capability.addCapabilities', function (&$capabilities) { + ['Access.Capability.addCapabilities', \DI\value(function (&$capabilities) { $capabilities[] = new TestCap1(); $capabilities[] = new TestCap2(); $capabilities[] = new TestCap3(); - }], + })], ]), ); } diff --git a/tests/PHPUnit/Fixtures/UITestFixture.php b/tests/PHPUnit/Fixtures/UITestFixture.php index b75ebe079b..297fcaaa5a 100644 --- a/tests/PHPUnit/Fixtures/UITestFixture.php +++ b/tests/PHPUnit/Fixtures/UITestFixture.php @@ -467,7 +467,7 @@ class UITestFixture extends SqlDump return [ 'Tests.now' => \DI\decorate(function(){ return Option::get("Tests.forcedNowTimestamp"); }), 'observers.global' => \DI\add([ - ['Report.addReports', function (&$reports) { + ['Report.addReports', \DI\value(function (&$reports) { $report = new XssReport(); $report->initForXss('forTwig'); $reports[] = $report; @@ -475,11 +475,11 @@ class UITestFixture extends SqlDump $report = new XssReport(); $report->initForXss('forAngular'); $reports[] = $report; - }], - ['Dimension.addDimensions', function (&$instances) { + })], + ['Dimension.addDimensions', \DI\value(function (&$instances) { $instances[] = new XssDimension(); - }], - ['API.Request.intercept', function (&$result, $finalParameters, $pluginName, $methodName) { + })], + ['API.Request.intercept', \DI\value(function (&$result, $finalParameters, $pluginName, $methodName) { if ($pluginName != 'ExampleAPI' && $methodName != 'xssReportforTwig' && $methodName != 'xssReportforAngular') { return; } @@ -498,7 +498,7 @@ class UITestFixture extends SqlDump 'nb_visits' => 15, ]); $result = $dataTable; - }], + })], ]), Proxy::class => \DI\get(CustomApiProxy::class), 'log.handlers' => \DI\decorate(function ($previous, ContainerInterface $c) { diff --git a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php index f41c51f266..8a836b0e39 100644 --- a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php +++ b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php @@ -8,7 +8,7 @@ namespace Piwik\Tests\Framework; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Piwik\Application\Environment; use Piwik\Application\EnvironmentManipulator; use Piwik\Application\Kernel\GlobalSettingsProvider; diff --git a/tests/PHPUnit/Framework/TestingEnvironmentVariables.php b/tests/PHPUnit/Framework/TestingEnvironmentVariables.php index 992368b55a..697caf7a95 100644 --- a/tests/PHPUnit/Framework/TestingEnvironmentVariables.php +++ b/tests/PHPUnit/Framework/TestingEnvironmentVariables.php @@ -40,6 +40,11 @@ class TestingEnvironmentVariables return isset($this->behaviorOverrideProperties[$name]); } + public function getProperties() + { + return $this->behaviorOverrideProperties; + } + /** * Overrides a config entry. * diff --git a/tests/PHPUnit/Framework/TestingEnvironmentVariablesDefinitionSource.php b/tests/PHPUnit/Framework/TestingEnvironmentVariablesDefinitionSource.php index 525c2a7a35..837cb2e883 100644 --- a/tests/PHPUnit/Framework/TestingEnvironmentVariablesDefinitionSource.php +++ b/tests/PHPUnit/Framework/TestingEnvironmentVariablesDefinitionSource.php @@ -22,7 +22,6 @@ class TestingEnvironmentVariablesDefinitionSource implements DefinitionSource private $prefix; /** - * @param TestingEnvironmentVariables $vars * @param string $prefix */ public function __construct($prefix = 'test.vars.') @@ -42,7 +41,24 @@ class TestingEnvironmentVariablesDefinitionSource implements DefinitionSource $variableName = $this->parseVariableName($name); $vars = new TestingEnvironmentVariables(); - return new ValueDefinition($name, $vars->$variableName); + $value = new ValueDefinition($vars->$variableName); + $value->setName($name); + return $value; + } + + public function getDefinitions(): array + { + $vars = new TestingEnvironmentVariables(); + $properties = $vars->getProperties(); + + $result = []; + foreach ($properties as $name => $property) { + $value = new ValueDefinition($property); + $value->setName($name); + $result[] = $value; + } + + return $result; } private function parseVariableName($name) diff --git a/tests/PHPUnit/Framework/XssTesting.php b/tests/PHPUnit/Framework/XssTesting.php index 0c5a8d03d2..b037a72aa4 100644 --- a/tests/PHPUnit/Framework/XssTesting.php +++ b/tests/PHPUnit/Framework/XssTesting.php @@ -91,9 +91,9 @@ JS; public static function getJavaScriptAddEvent() { $xssTesting = new XssTesting(); - return ['Template.jsGlobalVariables', function (&$out) use ($xssTesting) { + return ['Template.jsGlobalVariables', \DI\value(function (&$out) use ($xssTesting) { $out .= $xssTesting->getJavaScriptCode(); - }]; + })]; } /** diff --git a/tests/PHPUnit/Integration/ArchiveWebTest.php b/tests/PHPUnit/Integration/ArchiveWebTest.php index 1b9841ccc3..802c3194a1 100644 --- a/tests/PHPUnit/Integration/ArchiveWebTest.php +++ b/tests/PHPUnit/Integration/ArchiveWebTest.php @@ -70,17 +70,17 @@ class ArchiveWebTest extends SystemTestCase 'Psr\Log\LoggerInterface' => \DI\get('Monolog\Logger'), 'Tests.log.allowAllHandlers' => true, 'observers.global' => [ - ['API.Request.intercept', function (&$returnedValue, $finalParameters, $pluginName, $methodName, $parametersRequest) { + ['API.Request.intercept', \DI\value(function (&$returnedValue, $finalParameters, $pluginName, $methodName, $parametersRequest) { if ($pluginName == 'CoreAdminHome' && $methodName == 'runCronArchiving') { $returnedValue = 'mock output'; } - }], - ['Console.doRun', function (&$exitCode, InputInterface $input, OutputInterface $output) { + })], + ['Console.doRun', \DI\value(function (&$exitCode, InputInterface $input, OutputInterface $output) { if ($input->getFirstArgument() == 'core:archive') { $output->writeln('mock output'); $exitCode = 0; } - }], + })], ], ); } diff --git a/tests/PHPUnit/Integration/AssetManagerTest.php b/tests/PHPUnit/Integration/AssetManagerTest.php index 249b00c8d7..360d4352aa 100644 --- a/tests/PHPUnit/Integration/AssetManagerTest.php +++ b/tests/PHPUnit/Integration/AssetManagerTest.php @@ -92,7 +92,7 @@ class AssetManagerTest extends IntegrationTestCase public function provideContainerConfig() { return array( - 'Piwik\Plugin\Manager' => \DI\object('Piwik\Tests\Unit\AssetManager\PluginManagerMock') + 'Piwik\Plugin\Manager' => \DI\autowire('Piwik\Tests\Unit\AssetManager\PluginManagerMock') ); } diff --git a/tests/PHPUnit/Integration/CronArchiveTest.php b/tests/PHPUnit/Integration/CronArchiveTest.php index 0fc0992f4f..6a1613c22e 100644 --- a/tests/PHPUnit/Integration/CronArchiveTest.php +++ b/tests/PHPUnit/Integration/CronArchiveTest.php @@ -455,7 +455,7 @@ LOG; Date::$now = strtotime('2020-02-03 04:05:06'); return array( - 'Piwik\CliMulti' => \DI\object('Piwik\Tests\Framework\Mock\FakeCliMulti') + 'Piwik\CliMulti' => \DI\create('Piwik\Tests\Framework\Mock\FakeCliMulti') ); } diff --git a/tests/PHPUnit/Integration/Period/FactoryTest.php b/tests/PHPUnit/Integration/Period/FactoryTest.php index 2934715e68..9ff978a646 100644 --- a/tests/PHPUnit/Integration/Period/FactoryTest.php +++ b/tests/PHPUnit/Integration/Period/FactoryTest.php @@ -128,7 +128,7 @@ class FactoryTest extends IntegrationTestCase public function provideContainerConfig() { return [ - \Piwik\Plugin\Manager::class => \DI\object(MockPluginManager::class), + \Piwik\Plugin\Manager::class => \DI\autowire(MockPluginManager::class), ]; } } diff --git a/tests/PHPUnit/Integration/SegmentTest.php b/tests/PHPUnit/Integration/SegmentTest.php index ecca62eaf3..557c44d023 100644 --- a/tests/PHPUnit/Integration/SegmentTest.php +++ b/tests/PHPUnit/Integration/SegmentTest.php @@ -1868,7 +1868,7 @@ log_visit.visit_total_actions return array( 'Piwik\Access' => new FakeAccess(), - 'Piwik\Tracker\TableLogAction\Cache' => \DI\object()->constructorParameter('cache', $cacheProxy), + 'Piwik\Tracker\TableLogAction\Cache' => \DI\autowire()->constructorParameter('cache', $cacheProxy), ); } @@ -2021,14 +2021,14 @@ log_visit.visit_total_actions { return [ 'observers.global' => [ - ['Segment.addSegments', function (Segment\SegmentsList $list) { + ['Segment.addSegments', \DI\value(function (Segment\SegmentsList $list) { $segment = new \Piwik\Plugin\Segment(); $segment->setSegment('customSegment'); $segment->setType(\Piwik\Plugin\Segment::TYPE_DIMENSION); $segment->setName('Custom Segment'); $segment->setSqlSegment('(UNIX_TIMESTAMP(log_visit.visit_first_action_time) - log_visit.visitor_seconds_since_first)'); $list->addSegment($segment); - }], + })], ], ]; } diff --git a/tests/PHPUnit/Integration/Session/SessionAuthTest.php b/tests/PHPUnit/Integration/Session/SessionAuthTest.php index 2b322c812c..3f0c2142d1 100644 --- a/tests/PHPUnit/Integration/Session/SessionAuthTest.php +++ b/tests/PHPUnit/Integration/Session/SessionAuthTest.php @@ -154,7 +154,7 @@ class SessionAuthTest extends IntegrationTestCase public function provideContainerConfig() { return [ - SessionAuth::class => \DI\object() + SessionAuth::class => \DI\autowire() ->constructorParameter('shouldDestroySession', false), ]; } diff --git a/tests/PHPUnit/System/ConsoleTest.php b/tests/PHPUnit/System/ConsoleTest.php index 25b7f164a2..1fd9d8330d 100644 --- a/tests/PHPUnit/System/ConsoleTest.php +++ b/tests/PHPUnit/System/ConsoleTest.php @@ -105,6 +105,9 @@ class TestCommandWithException extends ConsoleCommand } } +/** + * @group ConsoleTest3 + */ class ConsoleTest extends ConsoleCommandTestCase { public function setUp(): void @@ -215,20 +218,20 @@ END; { return [ 'log.handlers' => [\DI\get(FailureLogMessageDetector::class)], - LoggerInterface::class => \DI\object(Logger::class) + LoggerInterface::class => \DI\create(Logger::class) ->constructor('piwik', \DI\get('log.handlers'), \DI\get('log.processors')), 'observers.global' => \DI\add([ - ['Console.filterCommands', function (&$commands) { + ['Console.filterCommands', \DI\value(function (&$commands) { $commands[] = TestCommandWithFatalError::class; $commands[] = TestCommandWithException::class; - }], + })], - ['Request.dispatch', function ($module, $action) { + ['Request.dispatch', \DI\value(function ($module, $action) { if ($module === 'CorePluginsAdmin' && $action === 'safemode') { print "*** IN SAFEMODE ***\n"; // will appear in output } - }], + })], ]), ]; } diff --git a/tests/PHPUnit/System/ImportLogsTest.php b/tests/PHPUnit/System/ImportLogsTest.php index 6129d07fe0..757e3b1817 100644 --- a/tests/PHPUnit/System/ImportLogsTest.php +++ b/tests/PHPUnit/System/ImportLogsTest.php @@ -195,17 +195,17 @@ class ImportLogsTest extends SystemTestCase $testingEnvironment = new TestingEnvironmentVariables(); if ($testingEnvironment->_triggerTrackerFailure) { - $observers[] = array('Tracker.newHandler', function () { + $observers[] = array('Tracker.newHandler', \DI\value(function () { @http_response_code(500); throw new \Exception("injected exception"); - }); + })); } if ($testingEnvironment->_triggerInvalidRequests) { // we trigger an invalid request by checking for triggerInvalid=1 in a request, and if found replacing the // request w/ a request that has an nonexistent idsite - $observers[] = array('Tracker.initRequestSet', function (RequestSet $requestSet) { + $observers[] = array('Tracker.initRequestSet', \DI\value(function (RequestSet $requestSet) { $requests = $requestSet->getRequests(); foreach ($requests as $index => $request) { $url = $request->getParam('url'); @@ -217,7 +217,7 @@ class ImportLogsTest extends SystemTestCase } } $requestSet->setRequests($requests); - }); + })); } if (!empty($observers)) { diff --git a/tests/PHPUnit/proxy/piwik.php b/tests/PHPUnit/proxy/piwik.php index 8135659410..216a1143c1 100644 --- a/tests/PHPUnit/proxy/piwik.php +++ b/tests/PHPUnit/proxy/piwik.php @@ -23,12 +23,12 @@ ob_start(); try { $globalObservers = array( - array('Environment.bootstrapped', function () { + array('Environment.bootstrapped', \DI\value(function () { Tracker::setTestEnvironment(); Manager::getInstance()->deleteAll(); Option::clearCache(); Site::clearCache(); - }) + })) ); Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables(), $globalObservers)); |