InstalledExtensions.php
2 years ago
MarketingCampaign.php
1 year ago
MarketingCampaignType.php
3 years ago
MarketingChannelInterface.php
3 years ago
MarketingChannels.php
3 years ago
Price.php
3 years ago
MarketingChannels.php
67 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles the registration of marketing channels and acts as their repository. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\Marketing; |
| 7 | |
| 8 | use Exception; |
| 9 | |
| 10 | /** |
| 11 | * MarketingChannels repository class |
| 12 | * |
| 13 | * @since x.x.x |
| 14 | */ |
| 15 | class MarketingChannels { |
| 16 | /** |
| 17 | * The registered marketing channels. |
| 18 | * |
| 19 | * @var MarketingChannelInterface[] |
| 20 | */ |
| 21 | private $registered_channels = []; |
| 22 | |
| 23 | /** |
| 24 | * Registers a marketing channel. |
| 25 | * |
| 26 | * @param MarketingChannelInterface $channel The marketing channel to register. |
| 27 | * |
| 28 | * @return void |
| 29 | * |
| 30 | * @throws Exception If the given marketing channel is already registered. |
| 31 | */ |
| 32 | public function register( MarketingChannelInterface $channel ): void { |
| 33 | if ( isset( $this->registered_channels[ $channel->get_slug() ] ) ) { |
| 34 | throw new Exception( __( 'Marketing channel cannot be registered because there is already a channel registered with the same slug!', 'woocommerce' ) ); |
| 35 | } |
| 36 | |
| 37 | $this->registered_channels[ $channel->get_slug() ] = $channel; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Unregisters all marketing channels. |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | public function unregister_all(): void { |
| 46 | unset( $this->registered_channels ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns an array of all registered marketing channels. |
| 51 | * |
| 52 | * @return MarketingChannelInterface[] |
| 53 | */ |
| 54 | public function get_registered_channels(): array { |
| 55 | /** |
| 56 | * Filter the list of registered marketing channels. |
| 57 | * |
| 58 | * @param MarketingChannelInterface[] $channels Array of registered marketing channels. |
| 59 | * |
| 60 | * @since x.x.x |
| 61 | */ |
| 62 | $channels = apply_filters( 'woocommerce_marketing_channels', $this->registered_channels ); |
| 63 | |
| 64 | return array_values( $channels ); |
| 65 | } |
| 66 | } |
| 67 |