PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.6
JetFormBuilder — Dynamic Blocks Form Builder v3.4.6
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / classes / arrayable / array-convert-once.php
jetformbuilder / includes / classes / arrayable Last commit date
array-continue-exception.php 2 years ago array-convert-once.php 2 years ago array-tools.php 2 years ago arrayable-once.php 2 years ago arrayable.php 2 years ago collection-item-interface.php 2 years ago collection.php 2 years ago
array-convert-once.php
123 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes\Arrayable;
5
6 use JFB_Components\Repository\Repository_Item_Instance_Trait;
7 use JFB_Components\Repository\Repository_Static_Item_It;
8
9 // If this file is called directly, abort.
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 class Array_Convert_Once {
15
16 /**
17 * @var array[]|Arrayable[]
18 */
19 private $stack = array();
20
21 /**
22 * @param Arrayable $item
23 *
24 * @return mixed
25 */
26 public function add( Arrayable $item ): Arrayable {
27 if ( ! ( $item instanceof Arrayable_Once ) ) {
28 return $item;
29 }
30 $slug = $this->get_slug( $item );
31
32 if ( isset( $this->stack[ $slug ] ) ) {
33 return $this->stack[ $slug ];
34 }
35
36 $this->stack[ $slug ] = $item;
37
38 return $this->stack[ $slug ];
39 }
40
41 public function to_array( Arrayable $item ): array {
42 if ( ! ( $item instanceof Arrayable_Once ) ) {
43 return $item->to_array();
44 }
45 $slug = $this->get_slug( $item );
46
47 if ( isset( $this->stack[ $slug ] ) && is_array( $this->stack[ $slug ] ) ) {
48 return $this->stack[ $slug ];
49 }
50
51 if ( isset( $this->stack[ $slug ] ) ) {
52 $this->stack[ $slug ] = $this->stack[ $slug ]->to_array();
53
54 return $this->stack[ $slug ];
55 }
56
57 $this->add( $item );
58
59 return $this->to_array( $item );
60 }
61
62 /**
63 * @param string $slug
64 *
65 * @return array|Arrayable
66 * @throws Array_Continue_Exception
67 */
68 public function get_item( string $slug ) {
69 $this->exist( $slug );
70
71 return $this->stack[ $slug ];
72 }
73
74 /**
75 * @param string $slug
76 *
77 * @return array|Arrayable
78 * @throws Array_Continue_Exception
79 */
80 public function get_array_item( string $slug ) {
81 $item = $this->get_item( $slug );
82
83 if ( is_array( $item ) ) {
84 return $item;
85 }
86
87 return $this->to_array( $item );
88 }
89
90 /**
91 * @param string $slug
92 *
93 * @return $this
94 * @throws Array_Continue_Exception
95 */
96 public function exist( string $slug ): Array_Convert_Once {
97 if ( isset( $this->stack[ $slug ] ) ) {
98 return $this;
99 }
100
101 throw new Array_Continue_Exception( esc_html( 'Undefined item: ' . $slug ) );
102 }
103
104
105 /**
106 * @param Arrayable $item
107 *
108 * @return mixed
109 */
110 private function get_slug( Arrayable $item ) {
111 if ( $item instanceof Repository_Item_Instance_Trait ) {
112 return $item->rep_item_id();
113 }
114 if ( $item instanceof Repository_Static_Item_It ) {
115 return $item::rep_item_id();
116 }
117
118 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
119 wp_die( 'Invalid element. Item must an instance of ' . Repository_Item_Instance_Trait::class );
120 }
121
122 }
123