| 1 |
<?php |
| 2 |
/** |
| 3 |
* Block: Service provider |
| 4 |
* |
| 5 |
* @package SimplePay |
| 6 |
* @subpackage Core |
| 7 |
* @copyright Copyright (c) 2022, Sandhills Development, LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 4.4.2 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace SimplePay\Core\Block; |
| 13 |
|
| 14 |
use SimplePay\Core\AbstractPluginServiceProvider; |
| 15 |
|
| 16 |
/** |
| 17 |
* BlockServiceProvider class. |
| 18 |
* |
| 19 |
* @since 4.4.2 |
| 20 |
*/ |
| 21 |
class BlockServiceProvider extends AbstractPluginServiceProvider { |
| 22 |
|
| 23 |
/** |
| 24 |
* {@inheritdoc} |
| 25 |
*/ |
| 26 |
public function get_services() { |
| 27 |
return array(); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
public function get_subscribers() { |
| 34 |
return array( |
| 35 |
'block-subscriber', |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* {@inheritdoc} |
| 41 |
*/ |
| 42 |
public function register() { |
| 43 |
$container = $this->getContainer(); |
| 44 |
|
| 45 |
$container->share( |
| 46 |
'block-subscriber', |
| 47 |
BlockSubscriber::class |
| 48 |
) |
| 49 |
->withArgument( $this->get_blocks() ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Returns a list of block types to register. |
| 54 |
* |
| 55 |
* @since 4.4.2 |
| 56 |
* |
| 57 |
* @return array<\SimplePay\Core\Block\BlockInterface> |
| 58 |
*/ |
| 59 |
private function get_blocks() { |
| 60 |
$container = $this->getContainer(); |
| 61 |
|
| 62 |
// Payment form. |
| 63 |
$container->share( 'block-payment-form', PaymentFormBlock::class ); |
| 64 |
|
| 65 |
// Manage subscription. |
| 66 |
$container->share( 'block-manage-subscription', ManageSubscriptionsBlock::class ); |
| 67 |
|
| 68 |
// Button. |
| 69 |
$container->share( 'block-button', ButtonBlock::class ) |
| 70 |
->withArgument( $container->get( 'event-manager' ) ); |
| 71 |
|
| 72 |
/** @var array<\SimplePay\Core\Block\BlockInterface> $blocks */ |
| 73 |
$blocks = array( |
| 74 |
$container->get( 'block-payment-form' ), |
| 75 |
$container->get( 'block-button' ), |
| 76 |
$container->get( 'block-manage-subscription' ), |
| 77 |
); |
| 78 |
|
| 79 |
return $blocks; |
| 80 |
} |
| 81 |
} |
| 82 |
|