PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.31.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.31.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
← All changes | app/src/BlockLibrary/BlockServiceProvider.php +43 -64 4.7.22.31.2 View file →
@@ -5,9 +5,9 @@
5 5 */
6 6
7 7 namespace SureCart\BlockLibrary;
8 8
9 -use SureCart\BlockLibrary\BlockService;
9 +use SureCartBlocks\Blocks\BlockService;
10 10 use SureCartCore\ServiceProviders\ServiceProviderInterface;
11 11
12 12 /**
13 13 * Block Service Provider Class
@@ -18,15 +18,8 @@
18 18 * @license GPL
19 19 */
20 20 class BlockServiceProvider implements ServiceProviderInterface {
21 21 /**
22 - * Cached components from kses.json
23 - *
24 - * @var array
25 - */
26 - private static $components = [];
27 -
28 - /**
29 22 * {@inheritDoc}
30 23 *
31 24 * @param \Pimple\Container $container Service Container.
32 25 */
@@ -32,29 +25,39 @@
32 25 */
33 26 public function register( $container ) {
34 27 $app = $container[ SURECART_APPLICATION_KEY ];
35 28
36 - $container['block'] = fn () => new BlockService( $app );
29 + $container['blocks'] = function () use ( $app ) {
30 + return new BlockService( $app );
31 + };
37 32
38 - $container['block.support.anchor'] = fn () => new BlockAnchorSupportService();
39 - $container['block.support.currency'] = fn () => new BlockCurrencyConversionSupportService();
40 - $container['blocks.quick_view'] = fn () => new ProductQuickViewService();
41 - $container['blocks.review_form'] = fn () => new ProductReviewFormService();
42 - $container['blocks.patterns'] = fn () => new BlockPatternsService( $app );
43 - $container['blocks.mode_switcher'] = fn () => new FormModeSwitcherService( $app );
44 - $container['blocks.validations'] = fn () => new BlockValidationService(
45 - apply_filters(
46 - 'surecart_block_validators',
47 - array(
48 - new \SureCart\BlockValidator\VariantChoice(),
33 + $container['blocks.patterns'] = function () use ( $app ) {
34 + return new BlockPatternsService( $app );
35 + };
36 +
37 + $container['blocks.validations'] = function () {
38 + return new BlockValidationService(
39 + apply_filters(
40 + 'surecart_block_validators',
41 + [
42 + new \SureCart\BlockValidator\VariantChoice(),
43 + ]
49 44 )
50 - )
51 - );
45 + );
46 + };
52 47
53 - $app->alias( 'block', 'block' );
48 + $container['blocks.mode_switcher'] = function () use ( $app ) {
49 + return new FormModeSwitcherService( $app );
50 + };
54 51
55 - // Register blocks.
56 - include plugin_dir_path( SURECART_PLUGIN_FILE ) . 'packages/blocks-next/index.php';
52 + $app->alias( 'blocks', 'blocks' );
53 +
54 + $app->alias(
55 + 'block',
56 + function () use ( $app ) {
57 + return call_user_func_array( [ $app->blocks(), 'render' ], func_get_args() );
58 + }
59 + );
57 60 }
58 61
59 62 /**
60 63 * {@inheritDoc}
@@ -68,17 +71,15 @@
68 71 public function bootstrap( $container ) {
69 72 $container['blocks.patterns']->bootstrap();
70 73 $container['blocks.validations']->bootstrap();
71 74 $container['blocks.mode_switcher']->bootstrap();
72 - $container['block.support.anchor']->bootstrap();
73 - $container['block.support.currency']->bootstrap();
74 75
75 76 // allow design tokens in css.
76 77 add_filter(
77 78 'safe_style_css',
78 - function ( $styles ) {
79 + function( $styles ) {
79 80 return array_merge(
80 - array(
81 + [
81 82 '--spacing',
82 83 '--font-weight',
83 84 '--line-height',
84 85 '--font-size',
@@ -90,19 +91,19 @@
90 91 '--sc-color-primary-text',
91 92 '--sc-color-primary-500',
92 93 '--sc-focus-ring-color-primary',
93 94 '--sc-input-border-color-focus',
94 - ),
95 + ],
95 96 $styles
96 97 );
97 98 }
98 99 );
99 100 // allow our web components in wp_kses contexts.
100 - add_filter( 'wp_kses_allowed_html', array( $this, 'ksesComponents' ) );
101 + add_filter( 'wp_kses_allowed_html', [ $this, 'ksesComponents' ] );
101 102 // register our blocks.
102 - add_action( 'init', array( $this, 'registerBlocks' ) );
103 + add_action( 'init', [ $this, 'registerBlocks' ] );
103 104 // register our category.
104 - add_action( 'block_categories_all', array( $this, 'registerBlockCategories' ) );
105 + add_action( 'block_categories_all', [ $this, 'registerBlockCategories' ] );
105 106 }
106 107
107 108 /**
108 109 * Register our custom block category.
@@ -110,37 +111,17 @@
110 111 * @param array $categories Array of categories.
111 112 * @return array
112 113 */
113 114 public function registerBlockCategories( $categories ) {
114 - return array(
115 - ...array(
116 - array(
115 + return [
116 + ...[
117 + [
117 118 'slug' => 'surecart',
118 - 'title' => esc_html__( 'Checkout', 'surecart' ),
119 - ),
120 - array(
121 - 'slug' => 'surecart-customer-dashboard',
122 - 'title' => esc_html__( 'Customer Dashboard', 'surecart' ),
123 - ),
124 - array(
125 - 'slug' => 'surecart-cart',
126 - 'title' => esc_html__( 'Cart', 'surecart' ),
127 - ),
128 - array(
129 - 'slug' => 'surecart-product-list',
130 - 'title' => esc_html__( 'Shop', 'surecart' ),
131 - ),
132 - array(
133 - 'slug' => 'surecart-product-page',
134 - 'title' => esc_html__( 'Product', 'surecart' ),
135 - ),
136 - array(
137 - 'slug' => 'surecart-upsell-page',
138 - 'title' => esc_html__( 'Upsells', 'surecart' ),
139 - ),
140 - ),
119 + 'title' => esc_html__( 'SureCart', 'surecart' ),
120 + ],
121 + ],
141 122 ...$categories,
142 - );
123 + ];
143 124 }
144 125
145 126 /**
146 127 * Add iFrame to allowed wp_kses_post tags
@@ -149,11 +130,9 @@
149 130 *
150 131 * @return array
151 132 */
152 133 public function ksesComponents( $tags ) {
153 - if ( empty( self::$components ) ) {
154 - self::$components = json_decode( file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'app/src/Support/kses.json' ), true );
155 - }
134 + $components = json_decode( file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'app/src/Support/kses.json' ), true );
156 135
157 136 // add slot to defaults.
158 137 $tags['span']['slot'] = true;
159 138 $tags['div']['slot'] = true;
@@ -158,9 +137,9 @@
158 137 $tags['span']['slot'] = true;
159 138 $tags['div']['slot'] = true;
160 139 $tags['sc-spinner']['data-*'] = true;
161 140
162 - return array_merge( self::$components, $tags );
141 + return array_merge( $components, $tags );
163 142 }
164 143
165 144 /**
166 145 * Register blocks from config