Actions
3 years ago
DataTransferObjects
3 years ago
Endpoints
2 years ago
Factories
2 years ago
LegacyListeners
3 years ago
ListTable
3 years ago
Migrations
3 years ago
Models
2 years ago
Repositories
3 years ago
ValueObjects
3 years ago
resources
1 year ago
ServiceProvider.php
3 years ago
SubscriptionsAdminPage.php
1 year ago
ServiceProvider.php
75 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Subscriptions; |
| 4 | |
| 5 | use Give\Framework\Migrations\MigrationsRegister; |
| 6 | use Give\Helpers\Hooks; |
| 7 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 8 | use Give\Subscriptions\LegacyListeners\DispatchGiveSubscriptionPostCreate; |
| 9 | use Give\Subscriptions\LegacyListeners\DispatchGiveSubscriptionPreCreate; |
| 10 | use Give\Subscriptions\ListTable\SubscriptionsListTable; |
| 11 | use Give\Subscriptions\Migrations\AddPaymentModeToSubscriptionTable; |
| 12 | use Give\Subscriptions\Migrations\CreateSubscriptionTables; |
| 13 | use Give\Subscriptions\Repositories\SubscriptionRepository; |
| 14 | |
| 15 | class ServiceProvider implements ServiceProviderInterface |
| 16 | { |
| 17 | /** |
| 18 | * @inheritDoc |
| 19 | */ |
| 20 | public function register() |
| 21 | { |
| 22 | give()->singleton('subscriptions', SubscriptionRepository::class); |
| 23 | give()->singleton(SubscriptionsListTable::class, function() { |
| 24 | $listTable = new SubscriptionsListTable(); |
| 25 | Hooks::doAction('givewp_subscriptions_list_table', $listTable); |
| 26 | |
| 27 | return $listTable; |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @inheritDoc |
| 33 | */ |
| 34 | public function boot() |
| 35 | { |
| 36 | $this->bootLegacyListeners(); |
| 37 | $this->registerMigrations(); |
| 38 | |
| 39 | $userId = get_current_user_id(); |
| 40 | $showLegacy = get_user_meta($userId, '_give_subscriptions_archive_show_legacy', true); |
| 41 | // only register new admin page if user hasn't chosen to use the old one |
| 42 | if (empty($showLegacy) && SubscriptionsAdminPage::isShowing()) { |
| 43 | Hooks::addAction('admin_enqueue_scripts', SubscriptionsAdminPage::class, 'loadScripts'); |
| 44 | } elseif (SubscriptionsAdminPage::isShowing()) { |
| 45 | Hooks::addAction('admin_head', SubscriptionsAdminPage::class, 'renderReactSwitch'); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Legacy Listeners |
| 51 | * |
| 52 | * @since 2.19.6 |
| 53 | */ |
| 54 | private function bootLegacyListeners() |
| 55 | { |
| 56 | Hooks::addAction('givewp_subscription_creating', DispatchGiveSubscriptionPreCreate::class); |
| 57 | Hooks::addAction('givewp_subscription_created', DispatchGiveSubscriptionPostCreate::class); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Registers database migrations with the MigrationsRunner |
| 62 | * |
| 63 | * @since 2.24.0 |
| 64 | */ |
| 65 | private function registerMigrations() |
| 66 | { |
| 67 | /** @var MigrationsRegister $register */ |
| 68 | $register = give(MigrationsRegister::class); |
| 69 | $register->addMigrations([ |
| 70 | CreateSubscriptionTables::class, |
| 71 | AddPaymentModeToSubscriptionTable::class, |
| 72 | ]); |
| 73 | } |
| 74 | } |
| 75 |