Skip to content

Commit

Permalink
Improve Application/PKPApplication typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Sep 11, 2024
1 parent 0ec0f46 commit 1b94fa4
Show file tree
Hide file tree
Showing 26 changed files with 47 additions and 96 deletions.
2 changes: 1 addition & 1 deletion api/v1/_submissions/BackendSubmissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function payment(Request $illuminateRequest): JsonResponse
], Response::HTTP_NOT_FOUND);
}

$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
$publicationFeeEnabled = $paymentManager->publicationEnabled();
if (!$publicationFeeEnabled) {
return response()->json([
Expand Down
2 changes: 1 addition & 1 deletion api/v1/submissions/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function getSubmissionPaymentForm(Request $illuminateRequest): JsonRes

$submission = $data['submission']; /** @var Submission $submission */
$context = $data['context']; /** @var Context $context*/
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);

if (!$paymentManager->publicationEnabled()) {
return response()->json([
Expand Down
58 changes: 17 additions & 41 deletions classes/core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use APP\facades\Repo;
use APP\journal\JournalDAO;
use APP\payment\ojs\OJSPaymentManager;
use APP\search\ArticleSearchIndex;
use PKP\context\Context;
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
Expand Down Expand Up @@ -75,41 +77,33 @@ public function getContextName(): string

/**
* Get the symbolic name of this application
*
* @return string
*/
public static function getName()
public static function getName(): string
{
return 'ojs2';
}

/**
* Get the locale key for the name of this application.
*
* @return string
*/
public function getNameKey()
public function getNameKey(): string
{
return('common.software');
}

/**
* Get the URL to the XML descriptor for the current version of this
* application.
*
* @return string
*/
public function getVersionDescriptorUrl()
public function getVersionDescriptorUrl(): string
{
return 'https://pkp.sfu.ca/ojs/xml/ojs-version.xml';
}

/**
* Get the map of DAOName => full.class.Path for this application.
*
* @return array
*/
public function getDAOMap()
public function getDAOMap(): array
{
return array_merge(parent::getDAOMap(), [
'ArticleSearchDAO' => 'APP\search\ArticleSearchDAO',
Expand All @@ -130,10 +124,8 @@ public function getDAOMap()

/**
* Get the list of plugin categories for this application.
*
* @return array
*/
public function getPluginCategories()
public function getPluginCategories(): array
{
return [
// NB: Meta-data plug-ins are first in the list as this
Expand All @@ -156,20 +148,14 @@ public function getPluginCategories()

/**
* Get the top-level context DAO.
*
* @return JournalDAO
*/
public static function getContextDAO()
public static function getContextDAO(): JournalDAO
{
/** @var JournalDAO */
$dao = DAORegistry::getDAO('JournalDAO');
return $dao;
return DAORegistry::getDAO('JournalDAO');
}

/**
* Get the representation DAO.
*
* @return \PKP\galley\DAO&RepresentationDAOInterface
*/
public static function getRepresentationDAO(): RepresentationDAOInterface
{
Expand All @@ -179,25 +165,23 @@ public static function getRepresentationDAO(): RepresentationDAOInterface
/**
* Get a SubmissionSearchIndex instance.
*/
public static function getSubmissionSearchIndex()
public static function getSubmissionSearchIndex(): ArticleSearchIndex
{
return new \APP\search\ArticleSearchIndex();
return new ArticleSearchIndex();
}

/**
* Get a SubmissionSearchDAO instance.
*/
public static function getSubmissionSearchDAO()
public static function getSubmissionSearchDAO(): \APP\search\ArticleSearchDAO
{
return DAORegistry::getDAO('ArticleSearchDAO');
}

/**
* Get the stages used by the application.
*
* @return array
*/
public static function getApplicationStages()
public static function getApplicationStages(): array
{
// We leave out WORKFLOW_STAGE_ID_PUBLISHED since it technically is not a 'stage'.
return [
Expand All @@ -210,28 +194,24 @@ public static function getApplicationStages()

/**
* Returns the context type for this application.
*
* @return int Application::ASSOC_TYPE_...
*/
public static function getContextAssocType()
public static function getContextAssocType(): int
{
return self::ASSOC_TYPE_JOURNAL;
}

/**
* Get the file directory array map used by the application.
*/
public static function getFileDirectories()
public static function getFileDirectories(): array
{
return ['context' => '/journals/', 'submission' => '/articles/'];
}

/**
* @copydoc PKPApplication::getRoleNames()
*
* @param null|mixed $roleIds
*/
public static function getRoleNames($contextOnly = false, $roleIds = null)
public static function getRoleNames(bool $contextOnly = false, ?array $roleIds = null): array
{
$roleNames = parent::getRoleNames($contextOnly, $roleIds);
if (!$roleIds || in_array(Role::ROLE_ID_SUBSCRIPTION_MANAGER, $roleIds)) {
Expand All @@ -242,12 +222,8 @@ public static function getRoleNames($contextOnly = false, $roleIds = null)

/**
* Get the payment manager.
*
* @param \APP\journal\Journal $context
*
* @return OJSPaymentManager
*/
public static function getPaymentManager($context)
public function getPaymentManager(Context $context): OJSPaymentManager
{
return new OJSPaymentManager($context);
}
Expand Down
2 changes: 1 addition & 1 deletion classes/decision/types/Accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getSteps(Submission $submission, Context $context, User $editor,
$steps = parent::getSteps($submission, $context, $editor, $reviewRound);

// Request payment if configured
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
if ($paymentManager->publicationEnabled()) {
$steps->addStep($this->getPaymentForm($context), true);
}
Expand Down
2 changes: 1 addition & 1 deletion classes/decision/types/SkipExternalReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getSteps(Submission $submission, Context $context, User $editor,
$steps = parent::getSteps($submission, $context, $editor, $reviewRound);

// Request payment if configured
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
if ($paymentManager->publicationEnabled()) {
$steps->addStep($this->getPaymentForm($context), true);
}
Expand Down
4 changes: 2 additions & 2 deletions classes/decision/types/traits/RequestPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function getPaymentForm(Context $context): Form
*/
protected function validatePaymentAction(array $action, string $actionErrorKey, Validator $validator, Context $context)
{
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
if (!$paymentManager->publicationEnabled()) {
$validator->errors()->add($actionErrorKey . '.requestPayment', __('payment.requestPublicationFee.notEnabled'));
} elseif (!isset($action['requestPayment'])) {
Expand All @@ -62,7 +62,7 @@ protected function validatePaymentAction(array $action, string $actionErrorKey,
*/
protected function requestPayment(Submission $submission, User $editor, Context $context)
{
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
$queuedPayment = $paymentManager->createQueuedPayment(
Application::get()->getRequest(),
OJSPaymentManager::PAYMENT_TYPE_PUBLICATION,
Expand Down
2 changes: 1 addition & 1 deletion classes/journal/JournalDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ public function removeCurrentIssue(int $contextId)
}
}

if (!PKP_STRICT_MODE) {
if (!defined('PKP_STRICT_MODE')) {
class_alias('\APP\journal\JournalDAO', '\JournalDAO');
}
17 changes: 0 additions & 17 deletions classes/payment/ojs/OJSPaymentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,3 @@ public function getPaymentName($payment)
}
}
}

if (!PKP_STRICT_MODE) {
class_alias('\APP\payment\ojs\OJSPaymentManager', '\OJSPaymentManager');
foreach ([
'PAYMENT_TYPE_MEMBERSHIP',
'PAYMENT_TYPE_RENEW_SUBSCRIPTION',
'PAYMENT_TYPE_PURCHASE_ARTICLE',
'PAYMENT_TYPE_DONATION',
'PAYMENT_TYPE_SUBMISSION',
'PAYMENT_TYPE_FASTTRACK',
'PAYMENT_TYPE_PUBLICATION',
'PAYMENT_TYPE_PURCHASE_SUBSCRIPTION',
'PAYMENT_TYPE_PURCHASE_ISSUE',
] as $constantName) {
define($constantName, constant('\OJSPaymentManager::' . $constantName));
}
}
2 changes: 1 addition & 1 deletion classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function validatePublish(Publication $publication, Submission $submission
if (!$context || $context->getId() !== $submission->getData('contextId')) {
$context = app()->get('context')->get($submission->getData('contextId'));
}
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
$completedPaymentDao = DAORegistry::getDAO('OJSCompletedPaymentDAO'); /** @var OJSCompletedPaymentDAO $completedPaymentDao */
$publicationFeeEnabled = $paymentManager->publicationEnabled();
$publicationFeePayment = $completedPaymentDao->getByAssoc(null, OJSPaymentManager::PAYMENT_TYPE_PUBLICATION, $submission->getId());
Expand Down
4 changes: 0 additions & 4 deletions classes/search/ArticleSearchDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,3 @@ public function getPhraseResults($journal, $phrase, $publishedFrom = null, $publ
return $returner;
}
}

if (!PKP_STRICT_MODE) {
class_alias('\APP\search\ArticleSearchDAO', '\ArticleSearchDAO');
}
4 changes: 0 additions & 4 deletions classes/search/ArticleSearchIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,3 @@ protected function _flattenLocalizedArray($arrayWithLocales)
return $flattenedArray;
}
}

if (!PKP_STRICT_MODE) {
class_alias('\APP\search\ArticleSearchIndex', '\ArticleSearchIndex');
}
4 changes: 2 additions & 2 deletions classes/services/NavigationMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ public function getDisplayStatusCallback($hookName, $args)
break;
case self::NMI_TYPE_SUBSCRIPTIONS:
if ($context) {
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
$navigationMenuItem->setIsDisplayed($context->getData('paymentsEnabled') && $paymentManager->isConfigured());
}
break;
case self::NMI_TYPE_MY_SUBSCRIPTIONS:
if ($context) {
$paymentManager = Application::getPaymentManager($context);
$paymentManager = Application::get()->getPaymentManager($context);
$navigationMenuItem->setIsDisplayed(Validation::isLoggedIn() && $context->getData('paymentsEnabled') && $paymentManager->isConfigured() && $context->getData('publishingMode') == \APP\journal\Journal::PUBLISHING_MODE_SUBSCRIPTION);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion classes/subscription/form/SubscriptionPolicyForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function __construct()
*/
public function fetch($request, $template = null, $display = false)
{
$paymentManager = Application::getPaymentManager($request->getContext());
$paymentManager = Application::get()->getPaymentManager($request->getContext());
$templateMgr = TemplateManager::getManager();
$templateMgr->assign([
'validNumMonthsBeforeExpiry' => $this->validNumMonthsBeforeExpiry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function execute(...$functionArgs)
$subscription = $this->subscription;
}

$paymentManager = Application::getPaymentManager($journal);
$paymentManager = Application::get()->getPaymentManager($journal);
$paymentPlugin = $paymentManager->getPaymentPlugin();

if ($paymentPlugin->getName() == 'ManualPayment') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function execute(...$functionArgs)
$subscription = $this->subscription;
}

$paymentManager = Application::getPaymentManager($journal);
$paymentManager = Application::get()->getPaymentManager($journal);
$paymentPlugin = $paymentManager->getPaymentPlugin();

if ($paymentPlugin->getName() == 'ManualPayment') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getTemplateVarsFromRowColumn($row, $column)
$user = Repo::user()->get($payment->getUserId(), true);
return ['label' => $user ? $user->getFullName() : __('common.user.nonexistent')]; // If no $user, returns "[Nonexistent user]" to avoid null user
case 'type':
$paymentManager = Application::getPaymentManager($this->_request->getJournal());
$paymentManager = Application::get()->getPaymentManager($this->_request->getJournal());
return ['label' => $paymentManager->getPaymentName($payment)];
case 'amount':
return ['label' => $payment->getAmount() . ' ' . $payment->getCurrencyCode()];
Expand Down
2 changes: 1 addition & 1 deletion pages/about/AboutHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function subscriptions($args, $request)
$subscriptionTypeDao = DAORegistry::getDAO('SubscriptionTypeDAO');

if ($journal) {
$paymentManager = Application::getPaymentManager($journal);
$paymentManager = Application::get()->getPaymentManager($journal);
if (!($journal->getData('paymentsEnabled') && $paymentManager->isConfigured())) {
$request->redirect(null, 'index');
}
Expand Down
4 changes: 2 additions & 2 deletions pages/issue/IssueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function userCanViewGalley($request)
$subscribedUser = $issueAction->subscribedUser($user, $journal, $issue->getId());
if (!$subscribedUser) {
// Check if payments are enabled,
$paymentManager = Application::getPaymentManager($journal);
$paymentManager = Application::get()->getPaymentManager($journal);

if ($paymentManager->purchaseIssueEnabled() || $paymentManager->membershipEnabled()) {
// If only pdf files are being restricted, then approve all non-pdf galleys
Expand Down Expand Up @@ -435,7 +435,7 @@ public static function _setupIssueTemplate(Request $request, Issue $issue, ?Jour
($user && $completedPaymentDao->hasPaidPurchaseIssue($user->getId(), $issue->getId()))
]);

$paymentManager = Application::getPaymentManager($journal);
$paymentManager = Application::get()->getPaymentManager($journal);
if ($paymentManager->onlyPdfEnabled()) {
$templateMgr->assign('restrictOnlyPdf', true);
}
Expand Down
2 changes: 1 addition & 1 deletion pages/payment/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function pay($args, $request)
Validation::redirectLogin();
}

$paymentManager = Application::getPaymentManager($request->getContext());
$paymentManager = Application::get()->getPaymentManager($request->getContext());
$templateMgr = TemplateManager::getManager($request);
$queuedPaymentDao = DAORegistry::getDAO('QueuedPaymentDAO'); /** @var QueuedPaymentDAO $queuedPaymentDao */
$queuedPayment = $queuedPaymentDao->getById($queuedPaymentId = array_shift($args));
Expand Down
2 changes: 1 addition & 1 deletion pages/payments/PaymentsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function subscriptionPolicies($args, $request)

$templateMgr = TemplateManager::getManager($request);

$paymentManager = Application::getPaymentManager($request->getJournal());
$paymentManager = Application::get()->getPaymentManager($request->getJournal());
$templateMgr->assign('acceptSubscriptionPayments', $paymentManager->isConfigured());

$subscriptionPolicyForm = new SubscriptionPolicyForm();
Expand Down
Loading

0 comments on commit 1b94fa4

Please sign in to comment.