From 340b86bbc8e8c684379e740be64b307e52c05ae8 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Thu, 11 Jul 2024 17:11:38 +0600 Subject: [PATCH] pkp/pkp-lib#9913 removed pimple dependency --- api/v1/submissions/SubmissionController.php | 3 +- classes/core/AppServiceProvider.php | 26 ++++-- classes/core/Services.php | 18 ++-- classes/search/PreprintSearch.php | 3 +- classes/services/OPSServiceProvider.php | 84 ------------------- classes/submission/Repository.php | 3 +- classes/submission/Submission.php | 5 +- classes/sushi/IR.php | 3 +- classes/sushi/PR.php | 3 +- .../AuthorDashboardHandler.php | 3 +- pages/preprint/PreprintHandler.php | 7 +- pages/workflow/WorkflowHandler.php | 3 +- tools/buildpkg.sh | 2 - 13 files changed, 37 insertions(+), 126 deletions(-) delete mode 100644 classes/services/OPSServiceProvider.php diff --git a/api/v1/submissions/SubmissionController.php b/api/v1/submissions/SubmissionController.php index 75ab10c610..84f8942679 100644 --- a/api/v1/submissions/SubmissionController.php +++ b/api/v1/submissions/SubmissionController.php @@ -17,7 +17,6 @@ namespace APP\API\v1\submissions; -use APP\core\Services; use APP\facades\Repo; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -122,7 +121,7 @@ public function relatePublication(Request $illuminateRequest): JsonResponse // Validate against the schema $submissionContext = $request->getContext(); if (!$submissionContext || $submissionContext->getId() !== $submission->getData('contextId')) { - $submissionContext = Services::get('context')->get($submission->getData('contextId')); + $submissionContext = app()->get('context')->get($submission->getData('contextId')); } $errors = Repo::publication()->validate($publication, $params, $submission, $submissionContext); diff --git a/classes/core/AppServiceProvider.php b/classes/core/AppServiceProvider.php index 3873f938a0..c6936bbd9b 100644 --- a/classes/core/AppServiceProvider.php +++ b/classes/core/AppServiceProvider.php @@ -3,20 +3,22 @@ /** * @file classes/core/AppServiceProvider.php * - * Copyright (c) 2014-2021 Simon Fraser University - * Copyright (c) 2003-2021 John Willinsky + * Copyright (c) 2014-2024 Simon Fraser University + * Copyright (c) 2003-2024 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class AppServiceProvider * - * @ingroup core - * - * @brief Resolves requests for application classes such as the request handler - * to support dependency injection + * @brief Resolves requests for application classes such as the request handler + * to support dependency injection */ namespace APP\core; +use APP\services\ContextService; +use APP\services\NavigationMenuService; +use APP\services\StatsEditorialService; +use APP\services\StatsPublicationService; use PKP\core\PKPRequest; class AppServiceProvider extends \PKP\core\AppServiceProvider @@ -29,5 +31,17 @@ public function register() parent::register(); $this->app->bind(Request::class, PKPRequest::class); + + // Navigation Menu service + $this->app->singleton('navigationMenu', fn ($app) => new NavigationMenuService()); + + // Context service + $this->app->singleton('context', fn ($app) => new ContextService()); + + // Publication statistics service + $this->app->singleton('publicationStats', fn ($app) => new StatsPublicationService()); + + // Editorial statistics service + $this->app->singleton('editorialStats', fn ($app) => new StatsEditorialService()); } } diff --git a/classes/core/Services.php b/classes/core/Services.php index b7ca6e5208..c243423896 100644 --- a/classes/core/Services.php +++ b/classes/core/Services.php @@ -3,30 +3,22 @@ /** * @file classes/core/Services.php * - * Copyright (c) 2014-2021 Simon Fraser University - * Copyright (c) 2000-2021 John Willinsky + * Copyright (c) 2014-2024 Simon Fraser University + * Copyright (c) 2000-2024 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class Services * - * @ingroup core - * - * @see Core - * * @brief Pimple Dependency Injection Container. + * + * @deprecated 3.5.0 Consider using {@see app()->get('SERVICE_NAME')} + * @see app()->get('SERVICE_NAME') */ namespace APP\core; class Services extends \PKP\core\PKPServices { - /** - * container initialization - */ - protected function init() - { - $this->container->register(new \APP\services\OPSServiceProvider()); - } } if (!PKP_STRICT_MODE) { diff --git a/classes/search/PreprintSearch.php b/classes/search/PreprintSearch.php index ddb5090222..4e14d015d4 100644 --- a/classes/search/PreprintSearch.php +++ b/classes/search/PreprintSearch.php @@ -21,7 +21,6 @@ use APP\core\Application; use APP\core\Request; -use APP\core\Services; use APP\facades\Repo; use APP\server\Server; use PKP\db\DAORegistry; @@ -74,7 +73,7 @@ public function getSparseArray($unorderedResults, $orderBy, $orderDir, $exclude) $filter['dateStart'] = $oneMonthAgo; $filter['dateEnd'] = $today; } - $rawReport = Services::get('publicationStats')->getTotals($filter); + $rawReport = app()->get('publicationStats')->getTotals($filter); foreach ($rawReport as $row) { $unorderedResults[$row->submission_id]['metric'] = $row->metric; } diff --git a/classes/services/OPSServiceProvider.php b/classes/services/OPSServiceProvider.php deleted file mode 100644 index 0b7cf4869a..0000000000 --- a/classes/services/OPSServiceProvider.php +++ /dev/null @@ -1,84 +0,0 @@ -getId() === $submission->getData('contextId')) { $context = $requestContext; } else { - $context = Services::get('context')->get($submission->getData('contextId')); + $context = app()->get('context')->get($submission->getData('contextId')); } $preprintTombstoneManager = new PreprintTombstoneManager(); if (!$section) { diff --git a/classes/submission/Submission.php b/classes/submission/Submission.php index 80358fe305..3d706462fe 100644 --- a/classes/submission/Submission.php +++ b/classes/submission/Submission.php @@ -24,7 +24,6 @@ namespace APP\submission; -use APP\core\Services; use APP\facades\Repo; use APP\publication\Publication; use APP\statistics\StatisticsHelper; @@ -56,7 +55,7 @@ class Submission extends PKPSubmission */ public function _getContextLicenseFieldValue($locale, $field, $publication = null) { - $context = Services::get('context')->get($this->getData('contextId')); + $context = app()->get('context')->get($this->getData('contextId')); $fieldValue = null; // Scrutinizer switch ($field) { case Submission::PERMISSIONS_FIELD_LICENSE_URL: @@ -144,7 +143,7 @@ public function getTotalGalleyViews() 'contextIds' => [$this->getData('contextId')], 'fileIds' => $fileIds, ]; - $metrics = Services::get('publicationStats') + $metrics = app()->get('publicationStats') ->getQueryBuilder($filters) ->getSum([]) ->value('metric'); diff --git a/classes/sushi/IR.php b/classes/sushi/IR.php index 4302438ed4..9e42f0d907 100644 --- a/classes/sushi/IR.php +++ b/classes/sushi/IR.php @@ -17,7 +17,6 @@ namespace APP\sushi; -use APP\core\Services; use APP\facades\Repo; use PKP\statistics\PKPStatisticsHelper; use PKP\sushi\CounterR5Report; @@ -199,7 +198,7 @@ public function getReportItems(): array } // do not consider metric_type filter now, but for display - $statsService = Services::get('sushiStats'); + $statsService = app()->get('sushiStats'); $metricsQB = $statsService->getQueryBuilder($params); // consider attributes to group the metrics by $groupBy = ['m.' . PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID]; diff --git a/classes/sushi/PR.php b/classes/sushi/PR.php index b9d7f0a76a..c24bd68d43 100644 --- a/classes/sushi/PR.php +++ b/classes/sushi/PR.php @@ -17,7 +17,6 @@ namespace APP\sushi; -use APP\core\Services; use PKP\statistics\PKPStatisticsHelper; use PKP\sushi\CounterR5Report; @@ -135,7 +134,7 @@ public function getReportItems(): array $params['dateEnd'] = $this->endDate; // do not consider metric_type filter now, but for display - $statsService = Services::get('sushiStats'); + $statsService = app()->get('sushiStats'); $metricsQB = $statsService->getQueryBuilder($params); $groupBy = []; // consider granularity=Month to group the metrics by month diff --git a/pages/authorDashboard/AuthorDashboardHandler.php b/pages/authorDashboard/AuthorDashboardHandler.php index ba516d8c0c..70275d20fd 100644 --- a/pages/authorDashboard/AuthorDashboardHandler.php +++ b/pages/authorDashboard/AuthorDashboardHandler.php @@ -19,7 +19,6 @@ use APP\components\forms\publication\PublishForm; use APP\core\Application; use APP\core\PageRouter; -use APP\core\Services; use APP\facades\Repo; use APP\publication\Publication; use APP\template\TemplateManager; @@ -45,7 +44,7 @@ public function setupTemplate($request) $submissionContext = $request->getContext(); if ($submission->getData('contextId') !== $submissionContext->getId()) { - $submissionContext = Services::get('context')->get($submission->getData('contextId')); + $submissionContext = app()->get('context')->get($submission->getData('contextId')); } $locales = $submissionContext->getSupportedFormLocaleNames(); diff --git a/pages/preprint/PreprintHandler.php b/pages/preprint/PreprintHandler.php index 527e95ef18..dd11a617ef 100644 --- a/pages/preprint/PreprintHandler.php +++ b/pages/preprint/PreprintHandler.php @@ -19,7 +19,6 @@ use APP\core\Application; use APP\core\Request; -use APP\core\Services; use APP\facades\Repo; use APP\handler\Handler; use APP\observers\events\UsageEvent; @@ -374,11 +373,11 @@ public function download($args, $request) if (!Hook::call('PreprintHandler::download', [$this->preprint, &$this->galley, &$this->submissionFileId])) { $submissionFile = Repo::submissionFile()->get($this->submissionFileId); - if (!Services::get('file')->fs->has($submissionFile->getData('path'))) { + if (!app()->get('file')->fs->has($submissionFile->getData('path'))) { $request->getDispatcher()->handle404(); } - $filename = Services::get('file')->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name')); + $filename = app()->get('file')->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name')); // if the file is a galley file (i.e. not a dependent file e.g. CSS or images), fire an usage event. if ($this->galley->getData('submissionFileId') == $this->submissionFileId) { @@ -395,7 +394,7 @@ public function download($args, $request) $returner = true; Hook::call('FileManager::downloadFileFinished', [&$returner]); - Services::get('file')->download($submissionFile->getData('fileId'), $filename); + app()->get('file')->download($submissionFile->getData('fileId'), $filename); } } else { header('HTTP/1.0 403 Forbidden'); diff --git a/pages/workflow/WorkflowHandler.php b/pages/workflow/WorkflowHandler.php index 93f2d7ffef..e6625bc9e1 100644 --- a/pages/workflow/WorkflowHandler.php +++ b/pages/workflow/WorkflowHandler.php @@ -17,7 +17,6 @@ namespace APP\pages\workflow; use APP\core\Application; -use APP\core\Services; use APP\decision\types\Decline; use APP\decision\types\RevertDecline; use APP\facades\Repo; @@ -70,7 +69,7 @@ public function setupIndex($request) $submissionContext = $request->getContext(); if ($submission->getData('contextId') !== $submissionContext->getId()) { - $submissionContext = Services::get('context')->get($submission->getData('contextId')); + $submissionContext = app()->get('context')->get($submission->getData('contextId')); } $latestPublication = $submission->getLatestPublication(); diff --git a/tools/buildpkg.sh b/tools/buildpkg.sh index 7fdbbd4947..ca7e27dbcd 100755 --- a/tools/buildpkg.sh +++ b/tools/buildpkg.sh @@ -76,7 +76,6 @@ plugins/generic/citationStyleLanguage/lib/vendor/guzzle/guzzle/tests/Guzzle/Test plugins/generic/citationStyleLanguage/lib/vendor/symfony/config/Tests/ \ lib/pkp/lib/vendor/symfony/translation/Tests/ \ lib/pkp/lib/vendor/symfony/process/Tests/ \ -lib/pkp/lib/vendor/pimple/pimple/src/Pimple/Tests/ \ lib/pkp/lib/vendor/robloach/component-installer/tests/ComponentInstaller/Test/ \ lib/pkp/lib/vendor/michelf/php-markdown/test \ plugins/generic/citationStyleLanguage/lib/vendor/satooshi/php-coveralls/tests/ \ @@ -87,7 +86,6 @@ plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/example/ lib/pkp/lib/vendor/nikic/fast-route/test/ \ lib/pkp/lib/vendor/ezyang/htmlpurifier/tests/ \ lib/pkp/lib/vendor/ezyang/htmlpurifier/smoketests/ \ -lib/pkp/lib/vendor/pimple/pimple/ext/pimple/tests/ \ lib/pkp/lib/vendor/robloach/component-installer/tests/ \ lib/pkp/lib/vendor/swiftmailer/swiftmailer/tests/ \ lib/pkp/lib/vendor/dragonmantank/cron-expression/tests/ \