Skip to content

Commit

Permalink
Merge pull request #6173 from impress-org/scope/migrate-addon-concept…
Browse files Browse the repository at this point in the history
…s-into-core
  • Loading branch information
JasonTheAdams authored Feb 7, 2022
2 parents 9c46ee2 + 69c2711 commit 0f95d8c
Show file tree
Hide file tree
Showing 15 changed files with 3,419 additions and 55 deletions.
45 changes: 24 additions & 21 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use Give\Framework\Exceptions\UncaughtExceptionLogger;
use Give\Framework\Migrations\MigrationsServiceProvider;
use Give\InPluginUpsells\ServiceProvider as InPluginUpsellsServiceProvider;
use Give\LegacySubscriptions\ServiceProvider as LegacySubscriptionsServiceProvider;
use Give\License\LicenseServiceProvider;
use Give\Log\LogServiceProvider;
use Give\MigrationLog\MigrationLogServiceProvider;
Expand Down Expand Up @@ -77,28 +78,29 @@
* @since 2.8.0 build in a service container
* @since 1.0
*
* @property-read Give_API $api
* @property-read Give_Async_Process $async_process
* @property-read Give_Comment $comment
* @property-read Give_DB_Donors $donors
* @property-read Give_DB_Donor_Meta $donor_meta
* @property-read Give_Emails $emails
* @property-read Give_Email_Template_Tags $email_tags
* @property-read Give_DB_Form_Meta $form_meta
* @property-read Give_Admin_Settings $give_settings
* @property-read Give_HTML_Elements $html
* @property-read Give_Logging $logs
* @property-read Give_Notices $notices
* @property-read Give_DB_Payment_Meta $payment_meta
* @property-read Give_Roles $roles
* @property-read FormRoute $routeForm
* @property-read Templates $templates
* @property-read Give_Scripts $scripts
* @property-read Give_DB_Sequential_Ordering $sequential_donation_db
* @property-read Give_API $api
* @property-read Give_Async_Process $async_process
* @property-read Give_Comment $comment
* @property-read Give_DB_Donors $donors
* @property-read Give_DB_Donor_Meta $donor_meta
* @property-read Give_Emails $emails
* @property-read Give_Email_Template_Tags $email_tags
* @property-read Give_DB_Form_Meta $form_meta
* @property-read Give_Admin_Settings $give_settings
* @property-read Give_HTML_Elements $html
* @property-read Give_Logging $logs
* @property-read Give_Notices $notices
* @property-read Give_DB_Payment_Meta $payment_meta
* @property-read Give_Roles $roles
* @property-read FormRoute $routeForm
* @property-read Templates $templates
* @property-read Give_Scripts $scripts
* @property-read Give_DB_Sequential_Ordering $sequential_donation_db
* @property-read Give_Sequential_Donation_Number $seq_donation_number
* @property-read Give_Session $session
* @property-read Give_DB_Sessions $session_db
* @property-read Give_Tooltips $tooltips
* @property-read Give_Session $session
* @property-read Give_DB_Sessions $session_db
* @property-read Give_Tooltips $tooltips
* @property-read Give_Recurring_DB_Subscription_Meta $subscription_meta
*
* @mixin Container
*/
Expand Down Expand Up @@ -167,6 +169,7 @@ final class Give
Give\Email\ServiceProvider::class,
DonationSummaryServiceProvider::class,
PaymentGatewaysServiceProvider::class,
LegacySubscriptionsServiceProvider::class
];

/**
Expand Down
9 changes: 3 additions & 6 deletions src/DonationSummary/SummaryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,13 @@ protected function isFeeRecoveryEnabled()
}

/**
* @since 2.17.0
* @unreleased - remove check for Give_Recurring
* @return bool
* @since 2.17.0
*/
protected function isRecurringEnabled()
{
if (class_exists('\Give_Recurring')) {
return Give_Recurring()->is_recurring($this->formID);
}

return false;
return give_recurring_is_recurring($this->formID);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public function handleBeforeGateway($legacyDonationData, $registeredGateway)

$gatewayPaymentData = $formData->toGatewayPaymentData($donationId);

if (
function_exists('Give_Recurring') &&
Give_Recurring()->is_donation_recurring($formData->legacyDonationData)
) {
if (give_recurring_is_donation_recurring($formData->legacyDonationData)) {
$subscriptionData = SubscriptionData::fromRequest($legacyDonationData);
$subscriptionId = $this->createSubscription($donationId, $formData, $subscriptionData);

Expand Down
105 changes: 105 additions & 0 deletions src/LegacySubscriptions/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace Give\LegacySubscriptions;

use Closure;
use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;

/**
* Class ServiceProvider - LegacySubscriptions
*
* This handles the loading of all the legacy codebase included in the LegacySubscriptions /includes directory.
* DO NOT EXTEND THIS WITH NEW CODE as it is intended to shrink over time as we migrate over
* to the new ways of doing things.
*
* @unreleased
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register()
{
$recurringIsInstalled = defined('GIVE_RECURRING_VERSION') && GIVE_RECURRING_VERSION;
$recurringMeetsRequirements = $recurringIsInstalled && version_compare(GIVE_RECURRING_VERSION, '1.14.1', '>');

if ($recurringMeetsRequirements || !$recurringIsInstalled) {
$this->includeLegacyFiles();
$this->bindClasses();
}

$this->includeLegacyHelpers();
}

/**
* @inheritDoc
*/
public function boot()
{
}

/**
* Load all the legacy class files since they don't have autoloading
*
* @unreleased
*/
private function includeLegacyFiles()
{
require_once __DIR__ . '/includes/give-subscriptions-db.php';
require_once __DIR__ . '/includes/give-recurring-db-subscription-meta.php';
require_once __DIR__ . '/includes/give-recurring-cache.php';
require_once __DIR__ . '/includes/give-subscription.php';
require_once __DIR__ . '/includes/give-subscriptions-api.php';
require_once __DIR__ . '/includes/give-recurring-subscriber.php';
require_once __DIR__ . '/includes/give-recurring-cron.php';
}

/**
* Load all the legacy helpers
*
* @unreleased
*/
private function includeLegacyHelpers()
{
require_once __DIR__ . '/includes/give-recurring-helpers.php';
}

/**
* Binds the legacy classes to the service provider
*
* @unreleased
*/
private function bindClasses()
{
$this->bindInstance(
'subscription_meta',
'Give_Recurring_DB_Subscription_Meta',
'give-recurring-db-subscription-meta.php'
);
}

/**
* A helper for loading legacy classes that do not use autoloading, then binding their instance
* to the container.
*
* @unreleased
*
* @param string $alias
* @param string|Closure $class
* @param string $includesPath
* @param bool $singleton
*/
private function bindInstance($alias, $class, $includesPath, $singleton = false)
{
require_once __DIR__ . "/includes/$includesPath";

if ($class instanceof Closure) {
give()->instance($alias, $class());
} elseif ($singleton) {
give()->instance($alias, $class::get_instance());
} else {
give()->instance($alias, new $class());
}
}
}
Loading

0 comments on commit 0f95d8c

Please sign in to comment.