Feed
2 weeks ago
Integrations
4 months ago
Storage
2 weeks ago
Utils
5 months ago
ProductFeed.php
5 months ago
ProductFeed.php
94 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin class. |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\Internal\ProductFeed |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Automattic\WooCommerce\Internal\ProductFeed; |
| 11 | |
| 12 | use Automattic\WooCommerce\Internal\ProductFeed\Integrations\IntegrationInterface; |
| 13 | use Automattic\WooCommerce\Internal\RegisterHooksInterface; |
| 14 | use Automattic\WooCommerce\Internal\ProductFeed\Integrations\IntegrationRegistry; |
| 15 | use Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog\POSIntegration; |
| 16 | |
| 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | exit; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Main Product Feed class. |
| 23 | * |
| 24 | * @since 10.5.0 |
| 25 | */ |
| 26 | final class ProductFeed implements RegisterHooksInterface { |
| 27 | /** |
| 28 | * Integration registry. |
| 29 | * |
| 30 | * @var IntegrationRegistry |
| 31 | */ |
| 32 | private IntegrationRegistry $integration_registry; |
| 33 | |
| 34 | /** |
| 35 | * Dependency injector. |
| 36 | * |
| 37 | * @param IntegrationRegistry $integration_registry The integration registry. |
| 38 | * @param POSIntegration $pos_integration The POS integration. |
| 39 | * @internal |
| 40 | */ |
| 41 | public function init( // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingFinal |
| 42 | IntegrationRegistry $integration_registry, |
| 43 | POSIntegration $pos_integration |
| 44 | ): void { |
| 45 | $this->integration_registry = $integration_registry; |
| 46 | $this->integration_registry->register_integration( $pos_integration ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Allows extensions to register integrations. |
| 51 | * |
| 52 | * @since 10.5.0 |
| 53 | * @param IntegrationInterface $integration The integration to register. |
| 54 | * @return void |
| 55 | */ |
| 56 | public function register_integration( IntegrationInterface $integration ): void { |
| 57 | $this->integration_registry->register_integration( $integration ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Initialize plugin components |
| 62 | * |
| 63 | * @since 10.5.0 |
| 64 | */ |
| 65 | public function register(): void { |
| 66 | // Let all integrations register their hooks. |
| 67 | foreach ( $this->integration_registry->get_integrations() as $integration ) { |
| 68 | $integration->register_hooks(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Plugin activation |
| 74 | * |
| 75 | * @since 10.5.0 |
| 76 | */ |
| 77 | public function activate(): void { |
| 78 | foreach ( $this->integration_registry->get_integrations() as $integration ) { |
| 79 | $integration->activate(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Plugin deactivation |
| 85 | * |
| 86 | * @since 10.5.0 |
| 87 | */ |
| 88 | public function deactivate(): void { |
| 89 | foreach ( $this->integration_registry->get_integrations() as $integration ) { |
| 90 | $integration->deactivate(); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 |