PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.19
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.19
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Hook_Manifest.php

Hook_Manifest.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.19, at includes/Hook_Manifest.php

59 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ordered WCPOS bootstrap hook installation.
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS;
9
10 /** Installs rows declared by Init::hook_rows(); registrars keep their own internals. */
11 final class Hook_Manifest {
12 /**
13 * Install named hooks, or invoke null-hook registrar callbacks immediately.
14 *
15 * @param array $rows Ordered hook rows.
16 */
17 public static function install( array $rows ): void {
18 self::validate( $rows );
19 foreach ( $rows as $row ) {
20 if ( null === $row['hook'] ) {
21 ( $row['callback'] )();
22 } else {
23 // WordPress actions and filters share the same registration primitive.
24 add_filter( $row['hook'], $row['callback'], $row['priority'], $row['args'] );
25 }
26 }
27 }
28
29 /**
30 * Require the declared metadata, without executing any callbacks.
31 *
32 * @param array $rows Ordered hook rows.
33 * @throws \InvalidArgumentException When required metadata is absent or invalid.
34 */
35 public static function validate( array $rows ): void {
36 foreach ( $rows as $index => $row ) {
37 foreach ( array( 'hook', 'callback', 'priority', 'args', 'reason', 'phase' ) as $field ) {
38 if ( ! array_key_exists( $field, $row ) ) {
39 throw new \InvalidArgumentException( esc_html( 'Hook manifest row ' . $index . ' is missing ' . $field . '.' ) );
40 }
41 }
42 if ( ! \in_array( $row['phase'], array( 'pre-latch', 'sync-latched', 'post-latch' ), true ) ) {
43 throw new \InvalidArgumentException( esc_html( 'Hook manifest row ' . $index . ' requires a valid phase.' ) );
44 }
45 foreach ( array( 'priority', 'args' ) as $field ) {
46 if ( ! \is_int( $row[ $field ] ) ) {
47 throw new \InvalidArgumentException( esc_html( 'Hook manifest row ' . $index . ' requires an integer ' . $field . '.' ) );
48 }
49 }
50 if ( ! \is_callable( $row['callback'] ) ) {
51 throw new \InvalidArgumentException( esc_html( 'Hook manifest row ' . $index . ' requires a callable callback.' ) );
52 }
53 if ( ! \is_string( $row['reason'] ) || '' === trim( $row['reason'] ) ) {
54 throw new \InvalidArgumentException( esc_html( 'Hook manifest row ' . $index . ' requires a non-empty reason.' ) );
55 }
56 }
57 }
58 }
59