diff --git a/classes/core/AppServiceProvider.php b/classes/core/AppServiceProvider.php index 1d05a94f59d..6e0a1ff0783 100644 --- a/classes/core/AppServiceProvider.php +++ b/classes/core/AppServiceProvider.php @@ -3,23 +3,24 @@ /** * @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\PublicationFormatService; +use APP\services\StatsEditorialService; +use APP\services\StatsPublicationService; use PKP\core\PKPRequest; -use PKP\submissionFile\Collector as SubmissionFileCollector; -use PKP\submissionFile\SubmissionFile as BaseSubmissionFile; class AppServiceProvider extends \PKP\core\AppServiceProvider { @@ -32,7 +33,19 @@ public function register() $this->app->bind(Request::class, PKPRequest::class); - $this->app->bind(\APP\submissionFile\Collector::class, SubmissionFileCollector::class); - $this->app->bind(\APP\submissionFile\SubmissionFile::class, BaseSubmissionFile::class); + // Publication Format service + $this->app->singleton('publicationFormat', fn ($app) => new PublicationFormatService()); + + // 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 dd255c97be3..c2434238962 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\OMPServiceProvider()); - } } if (!PKP_STRICT_MODE) { diff --git a/classes/publication/Repository.php b/classes/publication/Repository.php index f36db25be6f..e2344df1a91 100644 --- a/classes/publication/Repository.php +++ b/classes/publication/Repository.php @@ -14,7 +14,6 @@ namespace APP\publication; use APP\core\Application; -use APP\core\Services; use APP\facades\Repo; use APP\file\PublicFileManager; use APP\monograph\ChapterDAO; @@ -74,7 +73,7 @@ public function add(Publication $publication): int $submission = Repo::submission()->get($publication->getData('submissionId')); $submissionContext = $this->request->getContext(); if ($submissionContext->getId() !== $submission->getData('contextId')) { - $submissionContext = Services::get('context')->get($submission->getData('contextId')); + $submissionContext = app()->get('context')->get($submission->getData('contextId')); } $supportedLocales = $submission->getPublicationLanguages($submissionContext->getSupportedSubmissionMetadataLocales()); @@ -258,7 +257,7 @@ public function edit(Publication $publication, array $params): Publication $submission = Repo::submission()->get($publication->getData('submissionId')); $submissionContext = $this->request->getContext(); if ($submissionContext->getId() !== $submission->getData('contextId')) { - $submissionContext = Services::get('context')->get($submission->getData('contextId')); + $submissionContext = app()->get('context')->get($submission->getData('contextId')); } foreach ($params['coverImage'] as $localeKey => $newCoverImage) { @@ -301,7 +300,7 @@ public function publish(Publication $publication) if ($submission->getData('currentPublicationId') === $publication->getId()) { $context = $this->request->getContext(); if (!$context || $context->getId() !== $submission->getData('contextId')) { - $context = Services::get('context')->get($submission->getData('contextId')); + $context = app()->get('context')->get($submission->getData('contextId')); } // Remove publication format tombstones for this publication @@ -350,7 +349,7 @@ public function unpublish(Publication $publication) parent::unpublish($publication); $submission = Repo::submission()->get($publication->getData('submissionId')); - $submissionContext = Services::get('context')->get($submission->getData('contextId')); + $submissionContext = app()->get('context')->get($submission->getData('contextId')); // Create tombstones for this publication $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager(); @@ -384,12 +383,12 @@ public function unpublish(Publication $publication) public function delete(Publication $publication) { $submission = Repo::submission()->get($publication->getData('submissionId')); - $context = Services::get('context')->get($submission->getData('contextId')); + $context = app()->get('context')->get($submission->getData('contextId')); // Delete Publication Formats (and all related objects) $publicationFormats = $publication->getData('publicationFormats'); foreach ($publicationFormats as $publicationFormat) { - Services::get('publicationFormat')->deleteFormat($publicationFormat, $submission, $context); + app()->get('publicationFormat')->deleteFormat($publicationFormat, $submission, $context); } // Delete chapters and assigned chapter authors. diff --git a/classes/publicationFormat/PublicationFormat.php b/classes/publicationFormat/PublicationFormat.php index fb7cffdf292..aaf5b88ff55 100644 --- a/classes/publicationFormat/PublicationFormat.php +++ b/classes/publicationFormat/PublicationFormat.php @@ -20,7 +20,6 @@ use APP\codelist\ONIXCodelistItemDAO; use APP\core\Application; -use APP\core\Services; use APP\facades\Repo; use PKP\db\DAORegistry; use PKP\db\DAOResultFactory; @@ -322,7 +321,7 @@ public function getCalculatedFileSize() foreach ($stageMonographFiles as $monographFile) { if ($monographFile->getViewable()) { - $fileSize += (int) Services::get('file')->fs->fileSize($monographFile->getData('path')); + $fileSize += (int) app()->get('file')->fs->fileSize($monographFile->getData('path')); } } diff --git a/classes/search/MonographSearch.php b/classes/search/MonographSearch.php index 52444980b07..b3c988e34f0 100644 --- a/classes/search/MonographSearch.php +++ b/classes/search/MonographSearch.php @@ -21,7 +21,6 @@ use APP\core\Application; use APP\core\Request; -use APP\core\Services; use APP\facades\Repo; use APP\press\Press; use PKP\db\DAORegistry; @@ -69,7 +68,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/OMPServiceProvider.php b/classes/services/OMPServiceProvider.php deleted file mode 100644 index ec6fc9606cc..00000000000 --- a/classes/services/OMPServiceProvider.php +++ /dev/null @@ -1,90 +0,0 @@ -get($this->getData('contextId')); + $context = app()->get('context')->get($this->getData('contextId')); $fieldValue = null; // Scrutinizer switch ($field) { case static::PERMISSIONS_FIELD_LICENSE_URL: diff --git a/classes/sushi/PR.php b/classes/sushi/PR.php index 8fbe4b1d4ea..adf680055d5 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; @@ -144,7 +143,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/classes/sushi/TR.php b/classes/sushi/TR.php index 1f71404d0f0..e3e8f53e14f 100644 --- a/classes/sushi/TR.php +++ b/classes/sushi/TR.php @@ -17,7 +17,6 @@ namespace APP\sushi; -use APP\core\Services; use APP\facades\Repo; use PKP\statistics\PKPStatisticsHelper; use PKP\sushi\CounterR5Report; @@ -193,7 +192,7 @@ public function getReportItems(): array // do not consider section_type filter now, but later when grouping by submission // 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/controllers/grid/catalogEntry/PublicationFormatGridHandler.php b/controllers/grid/catalogEntry/PublicationFormatGridHandler.php index fd6502ed40c..a2d0d6c927a 100644 --- a/controllers/grid/catalogEntry/PublicationFormatGridHandler.php +++ b/controllers/grid/catalogEntry/PublicationFormatGridHandler.php @@ -22,7 +22,6 @@ use APP\controllers\tab\pubIds\form\PublicIdentifiersForm; use APP\core\Application; use APP\core\Request; -use APP\core\Services; use APP\facades\Repo; use APP\log\event\SubmissionEventLogEntry; use APP\notification\Notification; @@ -347,7 +346,7 @@ public function deleteFormat($args, $request) } /** @var PublicationFormatService */ - $publicationFormatService = Services::get('publicationFormat'); + $publicationFormatService = app()->get('publicationFormat'); $publicationFormatService->deleteFormat($representation, $submission, $context); $currentUser = $request->getUser(); diff --git a/controllers/grid/navigationMenus/form/NavigationMenuItemsForm.php b/controllers/grid/navigationMenus/form/NavigationMenuItemsForm.php index dba67d27bbc..0b0b0769404 100644 --- a/controllers/grid/navigationMenus/form/NavigationMenuItemsForm.php +++ b/controllers/grid/navigationMenus/form/NavigationMenuItemsForm.php @@ -17,7 +17,6 @@ namespace APP\controllers\grid\navigationMenus\form; use APP\core\Application; -use APP\core\Services; use APP\facades\Repo; use APP\section\Section; use APP\services\NavigationMenuService; @@ -35,7 +34,7 @@ class NavigationMenuItemsForm extends PKPNavigationMenuItemsForm */ public function fetch($request, $template = null, $display = false) { - $customTemplates = Services::get('navigationMenu')->getMenuItemCustomEditTemplates(); + $customTemplates = app()->get('navigationMenu')->getMenuItemCustomEditTemplates(); $request = Application::get()->getRequest(); $context = $request->getContext(); diff --git a/pages/catalog/CatalogBookHandler.php b/pages/catalog/CatalogBookHandler.php index 19e83dc7380..6fb7fac0f29 100755 --- a/pages/catalog/CatalogBookHandler.php +++ b/pages/catalog/CatalogBookHandler.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\monograph\Chapter; @@ -390,7 +389,7 @@ public function download($args, $request, $view = false) } $path = $submissionFile->getData('path'); - $filename = Services::get('file')->formatFilename($path, $submissionFile->getLocalizedData('name')); + $filename = app()->get('file')->formatFilename($path, $submissionFile->getLocalizedData('name')); switch ($submissionFile->getData('assocType')) { case Application::ASSOC_TYPE_PUBLICATION_FORMAT: // Publication format file if ($submissionFile->getData('assocId') != $publicationFormat->getId() || $submissionFile->getDirectSalesPrice() === null) { @@ -403,7 +402,7 @@ public function download($args, $request, $view = false) if (!$genre->getDependent()) { $dispatcher->handle404(); } - return Services::get('file')->download($submissionFile->getData('fileId'), $filename); + return app()->get('file')->download($submissionFile->getData('fileId'), $filename); default: $dispatcher->handle404(); } @@ -464,7 +463,7 @@ public function download($args, $request, $view = false) } $returner = true; Hook::call('FileManager::downloadFileFinished', [&$returner]); - return Services::get('file')->download($submissionFile->getData('fileId'), $filename, $inline); + return app()->get('file')->download($submissionFile->getData('fileId'), $filename, $inline); } // Fall-through: user needs to pay for purchase. diff --git a/pages/workflow/WorkflowHandler.php b/pages/workflow/WorkflowHandler.php index 2f5400bc478..73dae3d1fc7 100644 --- a/pages/workflow/WorkflowHandler.php +++ b/pages/workflow/WorkflowHandler.php @@ -19,7 +19,6 @@ use APP\components\listPanels\ContributorsListPanel; use APP\core\Application; use APP\core\Request; -use APP\core\Services; use APP\decision\types\AcceptFromInternal; use APP\decision\types\CancelInternalReviewRound; use APP\decision\types\DeclineInternal; @@ -112,7 +111,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/plugins/generic/htmlMonographFile/HtmlMonographFilePlugin.php b/plugins/generic/htmlMonographFile/HtmlMonographFilePlugin.php index 936e7ccf026..10c1a0bec4d 100644 --- a/plugins/generic/htmlMonographFile/HtmlMonographFilePlugin.php +++ b/plugins/generic/htmlMonographFile/HtmlMonographFilePlugin.php @@ -16,7 +16,6 @@ use APP\core\Application; use APP\core\Request; -use APP\core\Services; use APP\facades\Repo; use APP\file\PublicFileManager; use APP\monograph\ChapterDAO; @@ -163,7 +162,7 @@ public function downloadCallback($hookName, $params) */ public function _getHTMLContents($request, $monograph, $publicationFormat, $submissionFile) { - $contents = Services::get('file')->fs->read($submissionFile->getData('path')); + $contents = app()->get('file')->fs->read($submissionFile->getData('path')); // Replace media file references $proofCollector = Repo::submissionFile() diff --git a/plugins/importexport/csv/CSVImportExportPlugin.php b/plugins/importexport/csv/CSVImportExportPlugin.php index 6a72792f729..bfded81317e 100644 --- a/plugins/importexport/csv/CSVImportExportPlugin.php +++ b/plugins/importexport/csv/CSVImportExportPlugin.php @@ -16,7 +16,6 @@ use APP\core\Application; use APP\core\Request; -use APP\core\Services; use APP\facades\Repo; use APP\publicationFormat\PublicationDateDAO; use APP\publicationFormat\PublicationFormatDAO; @@ -264,7 +263,7 @@ public function executeCLI($scriptName, &$args) $extension = $fileManager->parseFileExtension($filename); $submissionDir = Repo::submissionFile()->getSubmissionDir($press->getId(), $submissionId); /** @var \PKP\services\PKPFileService */ - $fileService = Services::get('file'); + $fileService = app()->get('file'); $fileId = $fileService->add( $filename, $submissionDir . '/' . uniqid() . '.' . $extension diff --git a/tests/classes/monograph/SubmissionFileDAOTest.php b/tests/classes/monograph/SubmissionFileDAOTest.php index 3913bcda43c..4d5276566f2 100644 --- a/tests/classes/monograph/SubmissionFileDAOTest.php +++ b/tests/classes/monograph/SubmissionFileDAOTest.php @@ -21,7 +21,6 @@ use APP\core\Application; use APP\core\PageRouter; use APP\core\Request; -use APP\core\Services; use APP\facades\Repo; use APP\press\Press; use APP\submission\Submission; @@ -77,7 +76,7 @@ protected function setUp(): void // Register a mock monograph DAO. $submissionDao = $this->getMockBuilder(\APP\submission\DAO::class) - ->setConstructorArgs([Services::get('schema')]) + ->setConstructorArgs([app()->get('schema')]) ->onlyMethods(['get']) ->getMock(); $monograph = new Submission(); @@ -153,7 +152,7 @@ public function testSubmissionFileCrud() // Create test files $submissionDir = Repo::submissionFile() ->getSubmissionDir(static::SUBMISSION_FILE_DAO_TEST_PRESS_ID, $submissionId); - $fileId1 = Services::get('file')->add( + $fileId1 = app()->get('file')->add( $this->testFile1, $submissionDir . '/' . uniqid() . '.txt' ); @@ -167,7 +166,7 @@ public function testSubmissionFileCrud() 'createdAt' => '2011-12-05 00:00:00', 'updatedAt' => '2011-12-05 00:00:00', ]); - $fileId2 = Services::get('file')->add( + $fileId2 = app()->get('file')->add( $this->testFile2, $submissionDir . '/' . uniqid() . '.txt' ); @@ -207,7 +206,7 @@ public function testSubmissionFileCrud() static::assertEquals($submissionFile2->getData('genreId'), static::SUBMISSION_FILE_DAO_TEST_ART_GENRE_ID); // Save a new revision of a submission file - $fileId3 = Services::get('file')->add( + $fileId3 = app()->get('file')->add( $this->testFile3, $submissionDir . '/' . uniqid() . '.txt' ); diff --git a/tools/buildpkg.sh b/tools/buildpkg.sh index 8f3752ee27b..447d4654907 100755 --- a/tools/buildpkg.sh +++ b/tools/buildpkg.sh @@ -87,7 +87,6 @@ lib/pkp/lib/vendor/leafo/lessphp/docs \ lib/pkp/lib/vendor/moxiecode/plupload/examples \ lib/pkp/lib/vendor/robloach \ lib/pkp/lib/vendor/smarty/smarty/demo \ -lib/pkp/lib/vendor/pimple/pimple/ext/pimple/tests \ lib/pkp/lib/vendor/phpunit \ lib/pkp/lib/vendor/phpdocumentor/reflection-docblock \ lib/pkp/lib/vendor/doctrine/instantiator/tests \