Skip to content

Commit

Permalink
pkp/pkp-lib#9913 removed pimple dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir authored and asmecher committed Aug 1, 2024
1 parent 21f3926 commit 18130b0
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 150 deletions.
33 changes: 23 additions & 10 deletions classes/core/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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());
}
}
18 changes: 5 additions & 13 deletions classes/core/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 6 additions & 7 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions classes/publicationFormat/PublicationFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
}
}

Expand Down
3 changes: 1 addition & 2 deletions classes/search/MonographSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
90 changes: 0 additions & 90 deletions classes/services/OMPServiceProvider.php

This file was deleted.

3 changes: 1 addition & 2 deletions classes/submission/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace APP\submission;

use APP\core\Services;
use APP\facades\Repo;
use APP\publication\Publication;
use PKP\submission\PKPSubmission;
Expand Down Expand Up @@ -56,7 +55,7 @@ public function getSectionId()
*/
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 static::PERMISSIONS_FIELD_LICENSE_URL:
Expand Down
3 changes: 1 addition & 2 deletions classes/sushi/PR.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace APP\sushi;

use APP\core\Services;
use PKP\statistics\PKPStatisticsHelper;
use PKP\sushi\CounterR5Report;

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions classes/sushi/TR.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace APP\sushi;

use APP\core\Services;
use APP\facades\Repo;
use PKP\statistics\PKPStatisticsHelper;
use PKP\sushi\CounterR5Report;
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\NotificationManager;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions pages/catalog/CatalogBookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 18130b0

Please sign in to comment.