-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6173 from impress-org/scope/migrate-addon-concept…
…s-into-core
- Loading branch information
Showing
15 changed files
with
3,419 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
Oops, something went wrong.