Completed
Branch master (4b3da1)
by
unknown
22:00 queued 19:52
created
core/services/editor/BlockRegistrationManager.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -32,223 +32,223 @@
 block discarded – undo
32 32
 class BlockRegistrationManager extends BlockManager
33 33
 {
34 34
 
35
-    /**
36
-     * @var BlockAssetManagerCollection $block_asset_manager_collection
37
-     */
38
-    protected $block_asset_manager_collection;
39
-
40
-    /**
41
-     * @var RouteMatchSpecificationManager $route_manager
42
-     */
43
-    protected $route_manager;
44
-
45
-    /**
46
-     * array for tracking asset managers required by blocks for the current route
47
-     *
48
-     * @var array $block_asset_managers
49
-     */
50
-    protected $block_asset_managers = array();
51
-
52
-
53
-    /**
54
-     * BlockRegistrationManager constructor.
55
-     *
56
-     * @param BlockAssetManagerCollection    $block_asset_manager_collection
57
-     * @param BlockCollection                $blocks
58
-     * @param RouteMatchSpecificationManager $route_manager
59
-     * @param RequestInterface               $request
60
-     */
61
-    public function __construct(
62
-        BlockAssetManagerCollection $block_asset_manager_collection,
63
-        BlockCollection $blocks,
64
-        RouteMatchSpecificationManager $route_manager,
65
-        RequestInterface $request
66
-    ) {
67
-        $this->block_asset_manager_collection = $block_asset_manager_collection;
68
-        $this->route_manager = $route_manager;
69
-        parent::__construct($blocks, $request);
70
-    }
71
-
72
-
73
-    /**
74
-     *  Returns the name of a hookpoint to be used to call initialize()
75
-     *
76
-     * @return string
77
-     */
78
-    public function initHook()
79
-    {
80
-        return 'AHEE__EE_System__initialize';
81
-    }
82
-
83
-
84
-    /**
85
-     * Perform any early setup required for block editors to functions
86
-     *
87
-     * @return void
88
-     * @throws Exception
89
-     */
90
-    public function initialize()
91
-    {
92
-        $this->initializeBlocks();
93
-        add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks'));
94
-        add_action('wp_loaded', array($this, 'unloadAssets'));
95
-        add_filter('block_categories_all', array($this, 'addEspressoBlockCategories'));
96
-    }
97
-
98
-
99
-    /**
100
-     * @param array $categories
101
-     * @since 4.9.71.p
102
-     * @return array
103
-     */
104
-    public function addEspressoBlockCategories(array $categories)
105
-    {
106
-        return array_merge(
107
-            $categories,
108
-            array(
109
-                array(
110
-                    'slug' => 'event-espresso',
111
-                    'title' => esc_html__('Event Espresso', 'event_espresso'),
112
-                ),
113
-            )
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * @return CollectionInterface|BlockInterface[]
120
-     * @throws CollectionLoaderException
121
-     * @throws CollectionDetailsException
122
-     */
123
-    protected function populateBlockCollection()
124
-    {
125
-        $loader = new CollectionLoader(
126
-            new CollectionDetails(
127
-                // collection name
128
-                'editor_blocks',
129
-                // collection interface
130
-                'EventEspresso\core\domain\entities\editor\BlockInterface',
131
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
132
-                apply_filters(
133
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
134
-                    array('EventEspresso\core\domain\entities\editor\blocks')
135
-                ),
136
-                // filepaths to classes to add
137
-                array(),
138
-                // file mask to use if parsing folder for files to add
139
-                '',
140
-                // what to use as identifier for collection entities
141
-                // using CLASS NAME prevents duplicates (works like a singleton)
142
-                CollectionDetails::ID_CLASS_NAME
143
-            ),
144
-            $this->blocks
145
-        );
146
-        return $loader->getCollection();
147
-    }
148
-
149
-
150
-    /**
151
-     * populates the BlockCollection and calls initialize() on all installed blocks
152
-     *
153
-     * @return void
154
-     * @throws Exception
155
-     */
156
-    public function initializeBlocks()
157
-    {
158
-        try {
159
-            $this->populateBlockCollection();
160
-            // cycle thru block loaders and initialize each loader
161
-            foreach ($this->blocks as $block) {
162
-                $block->initialize();
163
-                $this->trackAssetManagersForBlocks($block);
164
-                if (! $this->block_asset_manager_collection->has($block->assetManager())) {
165
-                    $this->block_asset_manager_collection->add($block->assetManager());
166
-                    $block->assetManager()->setAssetHandles();
167
-                }
168
-            }
169
-        } catch (Exception $exception) {
170
-            new ExceptionStackTraceDisplay($exception);
171
-        }
172
-    }
173
-
174
-
175
-    /**
176
-     * track blocks with routes that match the current request
177
-     *
178
-     * @param BlockInterface $block
179
-     * @throws InvalidClassException
180
-     */
181
-    private function trackAssetManagersForBlocks(BlockInterface $block)
182
-    {
183
-        $supported_routes = $block->supportedRoutes();
184
-        foreach ($supported_routes as $supported_route) {
185
-            if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
186
-                $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
187
-            }
188
-        }
189
-    }
190
-
191
-
192
-    /**
193
-     * returns true if the block should be registered for the current request
194
-     * else removes block from block_routes array and returns false
195
-     *
196
-     * @param BlockInterface $block
197
-     * @return boolean
198
-     * @throws InvalidClassException
199
-     */
200
-    public function matchesRoute(BlockInterface $block)
201
-    {
202
-        if (isset($this->block_asset_managers[ $block->blockType() ])) {
203
-            return true;
204
-        }
205
-        unset($this->block_asset_managers[ $block->blockType() ]);
206
-        return false;
207
-    }
208
-
209
-
210
-    /**
211
-     * calls registerBlock() and load assets for all installed blocks
212
-     *
213
-     * @return void
214
-     * @throws Exception
215
-     */
216
-    public function registerBlocks()
217
-    {
218
-        try {
219
-            // cycle thru block loader folders
220
-            foreach ($this->blocks as $block) {
221
-                if (! $this->matchesRoute($block)) {
222
-                    continue;
223
-                }
224
-                // perform any setup required for the block
225
-                $block_type = $block->registerBlock();
226
-                if (! $block_type instanceof WP_Block_Type) {
227
-                    throw new InvalidEntityException($block_type, 'WP_Block_Type');
228
-                }
229
-                do_action(
230
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
231
-                    $block,
232
-                    $block_type
233
-                );
234
-            }
235
-        } catch (Exception $exception) {
236
-            new ExceptionStackTraceDisplay($exception);
237
-        }
238
-    }
239
-
240
-    public function unloadAssets()
241
-    {
242
-        $assets = array_flip($this->block_asset_managers);
243
-        foreach ($this->block_asset_manager_collection as $asset_manager) {
244
-            // if there are no longer any blocks that require these assets,
245
-            if (! isset($assets[ $asset_manager->assetNamespace() ])) {
246
-                // then unset asset enqueueing and bail
247
-                remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
248
-                remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
249
-                remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
250
-                remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
251
-            }
252
-        }
253
-    }
35
+	/**
36
+	 * @var BlockAssetManagerCollection $block_asset_manager_collection
37
+	 */
38
+	protected $block_asset_manager_collection;
39
+
40
+	/**
41
+	 * @var RouteMatchSpecificationManager $route_manager
42
+	 */
43
+	protected $route_manager;
44
+
45
+	/**
46
+	 * array for tracking asset managers required by blocks for the current route
47
+	 *
48
+	 * @var array $block_asset_managers
49
+	 */
50
+	protected $block_asset_managers = array();
51
+
52
+
53
+	/**
54
+	 * BlockRegistrationManager constructor.
55
+	 *
56
+	 * @param BlockAssetManagerCollection    $block_asset_manager_collection
57
+	 * @param BlockCollection                $blocks
58
+	 * @param RouteMatchSpecificationManager $route_manager
59
+	 * @param RequestInterface               $request
60
+	 */
61
+	public function __construct(
62
+		BlockAssetManagerCollection $block_asset_manager_collection,
63
+		BlockCollection $blocks,
64
+		RouteMatchSpecificationManager $route_manager,
65
+		RequestInterface $request
66
+	) {
67
+		$this->block_asset_manager_collection = $block_asset_manager_collection;
68
+		$this->route_manager = $route_manager;
69
+		parent::__construct($blocks, $request);
70
+	}
71
+
72
+
73
+	/**
74
+	 *  Returns the name of a hookpoint to be used to call initialize()
75
+	 *
76
+	 * @return string
77
+	 */
78
+	public function initHook()
79
+	{
80
+		return 'AHEE__EE_System__initialize';
81
+	}
82
+
83
+
84
+	/**
85
+	 * Perform any early setup required for block editors to functions
86
+	 *
87
+	 * @return void
88
+	 * @throws Exception
89
+	 */
90
+	public function initialize()
91
+	{
92
+		$this->initializeBlocks();
93
+		add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks'));
94
+		add_action('wp_loaded', array($this, 'unloadAssets'));
95
+		add_filter('block_categories_all', array($this, 'addEspressoBlockCategories'));
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param array $categories
101
+	 * @since 4.9.71.p
102
+	 * @return array
103
+	 */
104
+	public function addEspressoBlockCategories(array $categories)
105
+	{
106
+		return array_merge(
107
+			$categories,
108
+			array(
109
+				array(
110
+					'slug' => 'event-espresso',
111
+					'title' => esc_html__('Event Espresso', 'event_espresso'),
112
+				),
113
+			)
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return CollectionInterface|BlockInterface[]
120
+	 * @throws CollectionLoaderException
121
+	 * @throws CollectionDetailsException
122
+	 */
123
+	protected function populateBlockCollection()
124
+	{
125
+		$loader = new CollectionLoader(
126
+			new CollectionDetails(
127
+				// collection name
128
+				'editor_blocks',
129
+				// collection interface
130
+				'EventEspresso\core\domain\entities\editor\BlockInterface',
131
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
132
+				apply_filters(
133
+					'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
134
+					array('EventEspresso\core\domain\entities\editor\blocks')
135
+				),
136
+				// filepaths to classes to add
137
+				array(),
138
+				// file mask to use if parsing folder for files to add
139
+				'',
140
+				// what to use as identifier for collection entities
141
+				// using CLASS NAME prevents duplicates (works like a singleton)
142
+				CollectionDetails::ID_CLASS_NAME
143
+			),
144
+			$this->blocks
145
+		);
146
+		return $loader->getCollection();
147
+	}
148
+
149
+
150
+	/**
151
+	 * populates the BlockCollection and calls initialize() on all installed blocks
152
+	 *
153
+	 * @return void
154
+	 * @throws Exception
155
+	 */
156
+	public function initializeBlocks()
157
+	{
158
+		try {
159
+			$this->populateBlockCollection();
160
+			// cycle thru block loaders and initialize each loader
161
+			foreach ($this->blocks as $block) {
162
+				$block->initialize();
163
+				$this->trackAssetManagersForBlocks($block);
164
+				if (! $this->block_asset_manager_collection->has($block->assetManager())) {
165
+					$this->block_asset_manager_collection->add($block->assetManager());
166
+					$block->assetManager()->setAssetHandles();
167
+				}
168
+			}
169
+		} catch (Exception $exception) {
170
+			new ExceptionStackTraceDisplay($exception);
171
+		}
172
+	}
173
+
174
+
175
+	/**
176
+	 * track blocks with routes that match the current request
177
+	 *
178
+	 * @param BlockInterface $block
179
+	 * @throws InvalidClassException
180
+	 */
181
+	private function trackAssetManagersForBlocks(BlockInterface $block)
182
+	{
183
+		$supported_routes = $block->supportedRoutes();
184
+		foreach ($supported_routes as $supported_route) {
185
+			if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
186
+				$this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
187
+			}
188
+		}
189
+	}
190
+
191
+
192
+	/**
193
+	 * returns true if the block should be registered for the current request
194
+	 * else removes block from block_routes array and returns false
195
+	 *
196
+	 * @param BlockInterface $block
197
+	 * @return boolean
198
+	 * @throws InvalidClassException
199
+	 */
200
+	public function matchesRoute(BlockInterface $block)
201
+	{
202
+		if (isset($this->block_asset_managers[ $block->blockType() ])) {
203
+			return true;
204
+		}
205
+		unset($this->block_asset_managers[ $block->blockType() ]);
206
+		return false;
207
+	}
208
+
209
+
210
+	/**
211
+	 * calls registerBlock() and load assets for all installed blocks
212
+	 *
213
+	 * @return void
214
+	 * @throws Exception
215
+	 */
216
+	public function registerBlocks()
217
+	{
218
+		try {
219
+			// cycle thru block loader folders
220
+			foreach ($this->blocks as $block) {
221
+				if (! $this->matchesRoute($block)) {
222
+					continue;
223
+				}
224
+				// perform any setup required for the block
225
+				$block_type = $block->registerBlock();
226
+				if (! $block_type instanceof WP_Block_Type) {
227
+					throw new InvalidEntityException($block_type, 'WP_Block_Type');
228
+				}
229
+				do_action(
230
+					'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
231
+					$block,
232
+					$block_type
233
+				);
234
+			}
235
+		} catch (Exception $exception) {
236
+			new ExceptionStackTraceDisplay($exception);
237
+		}
238
+	}
239
+
240
+	public function unloadAssets()
241
+	{
242
+		$assets = array_flip($this->block_asset_managers);
243
+		foreach ($this->block_asset_manager_collection as $asset_manager) {
244
+			// if there are no longer any blocks that require these assets,
245
+			if (! isset($assets[ $asset_manager->assetNamespace() ])) {
246
+				// then unset asset enqueueing and bail
247
+				remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
248
+				remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
249
+				remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
250
+				remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
251
+			}
252
+		}
253
+	}
254 254
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.30.rc.003');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.30.rc.003');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.