Completed
Branch dependabot/composer/wp-graphql... (64393b)
by
unknown
04:29
created
domain/services/graphql/connection_resolvers/StateConnectionResolver.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -14,152 +14,152 @@
 block discarded – undo
14 14
  */
15 15
 class StateConnectionResolver extends AbstractConnectionResolver
16 16
 {
17
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
18
-    public function get_loader_name(): string
19
-    {
20
-        return 'espresso_state';
21
-    }
22
-
23
-    /**
24
-     * @return EEM_State
25
-     * @throws EE_Error
26
-     * @throws InvalidArgumentException
27
-     * @throws InvalidDataTypeException
28
-     * @throws InvalidInterfaceException
29
-     * @throws ReflectionException
30
-     */
31
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
32
-    public function get_query(): EEM_State
33
-    {
34
-        return EEM_State::instance();
35
-    }
36
-
37
-
38
-    /**
39
-     * Return an array of item IDs from the query
40
-     *
41
-     * @return array
42
-     */
43
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
44
-    public function get_ids(): array
45
-    {
46
-        $results = $this->query->get_col($this->query_args);
47
-
48
-        return ! empty($results) ? $results : [];
49
-    }
50
-
51
-
52
-    /**
53
-     * Here, we map the args from the input, then we make sure that we're only querying
54
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
55
-     * handle batch resolution of the posts.
56
-     *
57
-     * @return array
58
-     * @throws InvalidArgumentException
59
-     * @throws InvalidDataTypeException
60
-     * @throws InvalidInterfaceException
61
-     */
62
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63
-    public function get_query_args(): array
64
-    {
65
-        $where_params = [];
66
-        $query_args   = [];
67
-
68
-        $query_args['limit'] = $this->getLimit();
69
-
70
-        // Avoid multiple entries by join.
71
-        $query_args['group_by'] = 'STA_ID';
72
-
73
-        $query_args['default_where_conditions'] = 'minimum';
74
-
75
-        /**
76
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
77
-         */
78
-        $input_fields = [];
79
-        if (! empty($this->args['where'])) {
80
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
81
-
82
-            // Since we do not have any falsy values in query params
83
-            // Lets get rid of empty values
84
-            $input_fields = array_filter($input_fields);
85
-
86
-            // Use the proper operator.
87
-            if (! empty($input_fields['STA_ID']) && is_array($input_fields['STA_ID'])) {
88
-                $input_fields['STA_ID'] = ['IN', $input_fields['STA_ID']];
89
-            }
90
-            if (! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
91
-                $input_fields['CNT_ISO'] = ['IN', $input_fields['CNT_ISO']];
92
-            }
93
-        }
94
-
95
-        /**
96
-         * Merge the input_fields with the default query_args
97
-         */
98
-        if (! empty($input_fields)) {
99
-            $where_params = array_merge($where_params, $input_fields);
100
-        }
101
-
102
-        // limit to active countries by default.
103
-        if (!isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
104
-            $where_params['STA_active'] = true;
105
-        }
106
-
107
-        [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'STA_ID');
108
-
109
-        if (empty($query_args['order_by'])) {
110
-            // set order_by to 'name' by default
111
-            $query_args['order_by'] = [
112
-                'STA_name' => 'ASC',
113
-            ];
114
-        }
115
-
116
-        $search = $this->getSearchKeywords($this->args['where']);
117
-
118
-        if (! empty($search)) {
119
-            // use OR operator to search in any of the fields
120
-            $where_params['OR'] = array(
121
-                'STA_name' => array('LIKE', '%' . $search . '%'),
122
-            );
123
-        }
124
-
125
-        $where_params = apply_filters(
126
-            'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__state_where_params',
127
-            $where_params,
128
-            $this->source,
129
-            $this->args
130
-        );
131
-
132
-        $query_args[] = $where_params;
133
-
134
-        /**
135
-         * Return the $query_args
136
-         */
137
-        return apply_filters(
138
-            'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__state_query_args',
139
-            $query_args,
140
-            $this->source,
141
-            $this->args
142
-        );
143
-    }
144
-
145
-
146
-    /**
147
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
148
-     * friendly keys.
149
-     *
150
-     * @param array $where_args
151
-     * @return array
152
-     */
153
-    public function sanitizeInputFields(array $where_args): array
154
-    {
155
-        $arg_mapping = [
156
-            'in'           => 'STA_ID',
157
-            'countryIsoIn' => 'CNT_ISO',
158
-        ];
159
-        return $this->sanitizeWhereArgsForInputFields(
160
-            $where_args,
161
-            $arg_mapping,
162
-            ['in']
163
-        );
164
-    }
17
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
18
+	public function get_loader_name(): string
19
+	{
20
+		return 'espresso_state';
21
+	}
22
+
23
+	/**
24
+	 * @return EEM_State
25
+	 * @throws EE_Error
26
+	 * @throws InvalidArgumentException
27
+	 * @throws InvalidDataTypeException
28
+	 * @throws InvalidInterfaceException
29
+	 * @throws ReflectionException
30
+	 */
31
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
32
+	public function get_query(): EEM_State
33
+	{
34
+		return EEM_State::instance();
35
+	}
36
+
37
+
38
+	/**
39
+	 * Return an array of item IDs from the query
40
+	 *
41
+	 * @return array
42
+	 */
43
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
44
+	public function get_ids(): array
45
+	{
46
+		$results = $this->query->get_col($this->query_args);
47
+
48
+		return ! empty($results) ? $results : [];
49
+	}
50
+
51
+
52
+	/**
53
+	 * Here, we map the args from the input, then we make sure that we're only querying
54
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
55
+	 * handle batch resolution of the posts.
56
+	 *
57
+	 * @return array
58
+	 * @throws InvalidArgumentException
59
+	 * @throws InvalidDataTypeException
60
+	 * @throws InvalidInterfaceException
61
+	 */
62
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63
+	public function get_query_args(): array
64
+	{
65
+		$where_params = [];
66
+		$query_args   = [];
67
+
68
+		$query_args['limit'] = $this->getLimit();
69
+
70
+		// Avoid multiple entries by join.
71
+		$query_args['group_by'] = 'STA_ID';
72
+
73
+		$query_args['default_where_conditions'] = 'minimum';
74
+
75
+		/**
76
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
77
+		 */
78
+		$input_fields = [];
79
+		if (! empty($this->args['where'])) {
80
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
81
+
82
+			// Since we do not have any falsy values in query params
83
+			// Lets get rid of empty values
84
+			$input_fields = array_filter($input_fields);
85
+
86
+			// Use the proper operator.
87
+			if (! empty($input_fields['STA_ID']) && is_array($input_fields['STA_ID'])) {
88
+				$input_fields['STA_ID'] = ['IN', $input_fields['STA_ID']];
89
+			}
90
+			if (! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
91
+				$input_fields['CNT_ISO'] = ['IN', $input_fields['CNT_ISO']];
92
+			}
93
+		}
94
+
95
+		/**
96
+		 * Merge the input_fields with the default query_args
97
+		 */
98
+		if (! empty($input_fields)) {
99
+			$where_params = array_merge($where_params, $input_fields);
100
+		}
101
+
102
+		// limit to active countries by default.
103
+		if (!isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
104
+			$where_params['STA_active'] = true;
105
+		}
106
+
107
+		[$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'STA_ID');
108
+
109
+		if (empty($query_args['order_by'])) {
110
+			// set order_by to 'name' by default
111
+			$query_args['order_by'] = [
112
+				'STA_name' => 'ASC',
113
+			];
114
+		}
115
+
116
+		$search = $this->getSearchKeywords($this->args['where']);
117
+
118
+		if (! empty($search)) {
119
+			// use OR operator to search in any of the fields
120
+			$where_params['OR'] = array(
121
+				'STA_name' => array('LIKE', '%' . $search . '%'),
122
+			);
123
+		}
124
+
125
+		$where_params = apply_filters(
126
+			'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__state_where_params',
127
+			$where_params,
128
+			$this->source,
129
+			$this->args
130
+		);
131
+
132
+		$query_args[] = $where_params;
133
+
134
+		/**
135
+		 * Return the $query_args
136
+		 */
137
+		return apply_filters(
138
+			'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__state_query_args',
139
+			$query_args,
140
+			$this->source,
141
+			$this->args
142
+		);
143
+	}
144
+
145
+
146
+	/**
147
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
148
+	 * friendly keys.
149
+	 *
150
+	 * @param array $where_args
151
+	 * @return array
152
+	 */
153
+	public function sanitizeInputFields(array $where_args): array
154
+	{
155
+		$arg_mapping = [
156
+			'in'           => 'STA_ID',
157
+			'countryIsoIn' => 'CNT_ISO',
158
+		];
159
+		return $this->sanitizeWhereArgsForInputFields(
160
+			$where_args,
161
+			$arg_mapping,
162
+			['in']
163
+		);
164
+	}
165 165
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
          * Collect the input_fields and sanitize them to prepare them for sending to the Query
77 77
          */
78 78
         $input_fields = [];
79
-        if (! empty($this->args['where'])) {
79
+        if ( ! empty($this->args['where'])) {
80 80
             $input_fields = $this->sanitizeInputFields($this->args['where']);
81 81
 
82 82
             // Since we do not have any falsy values in query params
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
             $input_fields = array_filter($input_fields);
85 85
 
86 86
             // Use the proper operator.
87
-            if (! empty($input_fields['STA_ID']) && is_array($input_fields['STA_ID'])) {
87
+            if ( ! empty($input_fields['STA_ID']) && is_array($input_fields['STA_ID'])) {
88 88
                 $input_fields['STA_ID'] = ['IN', $input_fields['STA_ID']];
89 89
             }
90
-            if (! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
90
+            if ( ! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
91 91
                 $input_fields['CNT_ISO'] = ['IN', $input_fields['CNT_ISO']];
92 92
             }
93 93
         }
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
         /**
96 96
          * Merge the input_fields with the default query_args
97 97
          */
98
-        if (! empty($input_fields)) {
98
+        if ( ! empty($input_fields)) {
99 99
             $where_params = array_merge($where_params, $input_fields);
100 100
         }
101 101
 
102 102
         // limit to active countries by default.
103
-        if (!isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
103
+        if ( ! isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
104 104
             $where_params['STA_active'] = true;
105 105
         }
106 106
 
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
 
116 116
         $search = $this->getSearchKeywords($this->args['where']);
117 117
 
118
-        if (! empty($search)) {
118
+        if ( ! empty($search)) {
119 119
             // use OR operator to search in any of the fields
120 120
             $where_params['OR'] = array(
121
-                'STA_name' => array('LIKE', '%' . $search . '%'),
121
+                'STA_name' => array('LIKE', '%'.$search.'%'),
122 122
             );
123 123
         }
124 124
 
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/CountryConnectionResolver.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
          * Collect the input_fields and sanitize them to prepare them for sending to the Query
95 95
          */
96 96
         $input_fields = [];
97
-        if (! empty($this->args['where'])) {
97
+        if ( ! empty($this->args['where'])) {
98 98
             $input_fields = $this->sanitizeInputFields($this->args['where']);
99 99
 
100 100
             // Since we do not have any falsy values in query params
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
             $input_fields = array_filter($input_fields);
103 103
 
104 104
             // Use the proper operator.
105
-            if (! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
105
+            if ( ! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
106 106
                 $input_fields['CNT_ISO'] = ['IN', $input_fields['CNT_ISO']];
107 107
             }
108
-            if (! empty($input_fields['CNT_ISO3']) && is_array($input_fields['CNT_ISO3'])) {
108
+            if ( ! empty($input_fields['CNT_ISO3']) && is_array($input_fields['CNT_ISO3'])) {
109 109
                 $input_fields['CNT_ISO3'] = ['IN', $input_fields['CNT_ISO3']];
110 110
             }
111 111
         }
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
         /**
114 114
          * Merge the input_fields with the default query_args
115 115
          */
116
-        if (! empty($input_fields)) {
116
+        if ( ! empty($input_fields)) {
117 117
             $where_params = array_merge($where_params, $input_fields);
118 118
         }
119 119
 
120 120
         // limit to active countries by default.
121
-        if (!isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
121
+        if ( ! isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
122 122
             $where_params['CNT_active'] = true;
123 123
         }
124 124
 
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
 
134 134
         $search = $this->getSearchKeywords($this->args['where']);
135 135
 
136
-        if (! empty($search)) {
136
+        if ( ! empty($search)) {
137 137
             // use OR operator to search in any of the fields
138 138
             $where_params['OR'] = array(
139
-                'CNT_name' => array('LIKE', '%' . $search . '%'),
140
-                'CNT_ISO'  => array('LIKE', '%' . $search . '%'),
139
+                'CNT_name' => array('LIKE', '%'.$search.'%'),
140
+                'CNT_ISO'  => array('LIKE', '%'.$search.'%'),
141 141
             );
142 142
         }
143 143
 
Please login to merge, or discard this patch.
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -16,170 +16,170 @@
 block discarded – undo
16 16
  */
17 17
 class CountryConnectionResolver extends AbstractConnectionResolver
18 18
 {
19
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
20
-    public function get_loader_name(): string
21
-    {
22
-        return 'espresso_country';
23
-    }
24
-
25
-    /**
26
-     * @return EEM_Country
27
-     * @throws EE_Error
28
-     * @throws InvalidArgumentException
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidInterfaceException
31
-     * @throws ReflectionException
32
-     */
33
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
34
-    public function get_query(): EEM_Country
35
-    {
36
-        return EEM_Country::instance();
37
-    }
38
-
39
-
40
-    /**
41
-     * Return an array of item IDs from the query
42
-     *
43
-     * @return array
44
-     */
45
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
-    public function get_ids(): array
47
-    {
48
-        $results = $this->query->get_col($this->query_args);
49
-
50
-        return ! empty($results) ? $results : [];
51
-    }
52
-
53
-    /**
54
-     * Get_query_amount
55
-     *
56
-     * Returns the max between what was requested and what is defined as the $max_query_amount to
57
-     * ensure that queries don't exceed unwanted limits when querying data.
58
-     *
59
-     * @return int
60
-     * @throws Exception
61
-     */
62
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63
-    public function get_query_amount()
64
-    {
65
-        // Override the default limit (100) for countries
66
-        return 500;
67
-    }
68
-
69
-
70
-    /**
71
-     * Here, we map the args from the input, then we make sure that we're only querying
72
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
73
-     * handle batch resolution of the posts.
74
-     *
75
-     * @return array
76
-     * @throws InvalidArgumentException
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidInterfaceException
79
-     */
80
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
81
-    public function get_query_args(): array
82
-    {
83
-        $where_params = [];
84
-        $query_args   = [];
85
-
86
-        $query_args['limit'] = $this->getLimit();
87
-
88
-        // Avoid multiple entries by join.
89
-        $query_args['group_by'] = 'CNT_ISO';
90
-
91
-        $query_args['default_where_conditions'] = 'minimum';
92
-
93
-        /**
94
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
95
-         */
96
-        $input_fields = [];
97
-        if (! empty($this->args['where'])) {
98
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
99
-
100
-            // Since we do not have any falsy values in query params
101
-            // Lets get rid of empty values
102
-            $input_fields = array_filter($input_fields);
103
-
104
-            // Use the proper operator.
105
-            if (! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
106
-                $input_fields['CNT_ISO'] = ['IN', $input_fields['CNT_ISO']];
107
-            }
108
-            if (! empty($input_fields['CNT_ISO3']) && is_array($input_fields['CNT_ISO3'])) {
109
-                $input_fields['CNT_ISO3'] = ['IN', $input_fields['CNT_ISO3']];
110
-            }
111
-        }
112
-
113
-        /**
114
-         * Merge the input_fields with the default query_args
115
-         */
116
-        if (! empty($input_fields)) {
117
-            $where_params = array_merge($where_params, $input_fields);
118
-        }
119
-
120
-        // limit to active countries by default.
121
-        if (!isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
122
-            $where_params['CNT_active'] = true;
123
-        }
124
-
125
-        [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'CNT_ISO');
126
-
127
-        if (empty($query_args['order_by'])) {
128
-            // set order_by to 'name' by default
129
-            $query_args['order_by'] = [
130
-                'CNT_name' => 'ASC',
131
-            ];
132
-        }
133
-
134
-        $search = $this->getSearchKeywords($this->args['where']);
135
-
136
-        if (! empty($search)) {
137
-            // use OR operator to search in any of the fields
138
-            $where_params['OR'] = array(
139
-                'CNT_name' => array('LIKE', '%' . $search . '%'),
140
-                'CNT_ISO'  => array('LIKE', '%' . $search . '%'),
141
-            );
142
-        }
143
-
144
-        $where_params = apply_filters(
145
-            'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__country_where_params',
146
-            $where_params,
147
-            $this->source,
148
-            $this->args
149
-        );
150
-
151
-        $query_args[] = $where_params;
152
-
153
-        /**
154
-         * Return the $query_args
155
-         */
156
-        return apply_filters(
157
-            'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__country_query_args',
158
-            $query_args,
159
-            $this->source,
160
-            $this->args
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
167
-     * friendly keys.
168
-     *
169
-     * @param array $where_args
170
-     * @return array
171
-     */
172
-    public function sanitizeInputFields(array $where_args): array
173
-    {
174
-        $arg_mapping = [
175
-            'isoIn'  => 'CNT_ISO',
176
-            'in'     => 'CNT_ISO',
177
-            'iso3In' => 'CNT_ISO3',
178
-        ];
179
-        return $this->sanitizeWhereArgsForInputFields(
180
-            $where_args,
181
-            $arg_mapping,
182
-            ['in']
183
-        );
184
-    }
19
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
20
+	public function get_loader_name(): string
21
+	{
22
+		return 'espresso_country';
23
+	}
24
+
25
+	/**
26
+	 * @return EEM_Country
27
+	 * @throws EE_Error
28
+	 * @throws InvalidArgumentException
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidInterfaceException
31
+	 * @throws ReflectionException
32
+	 */
33
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
34
+	public function get_query(): EEM_Country
35
+	{
36
+		return EEM_Country::instance();
37
+	}
38
+
39
+
40
+	/**
41
+	 * Return an array of item IDs from the query
42
+	 *
43
+	 * @return array
44
+	 */
45
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
+	public function get_ids(): array
47
+	{
48
+		$results = $this->query->get_col($this->query_args);
49
+
50
+		return ! empty($results) ? $results : [];
51
+	}
52
+
53
+	/**
54
+	 * Get_query_amount
55
+	 *
56
+	 * Returns the max between what was requested and what is defined as the $max_query_amount to
57
+	 * ensure that queries don't exceed unwanted limits when querying data.
58
+	 *
59
+	 * @return int
60
+	 * @throws Exception
61
+	 */
62
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63
+	public function get_query_amount()
64
+	{
65
+		// Override the default limit (100) for countries
66
+		return 500;
67
+	}
68
+
69
+
70
+	/**
71
+	 * Here, we map the args from the input, then we make sure that we're only querying
72
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
73
+	 * handle batch resolution of the posts.
74
+	 *
75
+	 * @return array
76
+	 * @throws InvalidArgumentException
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidInterfaceException
79
+	 */
80
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
81
+	public function get_query_args(): array
82
+	{
83
+		$where_params = [];
84
+		$query_args   = [];
85
+
86
+		$query_args['limit'] = $this->getLimit();
87
+
88
+		// Avoid multiple entries by join.
89
+		$query_args['group_by'] = 'CNT_ISO';
90
+
91
+		$query_args['default_where_conditions'] = 'minimum';
92
+
93
+		/**
94
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
95
+		 */
96
+		$input_fields = [];
97
+		if (! empty($this->args['where'])) {
98
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
99
+
100
+			// Since we do not have any falsy values in query params
101
+			// Lets get rid of empty values
102
+			$input_fields = array_filter($input_fields);
103
+
104
+			// Use the proper operator.
105
+			if (! empty($input_fields['CNT_ISO']) && is_array($input_fields['CNT_ISO'])) {
106
+				$input_fields['CNT_ISO'] = ['IN', $input_fields['CNT_ISO']];
107
+			}
108
+			if (! empty($input_fields['CNT_ISO3']) && is_array($input_fields['CNT_ISO3'])) {
109
+				$input_fields['CNT_ISO3'] = ['IN', $input_fields['CNT_ISO3']];
110
+			}
111
+		}
112
+
113
+		/**
114
+		 * Merge the input_fields with the default query_args
115
+		 */
116
+		if (! empty($input_fields)) {
117
+			$where_params = array_merge($where_params, $input_fields);
118
+		}
119
+
120
+		// limit to active countries by default.
121
+		if (!isset($this->args['where']['activeOnly']) || $this->args['where']['activeOnly']) {
122
+			$where_params['CNT_active'] = true;
123
+		}
124
+
125
+		[$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'CNT_ISO');
126
+
127
+		if (empty($query_args['order_by'])) {
128
+			// set order_by to 'name' by default
129
+			$query_args['order_by'] = [
130
+				'CNT_name' => 'ASC',
131
+			];
132
+		}
133
+
134
+		$search = $this->getSearchKeywords($this->args['where']);
135
+
136
+		if (! empty($search)) {
137
+			// use OR operator to search in any of the fields
138
+			$where_params['OR'] = array(
139
+				'CNT_name' => array('LIKE', '%' . $search . '%'),
140
+				'CNT_ISO'  => array('LIKE', '%' . $search . '%'),
141
+			);
142
+		}
143
+
144
+		$where_params = apply_filters(
145
+			'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__country_where_params',
146
+			$where_params,
147
+			$this->source,
148
+			$this->args
149
+		);
150
+
151
+		$query_args[] = $where_params;
152
+
153
+		/**
154
+		 * Return the $query_args
155
+		 */
156
+		return apply_filters(
157
+			'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__country_query_args',
158
+			$query_args,
159
+			$this->source,
160
+			$this->args
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
167
+	 * friendly keys.
168
+	 *
169
+	 * @param array $where_args
170
+	 * @return array
171
+	 */
172
+	public function sanitizeInputFields(array $where_args): array
173
+	{
174
+		$arg_mapping = [
175
+			'isoIn'  => 'CNT_ISO',
176
+			'in'     => 'CNT_ISO',
177
+			'iso3In' => 'CNT_ISO3',
178
+		];
179
+		return $this->sanitizeWhereArgsForInputFields(
180
+			$where_args,
181
+			$arg_mapping,
182
+			['in']
183
+		);
184
+	}
185 185
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/types/Datetime.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function __construct(EEM_Datetime $datetime_model)
47 47
     {
48
-        $this->setName($this->namespace . 'Datetime');
48
+        $this->setName($this->namespace.'Datetime');
49 49
         $this->setDescription(__('An event date', 'event_espresso'));
50 50
         $this->setIsCustomPostType(false);
51 51
         parent::__construct($datetime_model);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             ),
99 99
             new GraphQLOutputField(
100 100
                 'event',
101
-                $this->namespace . 'Event',
101
+                $this->namespace.'Event',
102 102
                 null,
103 103
                 esc_html__('Event of the datetime.', 'event_espresso')
104 104
             ),
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             ),
207 207
             new GraphQLOutputField(
208 208
                 'status',
209
-                $this->namespace . 'DatetimeStatusEnum',
209
+                $this->namespace.'DatetimeStatusEnum',
210 210
                 'get_active_status',
211 211
                 esc_html__('Datetime status', 'event_espresso')
212 212
             ),
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                 null,
227 227
                 esc_html__('Datetime venue ID', 'event_espresso'),
228 228
                 null,
229
-                function (EE_Datetime $source) {
229
+                function(EE_Datetime $source) {
230 230
                     $venue_ID = $source->venue_ID();
231 231
                     return $venue_ID
232 232
                         // Since venue is a CPT, $type will be 'post'
@@ -320,14 +320,14 @@  discard block
 block discarded – undo
320 320
     public function registerMutations(array $inputFields)
321 321
     {
322 322
         register_graphql_input_type(
323
-            'Update' .  $this->name() . 'BaseInput',
323
+            'Update'.$this->name().'BaseInput',
324 324
             [
325 325
                 'fields' => $inputFields,
326 326
             ]
327 327
         );
328 328
         // Register mutation to update an entity.
329 329
         register_graphql_mutation(
330
-            'update' . $this->name(),
330
+            'update'.$this->name(),
331 331
             [
332 332
                 'inputFields'         => $inputFields,
333 333
                 'outputFields'        => [
@@ -339,10 +339,10 @@  discard block
 block discarded – undo
339 339
                 'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this),
340 340
             ]
341 341
         );
342
-        $base_input = 'Update' .  $this->name() . 'BaseInput';
342
+        $base_input = 'Update'.$this->name().'BaseInput';
343 343
         // Register mutation to update an entity.
344 344
         register_graphql_mutation(
345
-            'bulkUpdate' . $this->name(),
345
+            'bulkUpdate'.$this->name(),
346 346
             array_merge(
347 347
                 Datetime::bulkUpdateBaseConfig($base_input),
348 348
                 [
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
         // Register mutation to update an entity.
355 355
         register_graphql_mutation(
356
-            'bulkDelete' . $this->namespace . 'Entities',
356
+            'bulkDelete'.$this->namespace.'Entities',
357 357
             [
358 358
                 'inputFields'         => [
359 359
                     'entityIds'  => [
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
                     ],
365 365
                     'entityType' => [
366 366
                         'type'        => [
367
-                            'non_null' => $this->namespace . 'ModelNameEnum',
367
+                            'non_null' => $this->namespace.'ModelNameEnum',
368 368
                         ],
369 369
                         'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
370 370
                     ],
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
         );
387 387
         // Register mutation to delete an entity.
388 388
         register_graphql_mutation(
389
-            'delete' . $this->name(),
389
+            'delete'.$this->name(),
390 390
             [
391 391
                 'inputFields'         => [
392 392
                     'id'                => $inputFields['id'],
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
                     lcfirst($this->name()) => [
400 400
                         'type'        => $this->name(),
401 401
                         'description' => esc_html__('The object before it was deleted', 'event_espresso'),
402
-                        'resolve'     => static function ($payload) {
402
+                        'resolve'     => static function($payload) {
403 403
                             $deleted = (object) $payload['deleted'];
404 404
 
405 405
                             return ! empty($deleted) ? $deleted : null;
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
         unset($inputFields['id']);
415 415
         // Register mutation to update an entity.
416 416
         register_graphql_mutation(
417
-            'create' . $this->name(),
417
+            'create'.$this->name(),
418 418
             [
419 419
                 'inputFields'         => $inputFields,
420 420
                 'outputFields'        => [
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 
430 430
         // Register mutation to update an entity.
431 431
         register_graphql_mutation(
432
-            'reorder' . $this->namespace . 'Entities',
432
+            'reorder'.$this->namespace.'Entities',
433 433
             [
434 434
                 'inputFields'         => [
435 435
                     'entityIds'  => [
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
                     ],
441 441
                     'entityType' => [
442 442
                         'type'        => [
443
-                            'non_null' => $this->namespace . 'ModelNameEnum',
443
+                            'non_null' => $this->namespace.'ModelNameEnum',
444 444
                         ],
445 445
                         'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
446 446
                     ],
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
                 'outputFields'        => [
449 449
                     'ok' => [
450 450
                         'type'    => 'Boolean',
451
-                        'resolve' => function ($payload) {
451
+                        'resolve' => function($payload) {
452 452
                             return (bool) $payload['ok'];
453 453
                         },
454 454
                     ],
Please login to merge, or discard this patch.
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -37,423 +37,423 @@
 block discarded – undo
37 37
  */
38 38
 class Datetime extends TypeBase
39 39
 {
40
-    /**
41
-     * EventDate constructor.
42
-     *
43
-     * @param EEM_Datetime $datetime_model
44
-     */
45
-    public function __construct(EEM_Datetime $datetime_model)
46
-    {
47
-        $this->setName($this->namespace . 'Datetime');
48
-        $this->setDescription(__('An event date', 'event_espresso'));
49
-        $this->setIsCustomPostType(false);
50
-        parent::__construct($datetime_model);
51
-    }
40
+	/**
41
+	 * EventDate constructor.
42
+	 *
43
+	 * @param EEM_Datetime $datetime_model
44
+	 */
45
+	public function __construct(EEM_Datetime $datetime_model)
46
+	{
47
+		$this->setName($this->namespace . 'Datetime');
48
+		$this->setDescription(__('An event date', 'event_espresso'));
49
+		$this->setIsCustomPostType(false);
50
+		parent::__construct($datetime_model);
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * @return GraphQLFieldInterface[]
56
-     */
57
-    public function getFields(): array
58
-    {
59
-        $fields = [
60
-            new GraphQLField(
61
-                'id',
62
-                ['non_null' => 'ID'],
63
-                null,
64
-                esc_html__('The globally unique ID for the object.', 'event_espresso')
65
-            ),
66
-            new GraphQLOutputField(
67
-                'dbId',
68
-                ['non_null' => 'Int'],
69
-                'ID',
70
-                esc_html__('The datetime ID.', 'event_espresso')
71
-            ),
72
-            new GraphQLOutputField(
73
-                'cacheId',
74
-                ['non_null' => 'String'],
75
-                null,
76
-                esc_html__('The cache ID of the object.', 'event_espresso')
77
-            ),
78
-            new GraphQLField(
79
-                'capacity',
80
-                'Int',
81
-                'reg_limit',
82
-                esc_html__('Registration Limit for this time', 'event_espresso'),
83
-                [$this, 'parseInfiniteValue']
84
-            ),
85
-            new GraphQLField(
86
-                'description',
87
-                'String',
88
-                'description',
89
-                esc_html__('Description for Datetime', 'event_espresso')
90
-            ),
91
-            new GraphQLField(
92
-                'endDate',
93
-                'String',
94
-                'end_date_and_time',
95
-                esc_html__('End date and time of the Event', 'event_espresso'),
96
-                [$this, 'formatDatetime']
97
-            ),
98
-            new GraphQLOutputField(
99
-                'event',
100
-                $this->namespace . 'Event',
101
-                null,
102
-                esc_html__('Event of the datetime.', 'event_espresso')
103
-            ),
104
-            new GraphQLInputField(
105
-                'event',
106
-                'ID',
107
-                null,
108
-                esc_html__('Globally unique event ID of the datetime.', 'event_espresso')
109
-            ),
110
-            new GraphQLInputField(
111
-                'eventId',
112
-                'Int',
113
-                null,
114
-                esc_html__('Event ID of the datetime.', 'event_espresso')
115
-            ),
116
-            new GraphQLOutputField(
117
-                'isActive',
118
-                'Boolean',
119
-                'is_active',
120
-                esc_html__('Flag indicating datetime is active', 'event_espresso')
121
-            ),
122
-            new GraphQLOutputField(
123
-                'isExpired',
124
-                'Boolean',
125
-                'is_expired',
126
-                esc_html__('Flag indicating datetime is expired or not', 'event_espresso')
127
-            ),
128
-            new GraphQLField(
129
-                'isPrimary',
130
-                'Boolean',
131
-                'is_primary',
132
-                esc_html__('Flag indicating datetime is primary one for event', 'event_espresso')
133
-            ),
134
-            new GraphQLOutputField(
135
-                'isSoldOut',
136
-                'Boolean',
137
-                'sold_out',
138
-                esc_html__(
139
-                    'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit',
140
-                    'event_espresso'
141
-                )
142
-            ),
143
-            new GraphQLField(
144
-                'isTrashed',
145
-                'Boolean',
146
-                null,
147
-                esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'),
148
-                null,
149
-                [$this, 'getIsTrashed']
150
-            ),
151
-            new GraphQLOutputField(
152
-                'isUpcoming',
153
-                'Boolean',
154
-                'is_upcoming',
155
-                esc_html__('Whether the date is upcoming', 'event_espresso')
156
-            ),
157
-            new GraphQLOutputField(
158
-                'length',
159
-                'Int',
160
-                'length',
161
-                esc_html__('The length of the event (start to end time) in seconds', 'event_espresso')
162
-            ),
163
-            new GraphQLField(
164
-                'name',
165
-                'String',
166
-                'name',
167
-                esc_html__('Datetime Name', 'event_espresso')
168
-            ),
169
-            new GraphQLField(
170
-                'order',
171
-                'Int',
172
-                'order',
173
-                esc_html__('The order in which the Datetime is displayed', 'event_espresso')
174
-            ),
175
-            new GraphQLOutputField(
176
-                'parent',
177
-                $this->name(),
178
-                null,
179
-                esc_html__('The parent datetime of the current datetime', 'event_espresso')
180
-            ),
181
-            new GraphQLInputField(
182
-                'parent',
183
-                'ID',
184
-                null,
185
-                esc_html__('The parent datetime ID', 'event_espresso')
186
-            ),
187
-            new GraphQLField(
188
-                'reserved',
189
-                'Int',
190
-                'reserved',
191
-                esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso')
192
-            ),
193
-            new GraphQLField(
194
-                'startDate',
195
-                'String',
196
-                'start_date_and_time',
197
-                esc_html__('Start date and time of the Event', 'event_espresso'),
198
-                [$this, 'formatDatetime']
199
-            ),
200
-            new GraphQLField(
201
-                'sold',
202
-                'Int',
203
-                'sold',
204
-                esc_html__('How many sales for this Datetime that have occurred', 'event_espresso')
205
-            ),
206
-            new GraphQLOutputField(
207
-                'status',
208
-                $this->namespace . 'DatetimeStatusEnum',
209
-                'get_active_status',
210
-                esc_html__('Datetime status', 'event_espresso')
211
-            ),
212
-            new GraphQLInputField(
213
-                'tickets',
214
-                ['list_of' => 'ID'],
215
-                null,
216
-                sprintf(
217
-                    '%1$s %2$s',
218
-                    esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'),
219
-                    esc_html__('Ignored if empty.', 'event_espresso')
220
-                )
221
-            ),
222
-            new GraphQLField(
223
-                'venue',
224
-                'String',
225
-                null,
226
-                esc_html__('Datetime venue ID', 'event_espresso'),
227
-                null,
228
-                function (EE_Datetime $source) {
229
-                    $venue_ID = $source->venue_ID();
230
-                    return $venue_ID
231
-                        // Since venue is a CPT, $type will be 'post'
232
-                        ? Relay::toGlobalId('post', $venue_ID)
233
-                        : null;
234
-                }
235
-            ),
236
-        ];
54
+	/**
55
+	 * @return GraphQLFieldInterface[]
56
+	 */
57
+	public function getFields(): array
58
+	{
59
+		$fields = [
60
+			new GraphQLField(
61
+				'id',
62
+				['non_null' => 'ID'],
63
+				null,
64
+				esc_html__('The globally unique ID for the object.', 'event_espresso')
65
+			),
66
+			new GraphQLOutputField(
67
+				'dbId',
68
+				['non_null' => 'Int'],
69
+				'ID',
70
+				esc_html__('The datetime ID.', 'event_espresso')
71
+			),
72
+			new GraphQLOutputField(
73
+				'cacheId',
74
+				['non_null' => 'String'],
75
+				null,
76
+				esc_html__('The cache ID of the object.', 'event_espresso')
77
+			),
78
+			new GraphQLField(
79
+				'capacity',
80
+				'Int',
81
+				'reg_limit',
82
+				esc_html__('Registration Limit for this time', 'event_espresso'),
83
+				[$this, 'parseInfiniteValue']
84
+			),
85
+			new GraphQLField(
86
+				'description',
87
+				'String',
88
+				'description',
89
+				esc_html__('Description for Datetime', 'event_espresso')
90
+			),
91
+			new GraphQLField(
92
+				'endDate',
93
+				'String',
94
+				'end_date_and_time',
95
+				esc_html__('End date and time of the Event', 'event_espresso'),
96
+				[$this, 'formatDatetime']
97
+			),
98
+			new GraphQLOutputField(
99
+				'event',
100
+				$this->namespace . 'Event',
101
+				null,
102
+				esc_html__('Event of the datetime.', 'event_espresso')
103
+			),
104
+			new GraphQLInputField(
105
+				'event',
106
+				'ID',
107
+				null,
108
+				esc_html__('Globally unique event ID of the datetime.', 'event_espresso')
109
+			),
110
+			new GraphQLInputField(
111
+				'eventId',
112
+				'Int',
113
+				null,
114
+				esc_html__('Event ID of the datetime.', 'event_espresso')
115
+			),
116
+			new GraphQLOutputField(
117
+				'isActive',
118
+				'Boolean',
119
+				'is_active',
120
+				esc_html__('Flag indicating datetime is active', 'event_espresso')
121
+			),
122
+			new GraphQLOutputField(
123
+				'isExpired',
124
+				'Boolean',
125
+				'is_expired',
126
+				esc_html__('Flag indicating datetime is expired or not', 'event_espresso')
127
+			),
128
+			new GraphQLField(
129
+				'isPrimary',
130
+				'Boolean',
131
+				'is_primary',
132
+				esc_html__('Flag indicating datetime is primary one for event', 'event_espresso')
133
+			),
134
+			new GraphQLOutputField(
135
+				'isSoldOut',
136
+				'Boolean',
137
+				'sold_out',
138
+				esc_html__(
139
+					'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit',
140
+					'event_espresso'
141
+				)
142
+			),
143
+			new GraphQLField(
144
+				'isTrashed',
145
+				'Boolean',
146
+				null,
147
+				esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'),
148
+				null,
149
+				[$this, 'getIsTrashed']
150
+			),
151
+			new GraphQLOutputField(
152
+				'isUpcoming',
153
+				'Boolean',
154
+				'is_upcoming',
155
+				esc_html__('Whether the date is upcoming', 'event_espresso')
156
+			),
157
+			new GraphQLOutputField(
158
+				'length',
159
+				'Int',
160
+				'length',
161
+				esc_html__('The length of the event (start to end time) in seconds', 'event_espresso')
162
+			),
163
+			new GraphQLField(
164
+				'name',
165
+				'String',
166
+				'name',
167
+				esc_html__('Datetime Name', 'event_espresso')
168
+			),
169
+			new GraphQLField(
170
+				'order',
171
+				'Int',
172
+				'order',
173
+				esc_html__('The order in which the Datetime is displayed', 'event_espresso')
174
+			),
175
+			new GraphQLOutputField(
176
+				'parent',
177
+				$this->name(),
178
+				null,
179
+				esc_html__('The parent datetime of the current datetime', 'event_espresso')
180
+			),
181
+			new GraphQLInputField(
182
+				'parent',
183
+				'ID',
184
+				null,
185
+				esc_html__('The parent datetime ID', 'event_espresso')
186
+			),
187
+			new GraphQLField(
188
+				'reserved',
189
+				'Int',
190
+				'reserved',
191
+				esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso')
192
+			),
193
+			new GraphQLField(
194
+				'startDate',
195
+				'String',
196
+				'start_date_and_time',
197
+				esc_html__('Start date and time of the Event', 'event_espresso'),
198
+				[$this, 'formatDatetime']
199
+			),
200
+			new GraphQLField(
201
+				'sold',
202
+				'Int',
203
+				'sold',
204
+				esc_html__('How many sales for this Datetime that have occurred', 'event_espresso')
205
+			),
206
+			new GraphQLOutputField(
207
+				'status',
208
+				$this->namespace . 'DatetimeStatusEnum',
209
+				'get_active_status',
210
+				esc_html__('Datetime status', 'event_espresso')
211
+			),
212
+			new GraphQLInputField(
213
+				'tickets',
214
+				['list_of' => 'ID'],
215
+				null,
216
+				sprintf(
217
+					'%1$s %2$s',
218
+					esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'),
219
+					esc_html__('Ignored if empty.', 'event_espresso')
220
+				)
221
+			),
222
+			new GraphQLField(
223
+				'venue',
224
+				'String',
225
+				null,
226
+				esc_html__('Datetime venue ID', 'event_espresso'),
227
+				null,
228
+				function (EE_Datetime $source) {
229
+					$venue_ID = $source->venue_ID();
230
+					return $venue_ID
231
+						// Since venue is a CPT, $type will be 'post'
232
+						? Relay::toGlobalId('post', $venue_ID)
233
+						: null;
234
+				}
235
+			),
236
+		];
237 237
 
238
-        return apply_filters(
239
-            'FHEE__EventEspresso_core_domain_services_graphql_types__datetime_fields',
240
-            $fields,
241
-            $this->name,
242
-            $this->model
243
-        );
244
-    }
238
+		return apply_filters(
239
+			'FHEE__EventEspresso_core_domain_services_graphql_types__datetime_fields',
240
+			$fields,
241
+			$this->name,
242
+			$this->model
243
+		);
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     * @param EE_Datetime   $source  The source that's passed down the GraphQL queries
249
-     * @param array       $args    The inputArgs on the field
250
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
251
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
252
-     * @return bool
253
-     * @throws Exception
254
-     * @throws InvalidArgumentException
255
-     * @throws InvalidDataTypeException
256
-     * @throws InvalidInterfaceException
257
-     * @throws ReflectionException
258
-     * @throws UserError
259
-     * @throws UnexpectedEntityException
260
-     */
261
-    public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info): bool
262
-    {
263
-        return (bool) $source->get('DTT_deleted');
264
-    }
247
+	/**
248
+	 * @param EE_Datetime   $source  The source that's passed down the GraphQL queries
249
+	 * @param array       $args    The inputArgs on the field
250
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
251
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
252
+	 * @return bool
253
+	 * @throws Exception
254
+	 * @throws InvalidArgumentException
255
+	 * @throws InvalidDataTypeException
256
+	 * @throws InvalidInterfaceException
257
+	 * @throws ReflectionException
258
+	 * @throws UserError
259
+	 * @throws UnexpectedEntityException
260
+	 */
261
+	public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info): bool
262
+	{
263
+		return (bool) $source->get('DTT_deleted');
264
+	}
265 265
 
266
-    /**
267
-     * Return the base mutation config for bulk update.
268
-     *
269
-     * @param string $base_input
270
-     * @return array
271
-     */
272
-    public static function bulkUpdateBaseConfig(string $base_input): array
273
-    {
274
-        return [
275
-            'inputFields'     => [
276
-                /**
277
-                 * represents the input that is unique for each entity
278
-                 * e.g. dates may be unique for datetimes and tickets
279
-                 */
280
-                'uniqueInputs' => [
281
-                    'type'        => [
282
-                        'non_null' => ['list_of' => $base_input],
283
-                    ],
284
-                    'description' => esc_html__(
285
-                        'List of unique inputs for each entity in bulk update',
286
-                        'event_espresso'
287
-                    ),
288
-                ],
289
-                /**
290
-                 * represents the common input for all entities
291
-                 * e.g. capacity or quantity may be same for all dates/tickets
292
-                 */
293
-                'sharedInput' => [
294
-                    'type'        => $base_input,
295
-                    'description' => esc_html__(
296
-                        'Shared input for all entities in bulk update',
297
-                        'event_espresso'
298
-                    ),
299
-                ],
300
-            ],
301
-            'outputFields'        => [
302
-                'updated' => [
303
-                    'type' => ['list_of' => 'ID'],
304
-                ],
305
-                'failed' => [
306
-                    'type' => ['list_of' => 'ID'],
307
-                ],
308
-            ],
309
-        ];
310
-    }
266
+	/**
267
+	 * Return the base mutation config for bulk update.
268
+	 *
269
+	 * @param string $base_input
270
+	 * @return array
271
+	 */
272
+	public static function bulkUpdateBaseConfig(string $base_input): array
273
+	{
274
+		return [
275
+			'inputFields'     => [
276
+				/**
277
+				 * represents the input that is unique for each entity
278
+				 * e.g. dates may be unique for datetimes and tickets
279
+				 */
280
+				'uniqueInputs' => [
281
+					'type'        => [
282
+						'non_null' => ['list_of' => $base_input],
283
+					],
284
+					'description' => esc_html__(
285
+						'List of unique inputs for each entity in bulk update',
286
+						'event_espresso'
287
+					),
288
+				],
289
+				/**
290
+				 * represents the common input for all entities
291
+				 * e.g. capacity or quantity may be same for all dates/tickets
292
+				 */
293
+				'sharedInput' => [
294
+					'type'        => $base_input,
295
+					'description' => esc_html__(
296
+						'Shared input for all entities in bulk update',
297
+						'event_espresso'
298
+					),
299
+				],
300
+			],
301
+			'outputFields'        => [
302
+				'updated' => [
303
+					'type' => ['list_of' => 'ID'],
304
+				],
305
+				'failed' => [
306
+					'type' => ['list_of' => 'ID'],
307
+				],
308
+			],
309
+		];
310
+	}
311 311
 
312 312
 
313
-    /**
314
-     * @param array $inputFields The mutation input fields.
315
-     * @throws InvalidArgumentException
316
-     * @throws ReflectionException
317
-     * @throws Exception
318
-     */
319
-    public function registerMutations(array $inputFields)
320
-    {
321
-        register_graphql_input_type(
322
-            'Update' .  $this->name() . 'BaseInput',
323
-            [
324
-                'fields' => $inputFields,
325
-            ]
326
-        );
327
-        // Register mutation to update an entity.
328
-        register_graphql_mutation(
329
-            'update' . $this->name(),
330
-            [
331
-                'inputFields'         => $inputFields,
332
-                'outputFields'        => [
333
-                    lcfirst($this->name()) => [
334
-                        'type'    => $this->name(),
335
-                        'resolve' => [$this, 'resolveFromPayload'],
336
-                    ],
337
-                ],
338
-                'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this),
339
-            ]
340
-        );
341
-        $base_input = 'Update' .  $this->name() . 'BaseInput';
342
-        // Register mutation to update an entity.
343
-        register_graphql_mutation(
344
-            'bulkUpdate' . $this->name(),
345
-            array_merge(
346
-                Datetime::bulkUpdateBaseConfig($base_input),
347
-                [
348
-                    'mutateAndGetPayload' => DatetimeBulkUpdate::mutateAndGetPayload($this->model, $this),
349
-                ]
350
-            )
351
-        );
313
+	/**
314
+	 * @param array $inputFields The mutation input fields.
315
+	 * @throws InvalidArgumentException
316
+	 * @throws ReflectionException
317
+	 * @throws Exception
318
+	 */
319
+	public function registerMutations(array $inputFields)
320
+	{
321
+		register_graphql_input_type(
322
+			'Update' .  $this->name() . 'BaseInput',
323
+			[
324
+				'fields' => $inputFields,
325
+			]
326
+		);
327
+		// Register mutation to update an entity.
328
+		register_graphql_mutation(
329
+			'update' . $this->name(),
330
+			[
331
+				'inputFields'         => $inputFields,
332
+				'outputFields'        => [
333
+					lcfirst($this->name()) => [
334
+						'type'    => $this->name(),
335
+						'resolve' => [$this, 'resolveFromPayload'],
336
+					],
337
+				],
338
+				'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this),
339
+			]
340
+		);
341
+		$base_input = 'Update' .  $this->name() . 'BaseInput';
342
+		// Register mutation to update an entity.
343
+		register_graphql_mutation(
344
+			'bulkUpdate' . $this->name(),
345
+			array_merge(
346
+				Datetime::bulkUpdateBaseConfig($base_input),
347
+				[
348
+					'mutateAndGetPayload' => DatetimeBulkUpdate::mutateAndGetPayload($this->model, $this),
349
+				]
350
+			)
351
+		);
352 352
 
353
-        // Register mutation to update an entity.
354
-        register_graphql_mutation(
355
-            'bulkDelete' . $this->namespace . 'Entities',
356
-            [
357
-                'inputFields'         => [
358
-                    'entityIds'  => [
359
-                        'type'        => [
360
-                            'non_null' => ['list_of' => 'ID'],
361
-                        ],
362
-                        'description' => esc_html__('The list of GUIDs of the entities to be deleted.', 'event_espresso'),
363
-                    ],
364
-                    'entityType' => [
365
-                        'type'        => [
366
-                            'non_null' => $this->namespace . 'ModelNameEnum',
367
-                        ],
368
-                        'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
369
-                    ],
370
-                    'deletePermanently' => [
371
-                        'type'        => 'Boolean',
372
-                        'description' => esc_html__('Whether to delete the entities permanently.', 'event_espresso'),
373
-                    ],
374
-                ],
375
-                'outputFields'        => [
376
-                    'deleted' => [
377
-                        'type' => ['list_of' => 'ID'],
378
-                    ],
379
-                    'failed' => [
380
-                        'type' => ['list_of' => 'ID'],
381
-                    ],
382
-                ],
383
-                'mutateAndGetPayload' => BulkEntityDelete::mutateAndGetPayload(),
384
-            ]
385
-        );
386
-        // Register mutation to delete an entity.
387
-        register_graphql_mutation(
388
-            'delete' . $this->name(),
389
-            [
390
-                'inputFields'         => [
391
-                    'id'                => $inputFields['id'],
392
-                    'deletePermanently' => [
393
-                        'type'        => 'Boolean',
394
-                        'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'),
395
-                    ],
396
-                ],
397
-                'outputFields'        => [
398
-                    lcfirst($this->name()) => [
399
-                        'type'        => $this->name(),
400
-                        'description' => esc_html__('The object before it was deleted', 'event_espresso'),
401
-                        'resolve'     => static function ($payload) {
402
-                            $deleted = (object) $payload['deleted'];
353
+		// Register mutation to update an entity.
354
+		register_graphql_mutation(
355
+			'bulkDelete' . $this->namespace . 'Entities',
356
+			[
357
+				'inputFields'         => [
358
+					'entityIds'  => [
359
+						'type'        => [
360
+							'non_null' => ['list_of' => 'ID'],
361
+						],
362
+						'description' => esc_html__('The list of GUIDs of the entities to be deleted.', 'event_espresso'),
363
+					],
364
+					'entityType' => [
365
+						'type'        => [
366
+							'non_null' => $this->namespace . 'ModelNameEnum',
367
+						],
368
+						'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
369
+					],
370
+					'deletePermanently' => [
371
+						'type'        => 'Boolean',
372
+						'description' => esc_html__('Whether to delete the entities permanently.', 'event_espresso'),
373
+					],
374
+				],
375
+				'outputFields'        => [
376
+					'deleted' => [
377
+						'type' => ['list_of' => 'ID'],
378
+					],
379
+					'failed' => [
380
+						'type' => ['list_of' => 'ID'],
381
+					],
382
+				],
383
+				'mutateAndGetPayload' => BulkEntityDelete::mutateAndGetPayload(),
384
+			]
385
+		);
386
+		// Register mutation to delete an entity.
387
+		register_graphql_mutation(
388
+			'delete' . $this->name(),
389
+			[
390
+				'inputFields'         => [
391
+					'id'                => $inputFields['id'],
392
+					'deletePermanently' => [
393
+						'type'        => 'Boolean',
394
+						'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'),
395
+					],
396
+				],
397
+				'outputFields'        => [
398
+					lcfirst($this->name()) => [
399
+						'type'        => $this->name(),
400
+						'description' => esc_html__('The object before it was deleted', 'event_espresso'),
401
+						'resolve'     => static function ($payload) {
402
+							$deleted = (object) $payload['deleted'];
403 403
 
404
-                            return ! empty($deleted) ? $deleted : null;
405
-                        },
406
-                    ],
407
-                ],
408
-                'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this),
409
-            ]
410
-        );
404
+							return ! empty($deleted) ? $deleted : null;
405
+						},
406
+					],
407
+				],
408
+				'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this),
409
+			]
410
+		);
411 411
 
412
-        // remove primary key from input.
413
-        unset($inputFields['id']);
414
-        // Register mutation to update an entity.
415
-        register_graphql_mutation(
416
-            'create' . $this->name(),
417
-            [
418
-                'inputFields'         => $inputFields,
419
-                'outputFields'        => [
420
-                    lcfirst($this->name()) => [
421
-                        'type'    => $this->name(),
422
-                        'resolve' => [$this, 'resolveFromPayload'],
423
-                    ],
424
-                ],
425
-                'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this),
426
-            ]
427
-        );
412
+		// remove primary key from input.
413
+		unset($inputFields['id']);
414
+		// Register mutation to update an entity.
415
+		register_graphql_mutation(
416
+			'create' . $this->name(),
417
+			[
418
+				'inputFields'         => $inputFields,
419
+				'outputFields'        => [
420
+					lcfirst($this->name()) => [
421
+						'type'    => $this->name(),
422
+						'resolve' => [$this, 'resolveFromPayload'],
423
+					],
424
+				],
425
+				'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this),
426
+			]
427
+		);
428 428
 
429
-        // Register mutation to update an entity.
430
-        register_graphql_mutation(
431
-            'reorder' . $this->namespace . 'Entities',
432
-            [
433
-                'inputFields'         => [
434
-                    'entityIds'  => [
435
-                        'type'        => [
436
-                            'non_null' => ['list_of' => 'ID'],
437
-                        ],
438
-                        'description' => esc_html__('The reordered list of entity GUIDs.', 'event_espresso'),
439
-                    ],
440
-                    'entityType' => [
441
-                        'type'        => [
442
-                            'non_null' => $this->namespace . 'ModelNameEnum',
443
-                        ],
444
-                        'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
445
-                    ],
446
-                ],
447
-                'outputFields'        => [
448
-                    'ok' => [
449
-                        'type'    => 'Boolean',
450
-                        'resolve' => function ($payload) {
451
-                            return (bool) $payload['ok'];
452
-                        },
453
-                    ],
454
-                ],
455
-                'mutateAndGetPayload' => EntityReorder::mutateAndGetPayload(),
456
-            ]
457
-        );
458
-    }
429
+		// Register mutation to update an entity.
430
+		register_graphql_mutation(
431
+			'reorder' . $this->namespace . 'Entities',
432
+			[
433
+				'inputFields'         => [
434
+					'entityIds'  => [
435
+						'type'        => [
436
+							'non_null' => ['list_of' => 'ID'],
437
+						],
438
+						'description' => esc_html__('The reordered list of entity GUIDs.', 'event_espresso'),
439
+					],
440
+					'entityType' => [
441
+						'type'        => [
442
+							'non_null' => $this->namespace . 'ModelNameEnum',
443
+						],
444
+						'description' => esc_html__('The entity type for the IDs', 'event_espresso'),
445
+					],
446
+				],
447
+				'outputFields'        => [
448
+					'ok' => [
449
+						'type'    => 'Boolean',
450
+						'resolve' => function ($payload) {
451
+							return (bool) $payload['ok'];
452
+						},
453
+					],
454
+				],
455
+				'mutateAndGetPayload' => EntityReorder::mutateAndGetPayload(),
456
+			]
457
+		);
458
+	}
459 459
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/data/mutations/DatetimeMutation.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
             $args['DTT_description'] = wp_kses_post($input['description']);
41 41
         }
42 42
 
43
-        if (! empty($input['endDate'])) {
43
+        if ( ! empty($input['endDate'])) {
44 44
             $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate']));
45 45
         }
46 46
 
47
-        if (! empty($input['eventId'])) {
47
+        if ( ! empty($input['eventId'])) {
48 48
             $args['EVT_ID'] = absint($input['eventId']);
49
-        } elseif (! empty($input['event'])) {
49
+        } elseif ( ! empty($input['event'])) {
50 50
             $parts = Relay::fromGlobalId(sanitize_text_field($input['event']));
51 51
             $args['EVT_ID'] = ! empty($parts['id']) ? $parts['id'] : null;
52 52
         }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             $args['DTT_order'] = (int) $input['order'];
68 68
         }
69 69
 
70
-        if (! empty($input['parent'])) {
70
+        if ( ! empty($input['parent'])) {
71 71
             $parts = Relay::fromGlobalId(sanitize_text_field($input['parent']));
72 72
             $args['DTT_parent'] = ! empty($parts['id']) ? $parts['id'] : null;
73 73
         }
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
             $args['DTT_sold'] = (int) $input['sold'];
81 81
         }
82 82
 
83
-        if (! empty($input['startDate'])) {
83
+        if ( ! empty($input['startDate'])) {
84 84
             $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate']));
85 85
         }
86 86
 
87
-        if (! empty($input['tickets'])) {
87
+        if ( ! empty($input['tickets'])) {
88 88
             $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']);
89 89
         }
90 90
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 
122 122
         foreach ($tickets as $ID) {
123 123
             $parts = Relay::fromGlobalId($ID);
124
-            if (! empty($parts['id']) && absint($parts['id'])) {
124
+            if ( ! empty($parts['id']) && absint($parts['id'])) {
125 125
                 $entity->_add_relation_to(
126 126
                     $parts['id'],
127 127
                     $relationName
Please login to merge, or discard this patch.
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -20,134 +20,134 @@
 block discarded – undo
20 20
  */
21 21
 class DatetimeMutation
22 22
 {
23
-    /**
24
-     * Maps the GraphQL input to a format that the model functions can use
25
-     *
26
-     * @param array $input Data coming from the GraphQL mutation query input
27
-     * @return array
28
-     * @throws Exception
29
-     */
30
-    public static function prepareFields(array $input): array
31
-    {
32
-        $args = [];
33
-
34
-        if (array_key_exists('capacity', $input)) {
35
-            $args['DTT_reg_limit'] = (int) $input['capacity'];
36
-        }
37
-
38
-        if (isset($input['description'])) {
39
-            $args['DTT_description'] = wp_kses_post($input['description']);
40
-        }
41
-
42
-        if (! empty($input['endDate'])) {
43
-            $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate']));
44
-        }
45
-
46
-        if (! empty($input['eventId'])) {
47
-            $args['EVT_ID'] = absint($input['eventId']);
48
-        } elseif (! empty($input['event'])) {
49
-            $parts = Relay::fromGlobalId(sanitize_text_field($input['event']));
50
-            $args['EVT_ID'] = ! empty($parts['id']) ? $parts['id'] : null;
51
-        }
52
-
53
-        if (array_key_exists('isPrimary', $input)) {
54
-            $args['DTT_is_primary'] = (bool) $input['isPrimary'];
55
-        }
56
-
57
-        if (array_key_exists('isTrashed', $input)) {
58
-            $args['DTT_deleted'] = (bool) $input['isTrashed'];
59
-        }
60
-
61
-        if (isset($input['name'])) {
62
-            $args['DTT_name'] = sanitize_text_field($input['name']);
63
-        }
64
-
65
-        if (array_key_exists('order', $input)) {
66
-            $args['DTT_order'] = (int) $input['order'];
67
-        }
68
-
69
-        if (! empty($input['parent'])) {
70
-            $parts = Relay::fromGlobalId(sanitize_text_field($input['parent']));
71
-            $args['DTT_parent'] = ! empty($parts['id']) ? $parts['id'] : null;
72
-        }
73
-
74
-        if (array_key_exists('reserved', $input)) {
75
-            $args['DTT_reserved'] = (int) $input['reserved'];
76
-        }
77
-
78
-        if (array_key_exists('sold', $input)) {
79
-            $args['DTT_sold'] = (int) $input['sold'];
80
-        }
81
-
82
-        if (! empty($input['startDate'])) {
83
-            $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate']));
84
-        }
85
-
86
-        if (! empty($input['tickets'])) {
87
-            $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']);
88
-        }
89
-
90
-        if (array_key_exists('venue', $input)) {
91
-            $venue_id = sanitize_text_field($input['venue']);
92
-            $parts = Relay::fromGlobalId($venue_id);
93
-            $venue_id = ! empty($parts['id']) ? $parts['id'] : $venue_id;
94
-            $args['venue'] = absint($venue_id);
95
-        }
96
-
97
-        return apply_filters(
98
-            'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__datetime_args',
99
-            $args,
100
-            $input
101
-        );
102
-    }
103
-
104
-
105
-    /**
106
-     * Sets the related tickets for the given datetime.
107
-     *
108
-     * @param EE_Datetime $entity  The datetime instance.
109
-     * @param array       $tickets Array of ticket IDs to relate.
110
-     * @throws EE_Error
111
-     * @throws InvalidDataTypeException
112
-     * @throws InvalidInterfaceException
113
-     * @throws InvalidArgumentException
114
-     * @throws ReflectionException
115
-     */
116
-    public static function setRelatedTickets(EE_Datetime $entity, array $tickets)
117
-    {
118
-        $relationName = 'Ticket';
119
-        // Remove all the existing related tickets
120
-        $entity->_remove_relations($relationName);
121
-
122
-        foreach ($tickets as $ID) {
123
-            $parts = Relay::fromGlobalId($ID);
124
-            if (! empty($parts['id']) && absint($parts['id'])) {
125
-                $entity->_add_relation_to(
126
-                    $parts['id'],
127
-                    $relationName
128
-                );
129
-            }
130
-        }
131
-    }
132
-
133
-
134
-    /**
135
-     * Sets the venue for the datetime.
136
-     *
137
-     * @param EE_Datetime $entity The datetime instance.
138
-     * @param int      $venue  The venue ID
139
-     * @throws EE_Error
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidInterfaceException
142
-     * @throws InvalidArgumentException
143
-     * @throws ReflectionException
144
-     */
145
-    public static function setVenue(EE_Datetime $entity, int $venue)
146
-    {
147
-        if (empty($venue)) {
148
-            $entity->remove_venue($venue);
149
-        } else {
150
-            $entity->add_venue($venue);
151
-        }
152
-    }
23
+	/**
24
+	 * Maps the GraphQL input to a format that the model functions can use
25
+	 *
26
+	 * @param array $input Data coming from the GraphQL mutation query input
27
+	 * @return array
28
+	 * @throws Exception
29
+	 */
30
+	public static function prepareFields(array $input): array
31
+	{
32
+		$args = [];
33
+
34
+		if (array_key_exists('capacity', $input)) {
35
+			$args['DTT_reg_limit'] = (int) $input['capacity'];
36
+		}
37
+
38
+		if (isset($input['description'])) {
39
+			$args['DTT_description'] = wp_kses_post($input['description']);
40
+		}
41
+
42
+		if (! empty($input['endDate'])) {
43
+			$args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate']));
44
+		}
45
+
46
+		if (! empty($input['eventId'])) {
47
+			$args['EVT_ID'] = absint($input['eventId']);
48
+		} elseif (! empty($input['event'])) {
49
+			$parts = Relay::fromGlobalId(sanitize_text_field($input['event']));
50
+			$args['EVT_ID'] = ! empty($parts['id']) ? $parts['id'] : null;
51
+		}
52
+
53
+		if (array_key_exists('isPrimary', $input)) {
54
+			$args['DTT_is_primary'] = (bool) $input['isPrimary'];
55
+		}
56
+
57
+		if (array_key_exists('isTrashed', $input)) {
58
+			$args['DTT_deleted'] = (bool) $input['isTrashed'];
59
+		}
60
+
61
+		if (isset($input['name'])) {
62
+			$args['DTT_name'] = sanitize_text_field($input['name']);
63
+		}
64
+
65
+		if (array_key_exists('order', $input)) {
66
+			$args['DTT_order'] = (int) $input['order'];
67
+		}
68
+
69
+		if (! empty($input['parent'])) {
70
+			$parts = Relay::fromGlobalId(sanitize_text_field($input['parent']));
71
+			$args['DTT_parent'] = ! empty($parts['id']) ? $parts['id'] : null;
72
+		}
73
+
74
+		if (array_key_exists('reserved', $input)) {
75
+			$args['DTT_reserved'] = (int) $input['reserved'];
76
+		}
77
+
78
+		if (array_key_exists('sold', $input)) {
79
+			$args['DTT_sold'] = (int) $input['sold'];
80
+		}
81
+
82
+		if (! empty($input['startDate'])) {
83
+			$args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate']));
84
+		}
85
+
86
+		if (! empty($input['tickets'])) {
87
+			$args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']);
88
+		}
89
+
90
+		if (array_key_exists('venue', $input)) {
91
+			$venue_id = sanitize_text_field($input['venue']);
92
+			$parts = Relay::fromGlobalId($venue_id);
93
+			$venue_id = ! empty($parts['id']) ? $parts['id'] : $venue_id;
94
+			$args['venue'] = absint($venue_id);
95
+		}
96
+
97
+		return apply_filters(
98
+			'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__datetime_args',
99
+			$args,
100
+			$input
101
+		);
102
+	}
103
+
104
+
105
+	/**
106
+	 * Sets the related tickets for the given datetime.
107
+	 *
108
+	 * @param EE_Datetime $entity  The datetime instance.
109
+	 * @param array       $tickets Array of ticket IDs to relate.
110
+	 * @throws EE_Error
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws InvalidInterfaceException
113
+	 * @throws InvalidArgumentException
114
+	 * @throws ReflectionException
115
+	 */
116
+	public static function setRelatedTickets(EE_Datetime $entity, array $tickets)
117
+	{
118
+		$relationName = 'Ticket';
119
+		// Remove all the existing related tickets
120
+		$entity->_remove_relations($relationName);
121
+
122
+		foreach ($tickets as $ID) {
123
+			$parts = Relay::fromGlobalId($ID);
124
+			if (! empty($parts['id']) && absint($parts['id'])) {
125
+				$entity->_add_relation_to(
126
+					$parts['id'],
127
+					$relationName
128
+				);
129
+			}
130
+		}
131
+	}
132
+
133
+
134
+	/**
135
+	 * Sets the venue for the datetime.
136
+	 *
137
+	 * @param EE_Datetime $entity The datetime instance.
138
+	 * @param int      $venue  The venue ID
139
+	 * @throws EE_Error
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidInterfaceException
142
+	 * @throws InvalidArgumentException
143
+	 * @throws ReflectionException
144
+	 */
145
+	public static function setVenue(EE_Datetime $entity, int $venue)
146
+	{
147
+		if (empty($venue)) {
148
+			$entity->remove_venue($venue);
149
+		} else {
150
+			$entity->add_venue($venue);
151
+		}
152
+	}
153 153
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Message_Type.lib.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         }
61 61
 
62 62
         // make sure we don't register twice
63
-        if (isset(self::$_ee_message_type_registry[ $addon_name ])) {
63
+        if (isset(self::$_ee_message_type_registry[$addon_name])) {
64 64
             return true;
65 65
         }
66 66
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             );
83 83
         }
84 84
         // setup $__ee_message_type_registry array from incoming values.
85
-        self::$_ee_message_type_registry[ $addon_name ] = [
85
+        self::$_ee_message_type_registry[$addon_name] = [
86 86
             /**
87 87
              * The file name for the message type being registered.
88 88
              * Required.
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public static function deregister(string $addon_name = '')
265 265
     {
266
-        if (! empty(self::$_ee_message_type_registry[ $addon_name ])) {
266
+        if ( ! empty(self::$_ee_message_type_registry[$addon_name])) {
267 267
             // let's make sure that we remove any place this message type was made active
268 268
             /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
269 269
             $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
             );
276 276
             $Message_Resource_Manager->deactivate_message_type($addon_name, false);
277 277
         }
278
-        unset(self::$_ee_message_type_registry[ $addon_name ]);
278
+        unset(self::$_ee_message_type_registry[$addon_name]);
279 279
     }
280 280
 
281 281
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     public static function register_msgs_autoload_paths(array $paths): array
312 312
     {
313 313
         $autoload_paths = [];
314
-        if (! empty(self::$_ee_message_type_registry)) {
314
+        if ( ! empty(self::$_ee_message_type_registry)) {
315 315
             foreach (self::$_ee_message_type_registry as $mt_reg) {
316 316
                 if (empty($mt_reg['autoloadpaths'])) {
317 317
                     continue;
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
                 continue;
401 401
             }
402 402
             foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
403
-                $supports[ $messenger_slug ][] = $addon_name;
403
+                $supports[$messenger_slug][] = $addon_name;
404 404
             }
405 405
         }
406 406
         return $supports;
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
         string $file_extension,
473 473
         EE_Messages_Template_Pack $template_pack
474 474
     ): string {
475
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
475
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
476 476
             return $base_path_or_url;
477 477
         }
478 478
         foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
                 if ($url && ! empty($mt_reg['base_url_for_default_variation'])) {
481 481
                     return $mt_reg['base_url_for_default_variation'];
482 482
                 }
483
-                if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
483
+                if ( ! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
484 484
                     return $mt_reg['base_path_for_default_variation'];
485 485
                 }
486 486
             }
Please login to merge, or discard this patch.
Indentation   +453 added lines, -453 removed lines patch added patch discarded remove patch
@@ -10,485 +10,485 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Register_Message_Type implements EEI_Plugin_API
12 12
 {
13
-    /**
14
-     * Holds values for registered message types
15
-     *
16
-     * @var array
17
-     */
18
-    protected static $_ee_message_type_registry = [];
13
+	/**
14
+	 * Holds values for registered message types
15
+	 *
16
+	 * @var array
17
+	 */
18
+	protected static $_ee_message_type_registry = [];
19 19
 
20 20
 
21
-    /**
22
-     * Method for registering new message types in the EE_messages system.
23
-     * Note:  All message types must have the following files in order to work:
24
-     * Template files for default templates getting setup.
25
-     * See /core/libraries/messages/defaults/default/ for examples
26
-     * (note that template files match a specific naming schema).
27
-     * These templates will need to be registered with the default template pack.
28
-     * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
29
-     *      for examples.  Note for any new message types, there will need to be a validator for each
30
-     *      messenger combo this message type can activate with.
31
-     * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
32
-     *      message type and its properties.
33
-     *
34
-     * @param string $addon_name    Whatever is defined for the $name property of
35
-     *                              the message type you are registering (eg.
36
-     *                              declined_registration). Required.
37
-     * @param array  $setup_args    An array of arguments provided for registering the message type.
38
-     * @throws EE_Error
39
-     *                              }
40
-     * @see      inline docs in the register method for what can be passed in as arguments.
41
-     * @since    4.3.0
42
-     */
43
-    public static function register(string $addon_name = '', array $setup_args = []): bool
44
-    {
45
-        // required fields MUST be present, so let's make sure they are.
46
-        if (
47
-            ! isset($addon_name)
48
-            || ! is_array($setup_args)
49
-            || empty($setup_args['mtfilename'])
50
-            || empty($setup_args['autoloadpaths'])
51
-        ) {
52
-            throw new EE_Error(
53
-                esc_html__(
54
-                    'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
21
+	/**
22
+	 * Method for registering new message types in the EE_messages system.
23
+	 * Note:  All message types must have the following files in order to work:
24
+	 * Template files for default templates getting setup.
25
+	 * See /core/libraries/messages/defaults/default/ for examples
26
+	 * (note that template files match a specific naming schema).
27
+	 * These templates will need to be registered with the default template pack.
28
+	 * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
29
+	 *      for examples.  Note for any new message types, there will need to be a validator for each
30
+	 *      messenger combo this message type can activate with.
31
+	 * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
32
+	 *      message type and its properties.
33
+	 *
34
+	 * @param string $addon_name    Whatever is defined for the $name property of
35
+	 *                              the message type you are registering (eg.
36
+	 *                              declined_registration). Required.
37
+	 * @param array  $setup_args    An array of arguments provided for registering the message type.
38
+	 * @throws EE_Error
39
+	 *                              }
40
+	 * @see      inline docs in the register method for what can be passed in as arguments.
41
+	 * @since    4.3.0
42
+	 */
43
+	public static function register(string $addon_name = '', array $setup_args = []): bool
44
+	{
45
+		// required fields MUST be present, so let's make sure they are.
46
+		if (
47
+			! isset($addon_name)
48
+			|| ! is_array($setup_args)
49
+			|| empty($setup_args['mtfilename'])
50
+			|| empty($setup_args['autoloadpaths'])
51
+		) {
52
+			throw new EE_Error(
53
+				esc_html__(
54
+					'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59 59
 
60
-        // make sure we don't register twice
61
-        if (isset(self::$_ee_message_type_registry[ $addon_name ])) {
62
-            return true;
63
-        }
60
+		// make sure we don't register twice
61
+		if (isset(self::$_ee_message_type_registry[ $addon_name ])) {
62
+			return true;
63
+		}
64 64
 
65
-        // make sure this was called in the right place!
66
-        if (
67
-            ! did_action('EE_Brewing_Regular___messages_caf')
68
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    esc_html__(
74
-                        'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $addon_name
78
-                ),
79
-                '4.3.0'
80
-            );
81
-        }
82
-        // setup $__ee_message_type_registry array from incoming values.
83
-        self::$_ee_message_type_registry[ $addon_name ] = [
84
-            /**
85
-             * The file name for the message type being registered.
86
-             * Required.
87
-             *
88
-             * @type string
89
-             */
90
-            'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
-            /**
92
-             * Autoload paths for classes used by the message type.
93
-             * Required.
94
-             *
95
-             * @type array
96
-             */
97
-            'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
-            /**
99
-             * Messengers that the message type should be able to activate with.
100
-             * Use messenger slugs.
101
-             *
102
-             * @type array
103
-             */
104
-            'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
-                ? (array) $setup_args['messengers_to_activate_with']
106
-                : [],
107
-            /**
108
-             * Messengers that the message type should validate with.
109
-             * Use messenger slugs.
110
-             *
111
-             * @type array
112
-             */
113
-            'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
-                ? (array) $setup_args['messengers_to_validate_with']
115
-                : [],
116
-            /**
117
-             * Whether to force activate this message type the first time it is registered.
118
-             *
119
-             * @type bool   False means its not activated by default and left up to the end user to activate.
120
-             */
121
-            'force_activation'                                 => ! empty($setup_args['force_activation'])
122
-                                                                  && $setup_args['force_activation'],
123
-            /**
124
-             * What messengers this message type supports the default template pack for.
125
-             * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
-             * then it is expected that the message type being registered is doing its own custom default template
127
-             * pack/variation registration.
128
-             *
129
-             * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
-             * $setup_arguments array as well:
131
-             * - 'base_path_for_default_templates'
132
-             *
133
-             * @type array   Expect an array of messengers this supports default template packs for.
134
-             */
135
-            'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
-                ? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
-                : [],
138
-            /**
139
-             * The base path where the default templates for this message type can be found.
140
-             *
141
-             * @type string
142
-             */
143
-            'base_path_for_default_templates'                  => $setup_args['base_path_for_default_templates'] ?? '',
144
-            /**
145
-             * The base path where the default variations for this message type can be found.
146
-             *
147
-             * @type string
148
-             */
149
-            'base_path_for_default_variation'                  => $setup_args['base_path_for_default_variation'] ?? '',
150
-            /**
151
-             * The base url for the default variations for this message type.
152
-             *
153
-             * @type string
154
-             */
155
-            'base_url_for_default_variation'                   => $setup_args['base_url_for_default_variation'] ?? '',
156
-        ];
157
-        // add filters but only if they haven't already been set (these filters only need to be registered ONCE because
158
-        // the callback handles all registered message types.
159
-        if (
160
-            has_filter(
161
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
162
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths']
163
-            ) === false
164
-        ) {
165
-            add_filter(
166
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
167
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
168
-                10
169
-            );
170
-            add_filter(
171
-                'FHEE__EE_messages__get_installed__messagetype_files',
172
-                ['EE_Register_Message_Type', 'register_messagetype_files'],
173
-                10,
174
-                1
175
-            );
176
-            add_filter(
177
-                'FHEE__EE_messenger__get_default_message_types__default_types',
178
-                ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
179
-                10,
180
-                2
181
-            );
182
-            add_filter(
183
-                'FHEE__EE_messenger__get_valid_message_types__valid_types',
184
-                ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
185
-                10,
186
-                2
187
-            );
188
-            // actions
189
-            add_action(
190
-                'AHEE__EE_Addon__initialize_default_data__begin',
191
-                ['EE_Register_Message_Type', 'set_defaults']
192
-            );
65
+		// make sure this was called in the right place!
66
+		if (
67
+			! did_action('EE_Brewing_Regular___messages_caf')
68
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					esc_html__(
74
+						'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
+						'event_espresso'
76
+					),
77
+					$addon_name
78
+				),
79
+				'4.3.0'
80
+			);
81
+		}
82
+		// setup $__ee_message_type_registry array from incoming values.
83
+		self::$_ee_message_type_registry[ $addon_name ] = [
84
+			/**
85
+			 * The file name for the message type being registered.
86
+			 * Required.
87
+			 *
88
+			 * @type string
89
+			 */
90
+			'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
+			/**
92
+			 * Autoload paths for classes used by the message type.
93
+			 * Required.
94
+			 *
95
+			 * @type array
96
+			 */
97
+			'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
+			/**
99
+			 * Messengers that the message type should be able to activate with.
100
+			 * Use messenger slugs.
101
+			 *
102
+			 * @type array
103
+			 */
104
+			'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
+				? (array) $setup_args['messengers_to_activate_with']
106
+				: [],
107
+			/**
108
+			 * Messengers that the message type should validate with.
109
+			 * Use messenger slugs.
110
+			 *
111
+			 * @type array
112
+			 */
113
+			'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
+				? (array) $setup_args['messengers_to_validate_with']
115
+				: [],
116
+			/**
117
+			 * Whether to force activate this message type the first time it is registered.
118
+			 *
119
+			 * @type bool   False means its not activated by default and left up to the end user to activate.
120
+			 */
121
+			'force_activation'                                 => ! empty($setup_args['force_activation'])
122
+																  && $setup_args['force_activation'],
123
+			/**
124
+			 * What messengers this message type supports the default template pack for.
125
+			 * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
+			 * then it is expected that the message type being registered is doing its own custom default template
127
+			 * pack/variation registration.
128
+			 *
129
+			 * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
+			 * $setup_arguments array as well:
131
+			 * - 'base_path_for_default_templates'
132
+			 *
133
+			 * @type array   Expect an array of messengers this supports default template packs for.
134
+			 */
135
+			'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
+				? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
+				: [],
138
+			/**
139
+			 * The base path where the default templates for this message type can be found.
140
+			 *
141
+			 * @type string
142
+			 */
143
+			'base_path_for_default_templates'                  => $setup_args['base_path_for_default_templates'] ?? '',
144
+			/**
145
+			 * The base path where the default variations for this message type can be found.
146
+			 *
147
+			 * @type string
148
+			 */
149
+			'base_path_for_default_variation'                  => $setup_args['base_path_for_default_variation'] ?? '',
150
+			/**
151
+			 * The base url for the default variations for this message type.
152
+			 *
153
+			 * @type string
154
+			 */
155
+			'base_url_for_default_variation'                   => $setup_args['base_url_for_default_variation'] ?? '',
156
+		];
157
+		// add filters but only if they haven't already been set (these filters only need to be registered ONCE because
158
+		// the callback handles all registered message types.
159
+		if (
160
+			has_filter(
161
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
162
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths']
163
+			) === false
164
+		) {
165
+			add_filter(
166
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
167
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
168
+				10
169
+			);
170
+			add_filter(
171
+				'FHEE__EE_messages__get_installed__messagetype_files',
172
+				['EE_Register_Message_Type', 'register_messagetype_files'],
173
+				10,
174
+				1
175
+			);
176
+			add_filter(
177
+				'FHEE__EE_messenger__get_default_message_types__default_types',
178
+				['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
179
+				10,
180
+				2
181
+			);
182
+			add_filter(
183
+				'FHEE__EE_messenger__get_valid_message_types__valid_types',
184
+				['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
185
+				10,
186
+				2
187
+			);
188
+			// actions
189
+			add_action(
190
+				'AHEE__EE_Addon__initialize_default_data__begin',
191
+				['EE_Register_Message_Type', 'set_defaults']
192
+			);
193 193
 
194
-            // default template packs and variations related
195
-            add_filter(
196
-                'FHEE__EE_Messages_Template_Pack_Default__get_supports',
197
-                ['EE_Register_Message_Type', 'register_default_template_pack_supports']
198
-            );
199
-            add_filter(
200
-                'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
201
-                ['EE_Register_Message_Type', 'register_base_template_path'],
202
-                10,
203
-                6
204
-            );
205
-            add_filter(
206
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
207
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
208
-                10,
209
-                8
210
-            );
211
-            add_filter(
212
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
213
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
214
-                10,
215
-                8
216
-            );
217
-        }
218
-        return true;
219
-    }
194
+			// default template packs and variations related
195
+			add_filter(
196
+				'FHEE__EE_Messages_Template_Pack_Default__get_supports',
197
+				['EE_Register_Message_Type', 'register_default_template_pack_supports']
198
+			);
199
+			add_filter(
200
+				'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
201
+				['EE_Register_Message_Type', 'register_base_template_path'],
202
+				10,
203
+				6
204
+			);
205
+			add_filter(
206
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
207
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
208
+				10,
209
+				8
210
+			);
211
+			add_filter(
212
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
213
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
214
+				10,
215
+				8
216
+			);
217
+		}
218
+		return true;
219
+	}
220 220
 
221 221
 
222
-    /**
223
-     * This just ensures that when an addon registers a message type that on initial activation/reactivation the
224
-     * defaults the addon sets are taken care of.
225
-     *
226
-     * @throws EE_Error
227
-     * @throws ReflectionException
228
-     */
229
-    public static function set_defaults()
230
-    {
231
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
232
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
222
+	/**
223
+	 * This just ensures that when an addon registers a message type that on initial activation/reactivation the
224
+	 * defaults the addon sets are taken care of.
225
+	 *
226
+	 * @throws EE_Error
227
+	 * @throws ReflectionException
228
+	 */
229
+	public static function set_defaults()
230
+	{
231
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
232
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
233 233
 
234
-        // for any message types with force activation, let's ensure they are activated
235
-        foreach (self::$_ee_message_type_registry as $addon_name => $settings) {
236
-            if ($settings['force_activation']) {
237
-                foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
-                    // DO not force activation if this message type has already been activated in the system
239
-                    if (
240
-                        ! $message_resource_manager->has_message_type_been_activated_for_messenger(
241
-                            $addon_name,
242
-                            $messenger
243
-                        )
244
-                    ) {
245
-                        $message_resource_manager->ensure_message_type_is_active($addon_name, $messenger);
246
-                    }
247
-                }
248
-            }
249
-        }
250
-    }
234
+		// for any message types with force activation, let's ensure they are activated
235
+		foreach (self::$_ee_message_type_registry as $addon_name => $settings) {
236
+			if ($settings['force_activation']) {
237
+				foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
+					// DO not force activation if this message type has already been activated in the system
239
+					if (
240
+						! $message_resource_manager->has_message_type_been_activated_for_messenger(
241
+							$addon_name,
242
+							$messenger
243
+						)
244
+					) {
245
+						$message_resource_manager->ensure_message_type_is_active($addon_name, $messenger);
246
+					}
247
+				}
248
+			}
249
+		}
250
+	}
251 251
 
252 252
 
253
-    /**
254
-     * This deregisters a message type that was previously registered with a specific message_type_name.
255
-     *
256
-     * @param string $addon_name the name for the message type that was previously registered
257
-     * @return void
258
-     * @throws EE_Error
259
-     * @throws ReflectionException
260
-     * @since    4.3.0
261
-     */
262
-    public static function deregister(string $addon_name = '')
263
-    {
264
-        if (! empty(self::$_ee_message_type_registry[ $addon_name ])) {
265
-            // let's make sure that we remove any place this message type was made active
266
-            /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
267
-            $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
268
-            // ensures that if this message type is registered again that it retains its previous active state vs
269
-            // remaining inactive.
270
-            $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
271
-                $addon_name,
272
-                true
273
-            );
274
-            $Message_Resource_Manager->deactivate_message_type($addon_name, false);
275
-        }
276
-        unset(self::$_ee_message_type_registry[ $addon_name ]);
277
-    }
253
+	/**
254
+	 * This deregisters a message type that was previously registered with a specific message_type_name.
255
+	 *
256
+	 * @param string $addon_name the name for the message type that was previously registered
257
+	 * @return void
258
+	 * @throws EE_Error
259
+	 * @throws ReflectionException
260
+	 * @since    4.3.0
261
+	 */
262
+	public static function deregister(string $addon_name = '')
263
+	{
264
+		if (! empty(self::$_ee_message_type_registry[ $addon_name ])) {
265
+			// let's make sure that we remove any place this message type was made active
266
+			/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
267
+			$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
268
+			// ensures that if this message type is registered again that it retains its previous active state vs
269
+			// remaining inactive.
270
+			$Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
271
+				$addon_name,
272
+				true
273
+			);
274
+			$Message_Resource_Manager->deactivate_message_type($addon_name, false);
275
+		}
276
+		unset(self::$_ee_message_type_registry[ $addon_name ]);
277
+	}
278 278
 
279 279
 
280
-    /**
281
-     * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
282
-     *
283
-     * @param array $messagetype_files The current array of message type file names
284
-     * @return  array                                 Array of message type file names
285
-     * @since   4.3.0
286
-     */
287
-    public static function register_messagetype_files(array $messagetype_files): array
288
-    {
289
-        if (empty(self::$_ee_message_type_registry)) {
290
-            return $messagetype_files;
291
-        }
292
-        foreach (self::$_ee_message_type_registry as $mt_reg) {
293
-            if (empty($mt_reg['mtfilename'])) {
294
-                continue;
295
-            }
296
-            $messagetype_files[] = $mt_reg['mtfilename'];
297
-        }
298
-        return $messagetype_files;
299
-    }
280
+	/**
281
+	 * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
282
+	 *
283
+	 * @param array $messagetype_files The current array of message type file names
284
+	 * @return  array                                 Array of message type file names
285
+	 * @since   4.3.0
286
+	 */
287
+	public static function register_messagetype_files(array $messagetype_files): array
288
+	{
289
+		if (empty(self::$_ee_message_type_registry)) {
290
+			return $messagetype_files;
291
+		}
292
+		foreach (self::$_ee_message_type_registry as $mt_reg) {
293
+			if (empty($mt_reg['mtfilename'])) {
294
+				continue;
295
+			}
296
+			$messagetype_files[] = $mt_reg['mtfilename'];
297
+		}
298
+		return $messagetype_files;
299
+	}
300 300
 
301 301
 
302
-    /**
303
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
304
-     *
305
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
306
-     * @return array
307
-     * @since    4.3.0
308
-     */
309
-    public static function register_msgs_autoload_paths(array $paths): array
310
-    {
311
-        $autoload_paths = [];
312
-        if (! empty(self::$_ee_message_type_registry)) {
313
-            foreach (self::$_ee_message_type_registry as $mt_reg) {
314
-                if (empty($mt_reg['autoloadpaths'])) {
315
-                    continue;
316
-                }
317
-                $autoload_paths[] = $mt_reg['autoloadpaths'];
318
-            }
319
-        }
320
-        return array_merge($paths, ...$autoload_paths);
321
-    }
302
+	/**
303
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
304
+	 *
305
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
306
+	 * @return array
307
+	 * @since    4.3.0
308
+	 */
309
+	public static function register_msgs_autoload_paths(array $paths): array
310
+	{
311
+		$autoload_paths = [];
312
+		if (! empty(self::$_ee_message_type_registry)) {
313
+			foreach (self::$_ee_message_type_registry as $mt_reg) {
314
+				if (empty($mt_reg['autoloadpaths'])) {
315
+					continue;
316
+				}
317
+				$autoload_paths[] = $mt_reg['autoloadpaths'];
318
+			}
319
+		}
320
+		return array_merge($paths, ...$autoload_paths);
321
+	}
322 322
 
323 323
 
324
-    /**
325
-     * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
326
-     *
327
-     * @param array        $default_types   array of message types activated with messenger (
328
-     *                                      corresponds to the $name property of message type)
329
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
330
-     * @return array
331
-     * @since  4.3.0
332
-     */
333
-    public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger): array
334
-    {
335
-        if (empty(self::$_ee_message_type_registry)) {
336
-            return $default_types;
337
-        }
338
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
339
-            if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
340
-                continue;
341
-            }
342
-            // loop through each of the messengers and if it matches the loaded class
343
-            // then we add this message type to the
344
-            foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
345
-                if ($messenger->name == $msgr) {
346
-                    $default_types[] = $addon_name;
347
-                }
348
-            }
349
-        }
324
+	/**
325
+	 * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
326
+	 *
327
+	 * @param array        $default_types   array of message types activated with messenger (
328
+	 *                                      corresponds to the $name property of message type)
329
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
330
+	 * @return array
331
+	 * @since  4.3.0
332
+	 */
333
+	public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger): array
334
+	{
335
+		if (empty(self::$_ee_message_type_registry)) {
336
+			return $default_types;
337
+		}
338
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
339
+			if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
340
+				continue;
341
+			}
342
+			// loop through each of the messengers and if it matches the loaded class
343
+			// then we add this message type to the
344
+			foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
345
+				if ($messenger->name == $msgr) {
346
+					$default_types[] = $addon_name;
347
+				}
348
+			}
349
+		}
350 350
 
351
-        return $default_types;
352
-    }
351
+		return $default_types;
352
+	}
353 353
 
354 354
 
355
-    /**
356
-     * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
357
-     *
358
-     * @param array        $valid_types     array of message types valid with messenger (
359
-     *                                      corresponds to the $name property of message type)
360
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
361
-     * @return  array
362
-     * @since   4.3.0
363
-     */
364
-    public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger): array
365
-    {
366
-        if (empty(self::$_ee_message_type_registry)) {
367
-            return $valid_types;
368
-        }
369
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
370
-            if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
371
-                continue;
372
-            }
373
-            // loop through each of the messengers and if it matches the loaded class
374
-            // then we add this message type to the
375
-            foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
376
-                if ($messenger->name == $msgr) {
377
-                    $valid_types[] = $addon_name;
378
-                }
379
-            }
380
-        }
355
+	/**
356
+	 * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
357
+	 *
358
+	 * @param array        $valid_types     array of message types valid with messenger (
359
+	 *                                      corresponds to the $name property of message type)
360
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
361
+	 * @return  array
362
+	 * @since   4.3.0
363
+	 */
364
+	public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger): array
365
+	{
366
+		if (empty(self::$_ee_message_type_registry)) {
367
+			return $valid_types;
368
+		}
369
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
370
+			if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
371
+				continue;
372
+			}
373
+			// loop through each of the messengers and if it matches the loaded class
374
+			// then we add this message type to the
375
+			foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
376
+				if ($messenger->name == $msgr) {
377
+					$valid_types[] = $addon_name;
378
+				}
379
+			}
380
+		}
381 381
 
382
-        return $valid_types;
383
-    }
382
+		return $valid_types;
383
+	}
384 384
 
385 385
 
386
-    /**
387
-     * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
388
-     * supporting the default template pack
389
-     *
390
-     * @param array $supports
391
-     *
392
-     * @return array
393
-     */
394
-    public static function register_default_template_pack_supports(array $supports): array
395
-    {
396
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
397
-            if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
398
-                continue;
399
-            }
400
-            foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
401
-                $supports[ $messenger_slug ][] = $addon_name;
402
-            }
403
-        }
404
-        return $supports;
405
-    }
386
+	/**
387
+	 * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
388
+	 * supporting the default template pack
389
+	 *
390
+	 * @param array $supports
391
+	 *
392
+	 * @return array
393
+	 */
394
+	public static function register_default_template_pack_supports(array $supports): array
395
+	{
396
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
397
+			if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
398
+				continue;
399
+			}
400
+			foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
401
+				$supports[ $messenger_slug ][] = $addon_name;
402
+			}
403
+		}
404
+		return $supports;
405
+	}
406 406
 
407 407
 
408
-    /**
409
-     * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
410
-     *
411
-     * @param string                    $base_path The original base path for message templates
412
-     * @param EE_messenger              $messenger
413
-     * @param EE_message_type           $message_type
414
-     * @param string                    $field     The field requesting a template
415
-     * @param string                    $context   The context requesting a template
416
-     * @param EE_Messages_Template_Pack $template_pack
417
-     *
418
-     * @return string
419
-     */
420
-    public static function register_base_template_path(
421
-        string $base_path,
422
-        EE_messenger $messenger,
423
-        EE_message_type $message_type,
424
-        string $field,
425
-        string $context,
426
-        EE_Messages_Template_Pack $template_pack
427
-    ): string {
428
-        if (
429
-            ! $template_pack instanceof EE_Messages_Template_Pack_Default
430
-            || ! $message_type instanceof EE_message_type
431
-        ) {
432
-            return $base_path;
433
-        }
434
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
435
-            if (
436
-                $message_type->name === $addon_name
437
-                && ! empty($mt_reg['base_path_for_default_templates'])
438
-            ) {
439
-                return $mt_reg['base_path_for_default_templates'];
440
-            }
441
-        }
442
-        return $base_path;
443
-    }
408
+	/**
409
+	 * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
410
+	 *
411
+	 * @param string                    $base_path The original base path for message templates
412
+	 * @param EE_messenger              $messenger
413
+	 * @param EE_message_type           $message_type
414
+	 * @param string                    $field     The field requesting a template
415
+	 * @param string                    $context   The context requesting a template
416
+	 * @param EE_Messages_Template_Pack $template_pack
417
+	 *
418
+	 * @return string
419
+	 */
420
+	public static function register_base_template_path(
421
+		string $base_path,
422
+		EE_messenger $messenger,
423
+		EE_message_type $message_type,
424
+		string $field,
425
+		string $context,
426
+		EE_Messages_Template_Pack $template_pack
427
+	): string {
428
+		if (
429
+			! $template_pack instanceof EE_Messages_Template_Pack_Default
430
+			|| ! $message_type instanceof EE_message_type
431
+		) {
432
+			return $base_path;
433
+		}
434
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
435
+			if (
436
+				$message_type->name === $addon_name
437
+				&& ! empty($mt_reg['base_path_for_default_templates'])
438
+			) {
439
+				return $mt_reg['base_path_for_default_templates'];
440
+			}
441
+		}
442
+		return $base_path;
443
+	}
444 444
 
445 445
 
446
-    /**
447
-     * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
448
-     * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
449
-     *
450
-     * @param string                    $base_path_or_url  The original incoming base url or path
451
-     * @param string                    $messenger_slug    The slug of the messenger the template is being generated
452
-     *                                                     for.
453
-     * @param string                    $message_type_slug The slug of the message type the template is being generated
454
-     *                                                     for.
455
-     * @param string                    $type              The "type" of css being requested.
456
-     * @param string                    $variation         The variation being requested.
457
-     * @param bool                      $url               whether a url or path is being requested.
458
-     * @param string                    $file_extension    What file extension is expected for the variation file.
459
-     * @param EE_Messages_Template_Pack $template_pack
460
-     *
461
-     * @return string
462
-     */
463
-    public static function register_variation_base_path_or_url(
464
-        string $base_path_or_url,
465
-        string $messenger_slug,
466
-        string $message_type_slug,
467
-        string $type,
468
-        string $variation,
469
-        bool $url,
470
-        string $file_extension,
471
-        EE_Messages_Template_Pack $template_pack
472
-    ): string {
473
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
474
-            return $base_path_or_url;
475
-        }
476
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
477
-            if ($addon_name === $message_type_slug) {
478
-                if ($url && ! empty($mt_reg['base_url_for_default_variation'])) {
479
-                    return $mt_reg['base_url_for_default_variation'];
480
-                }
481
-                if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
482
-                    return $mt_reg['base_path_for_default_variation'];
483
-                }
484
-            }
485
-        }
486
-        return $base_path_or_url;
487
-    }
446
+	/**
447
+	 * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
448
+	 * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
449
+	 *
450
+	 * @param string                    $base_path_or_url  The original incoming base url or path
451
+	 * @param string                    $messenger_slug    The slug of the messenger the template is being generated
452
+	 *                                                     for.
453
+	 * @param string                    $message_type_slug The slug of the message type the template is being generated
454
+	 *                                                     for.
455
+	 * @param string                    $type              The "type" of css being requested.
456
+	 * @param string                    $variation         The variation being requested.
457
+	 * @param bool                      $url               whether a url or path is being requested.
458
+	 * @param string                    $file_extension    What file extension is expected for the variation file.
459
+	 * @param EE_Messages_Template_Pack $template_pack
460
+	 *
461
+	 * @return string
462
+	 */
463
+	public static function register_variation_base_path_or_url(
464
+		string $base_path_or_url,
465
+		string $messenger_slug,
466
+		string $message_type_slug,
467
+		string $type,
468
+		string $variation,
469
+		bool $url,
470
+		string $file_extension,
471
+		EE_Messages_Template_Pack $template_pack
472
+	): string {
473
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
474
+			return $base_path_or_url;
475
+		}
476
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
477
+			if ($addon_name === $message_type_slug) {
478
+				if ($url && ! empty($mt_reg['base_url_for_default_variation'])) {
479
+					return $mt_reg['base_url_for_default_variation'];
480
+				}
481
+				if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
482
+					return $mt_reg['base_path_for_default_variation'];
483
+				}
484
+			}
485
+		}
486
+		return $base_path_or_url;
487
+	}
488 488
 
489 489
 
490
-    public static function reset(): void
491
-    {
492
-        self::$_ee_message_type_registry = [];
493
-    }
490
+	public static function reset(): void
491
+	{
492
+		self::$_ee_message_type_registry = [];
493
+	}
494 494
 }
Please login to merge, or discard this patch.
core/services/encryption/EncryptionMethodInterface.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -12,46 +12,46 @@
 block discarded – undo
12 12
  */
13 13
 interface EncryptionMethodInterface
14 14
 {
15
-    /**
16
-     * returns true if the encryption method is cryptographically secure
17
-     *
18
-     * @return bool
19
-     */
20
-    public function isCryptographicallySecure();
21
-
22
-
23
-    /**
24
-     * returns true if the method can be used on the current server
25
-     *
26
-     * @return bool
27
-     */
28
-    public function canUse();
29
-
30
-
31
-    /**
32
-     * returns a message explaining why the encryption method in question can or can not be used
33
-     *
34
-     * @return string
35
-     */
36
-    public function canUseNotice();
37
-
38
-
39
-    /**
40
-     * encrypts data
41
-     *
42
-     * @param string $text_to_encrypt           - the text to be encrypted
43
-     * @param string $encryption_key_identifier - name of the encryption key to use
44
-     * @return string
45
-     */
46
-    public function encrypt($text_to_encrypt, $encryption_key_identifier = '');
47
-
48
-
49
-    /**
50
-     * decrypts data
51
-     *
52
-     * @param string $encrypted_text            - the text to be decrypted
53
-     * @param string $encryption_key_identifier - name of the encryption key to use
54
-     * @return string
55
-     */
56
-    public function decrypt($encrypted_text, $encryption_key_identifier = '');
15
+	/**
16
+	 * returns true if the encryption method is cryptographically secure
17
+	 *
18
+	 * @return bool
19
+	 */
20
+	public function isCryptographicallySecure();
21
+
22
+
23
+	/**
24
+	 * returns true if the method can be used on the current server
25
+	 *
26
+	 * @return bool
27
+	 */
28
+	public function canUse();
29
+
30
+
31
+	/**
32
+	 * returns a message explaining why the encryption method in question can or can not be used
33
+	 *
34
+	 * @return string
35
+	 */
36
+	public function canUseNotice();
37
+
38
+
39
+	/**
40
+	 * encrypts data
41
+	 *
42
+	 * @param string $text_to_encrypt           - the text to be encrypted
43
+	 * @param string $encryption_key_identifier - name of the encryption key to use
44
+	 * @return string
45
+	 */
46
+	public function encrypt($text_to_encrypt, $encryption_key_identifier = '');
47
+
48
+
49
+	/**
50
+	 * decrypts data
51
+	 *
52
+	 * @param string $encrypted_text            - the text to be decrypted
53
+	 * @param string $encryption_key_identifier - name of the encryption key to use
54
+	 * @return string
55
+	 */
56
+	public function decrypt($encrypted_text, $encryption_key_identifier = '');
57 57
 }
Please login to merge, or discard this patch.
core/services/encryption/openssl/OpenSSL.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function canUseNotice()
122 122
     {
123
-        if (! $this->openssl_installed) {
123
+        if ( ! $this->openssl_installed) {
124 124
             return esc_html__(
125 125
                 'The PHP openssl server extension is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
126 126
                 'event_espresso'
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      */
220 220
     protected function getHashAlgorithm()
221 221
     {
222
-        if (! $this->hash_algorithm) {
222
+        if ( ! $this->hash_algorithm) {
223 223
             // get installed hashing algorithms
224 224
             $hash_algorithms = hash_algos();
225 225
             // filter array for "sha" algorithms
Please login to merge, or discard this patch.
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -17,266 +17,266 @@
 block discarded – undo
17 17
  */
18 18
 abstract class OpenSSL implements EncryptionMethodInterface
19 19
 {
20
-    /**
21
-     * the default OPENSSL digest method to use
22
-     */
23
-    const DEFAULT_DIGEST_METHOD = 'sha512';
24
-
25
-    /**
26
-     * separates the encrypted text from the initialization vector
27
-     */
28
-    const IV_DELIMITER = ':iv:';
29
-
30
-    /**
31
-     * @var Base64Encoder
32
-     */
33
-    protected $base64_encoder;
34
-
35
-    /**
36
-     * @var CipherMethod
37
-     */
38
-    protected $cipher_method;
39
-
40
-    /**
41
-     * @var array $digest_methods
42
-     */
43
-    private $digest_methods = [];
44
-
45
-    /**
46
-     * @var EncryptionKeyManagerInterface
47
-     */
48
-    protected $encryption_key_manager;
49
-
50
-    /**
51
-     * @var boolean
52
-     */
53
-    private $openssl_installed;
54
-
55
-    /**
56
-     * @var string
57
-     */
58
-    private $min_php_version;
59
-
60
-    /**
61
-     * @var string
62
-     */
63
-    private $hash_algorithm;
64
-
65
-
66
-    /**
67
-     * To use custom a cipher method and/or encryption keys:
68
-     *  - extend this class
69
-     *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
70
-     *  - pass those to this constructor, like so:
71
-     *
72
-     *      public function __construct(Base64Encoder $base64_encoder) {
73
-     *          parent::__construct(
74
-     *              $base64_encoder,
75
-     *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME)
76
-     *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME)
77
-     *          );
78
-     *      }
79
-     *
80
-     * @param Base64Encoder                      $base64_encoder
81
-     * @param CipherMethod                       $cipher_method
82
-     * @param EncryptionKeyManagerInterface|null $encryption_key_manager
83
-     * @param string                             $min_php_version
84
-     */
85
-    protected function __construct(
86
-        Base64Encoder $base64_encoder,
87
-        CipherMethod $cipher_method,
88
-        EncryptionKeyManagerInterface $encryption_key_manager,
89
-        $min_php_version
90
-    ) {
91
-        $this->base64_encoder         = $base64_encoder;
92
-        $this->cipher_method          = $cipher_method;
93
-        $this->encryption_key_manager = $encryption_key_manager;
94
-        $this->min_php_version        = $min_php_version;
95
-        $this->openssl_installed      = extension_loaded('openssl');
96
-    }
97
-
98
-
99
-    /**
100
-     * @return bool
101
-     */
102
-    public function isCryptographicallySecure()
103
-    {
104
-        return true;
105
-    }
106
-
107
-
108
-    /**
109
-     * @return bool
110
-     */
111
-    public function canUse()
112
-    {
113
-        return $this->openssl_installed && version_compare(PHP_VERSION, $this->min_php_version, '>=');
114
-    }
115
-
116
-
117
-    /**
118
-     * @return string
119
-     */
120
-    public function canUseNotice()
121
-    {
122
-        if (! $this->openssl_installed) {
123
-            return esc_html__(
124
-                'The PHP openssl server extension is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
125
-                'event_espresso'
126
-            );
127
-        }
128
-        if (version_compare(PHP_VERSION, $this->min_php_version, '<')) {
129
-            return sprintf(
130
-                esc_html__(
131
-                    'PHP version %1$s or greater is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
132
-                    'event_espresso'
133
-                ),
134
-                $this->min_php_version
135
-            );
136
-        }
137
-        return sprintf(
138
-            esc_html__('OpenSSL v1 encryption using %1$s is available for use.', 'event_espresso'),
139
-            OpenSSLv1::CIPHER_METHOD
140
-        );
141
-    }
142
-
143
-
144
-    /**
145
-     * Computes the digest hash value using the specified digest method.
146
-     * If that digest method fails to produce a valid hash value,
147
-     * then we'll grab the next digest method and recursively try again until something works.
148
-     *
149
-     * @param string $encryption_key
150
-     * @param string $digest_method
151
-     * @param bool   $return_raw_data
152
-     * @return string
153
-     * @throws RuntimeException
154
-     */
155
-    protected function getDigestHashValue(
156
-        $encryption_key,
157
-        $digest_method = OpenSSL::DEFAULT_DIGEST_METHOD,
158
-        $return_raw_data = false
159
-    ) {
160
-        $digest_hash_value = openssl_digest($encryption_key, $digest_method, $return_raw_data);
161
-        if ($digest_hash_value === false) {
162
-            return $this->getDigestHashValue($this->getDigestMethod());
163
-        }
164
-        return $digest_hash_value;
165
-    }
166
-
167
-
168
-    /**
169
-     * Returns the NEXT element in the $digest_methods array.
170
-     * If the $digest_methods array is empty, then we populate it
171
-     * with the available values returned from openssl_get_md_methods().
172
-     *
173
-     * @return string
174
-     * @throws RuntimeException
175
-     */
176
-    private function getDigestMethod()
177
-    {
178
-        $digest_method = prev($this->digest_methods);
179
-        if (empty($this->digest_methods)) {
180
-            $this->digest_methods = openssl_get_md_methods();
181
-            $digest_method        = end($this->digest_methods);
182
-        }
183
-        if ($digest_method === false) {
184
-            throw new RuntimeException(
185
-                esc_html__(
186
-                    'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
187
-                    'event_espresso'
188
-                )
189
-            );
190
-        }
191
-        return $digest_method;
192
-    }
193
-
194
-
195
-    /**
196
-     * @param string $encryption_key
197
-     * @return int
198
-     */
199
-    protected function calculateHashLength($encryption_key)
200
-    {
201
-        // get existing key length
202
-        $prev_key_length = $this->encryption_key_manager->keyLength();
203
-        // set it to something HUGE
204
-        $this->encryption_key_manager->setKeyLength(512);
205
-        // generate a new weak key, which should just be a really long random string
206
-        $test_text = $this->encryption_key_manager->generateEncryptionKey(false);
207
-        // generate a hash using our test string and our real $encryption_key
208
-        $hash = hash_hmac($this->getHashAlgorithm(), $test_text, $encryption_key, true);
209
-        // reset key length back to original value
210
-        $this->encryption_key_manager->setKeyLength($prev_key_length);
211
-        // return the length of the hash
212
-        return strlen($hash);
213
-    }
214
-
215
-
216
-    /**
217
-     * @return string
218
-     */
219
-    protected function getHashAlgorithm()
220
-    {
221
-        if (! $this->hash_algorithm) {
222
-            // get installed hashing algorithms
223
-            $hash_algorithms = hash_algos();
224
-            // filter array for "sha" algorithms
225
-            $hash_algorithms = preg_grep('/^sha\d{3}$/i', $hash_algorithms);
226
-            // if no sha algorithms are installed, then just use md5
227
-            if (empty($hash_algorithms)) {
228
-                $this->hash_algorithm = 'md5';
229
-                return $this->hash_algorithm;
230
-            }
231
-            // sort ascending using "natural ordering"
232
-            sort($hash_algorithms, SORT_NATURAL);
233
-            // return last item from array, which should be the strongest installed sha hash
234
-            $this->hash_algorithm = array_pop($hash_algorithms);
235
-        }
236
-        return $this->hash_algorithm;
237
-    }
238
-
239
-
240
-    /**
241
-     * @param string $encrypted_text
242
-     * @throws RuntimeException
243
-     */
244
-    protected function validateEncryption($encrypted_text)
245
-    {
246
-        if ($encrypted_text === false) {
247
-            throw new RuntimeException(
248
-                sprintf(
249
-                    esc_html__('The following error occurred during OpenSSL encryption: %1$s', 'event_espresso'),
250
-                    $this->getOpenSslError()
251
-                )
252
-            );
253
-        }
254
-    }
255
-
256
-
257
-    /**
258
-     * @return false|string
259
-     */
260
-    private function getOpenSslError()
261
-    {
262
-        $error = openssl_error_string();
263
-        return $error ?: esc_html__('Unknown Error', 'event_espresso');
264
-    }
265
-
266
-
267
-    /**
268
-     * @param string $encrypted_text
269
-     * @throws RuntimeException
270
-     */
271
-    protected function validateDecryption($encrypted_text)
272
-    {
273
-        if ($encrypted_text === false) {
274
-            throw new RuntimeException(
275
-                sprintf(
276
-                    esc_html__('OpenSSL decryption failed for the following reason: %1$s', 'event_espresso'),
277
-                    $this->getOpenSslError()
278
-                )
279
-            );
280
-        }
281
-    }
20
+	/**
21
+	 * the default OPENSSL digest method to use
22
+	 */
23
+	const DEFAULT_DIGEST_METHOD = 'sha512';
24
+
25
+	/**
26
+	 * separates the encrypted text from the initialization vector
27
+	 */
28
+	const IV_DELIMITER = ':iv:';
29
+
30
+	/**
31
+	 * @var Base64Encoder
32
+	 */
33
+	protected $base64_encoder;
34
+
35
+	/**
36
+	 * @var CipherMethod
37
+	 */
38
+	protected $cipher_method;
39
+
40
+	/**
41
+	 * @var array $digest_methods
42
+	 */
43
+	private $digest_methods = [];
44
+
45
+	/**
46
+	 * @var EncryptionKeyManagerInterface
47
+	 */
48
+	protected $encryption_key_manager;
49
+
50
+	/**
51
+	 * @var boolean
52
+	 */
53
+	private $openssl_installed;
54
+
55
+	/**
56
+	 * @var string
57
+	 */
58
+	private $min_php_version;
59
+
60
+	/**
61
+	 * @var string
62
+	 */
63
+	private $hash_algorithm;
64
+
65
+
66
+	/**
67
+	 * To use custom a cipher method and/or encryption keys:
68
+	 *  - extend this class
69
+	 *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
70
+	 *  - pass those to this constructor, like so:
71
+	 *
72
+	 *      public function __construct(Base64Encoder $base64_encoder) {
73
+	 *          parent::__construct(
74
+	 *              $base64_encoder,
75
+	 *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME)
76
+	 *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME)
77
+	 *          );
78
+	 *      }
79
+	 *
80
+	 * @param Base64Encoder                      $base64_encoder
81
+	 * @param CipherMethod                       $cipher_method
82
+	 * @param EncryptionKeyManagerInterface|null $encryption_key_manager
83
+	 * @param string                             $min_php_version
84
+	 */
85
+	protected function __construct(
86
+		Base64Encoder $base64_encoder,
87
+		CipherMethod $cipher_method,
88
+		EncryptionKeyManagerInterface $encryption_key_manager,
89
+		$min_php_version
90
+	) {
91
+		$this->base64_encoder         = $base64_encoder;
92
+		$this->cipher_method          = $cipher_method;
93
+		$this->encryption_key_manager = $encryption_key_manager;
94
+		$this->min_php_version        = $min_php_version;
95
+		$this->openssl_installed      = extension_loaded('openssl');
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return bool
101
+	 */
102
+	public function isCryptographicallySecure()
103
+	{
104
+		return true;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return bool
110
+	 */
111
+	public function canUse()
112
+	{
113
+		return $this->openssl_installed && version_compare(PHP_VERSION, $this->min_php_version, '>=');
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function canUseNotice()
121
+	{
122
+		if (! $this->openssl_installed) {
123
+			return esc_html__(
124
+				'The PHP openssl server extension is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
125
+				'event_espresso'
126
+			);
127
+		}
128
+		if (version_compare(PHP_VERSION, $this->min_php_version, '<')) {
129
+			return sprintf(
130
+				esc_html__(
131
+					'PHP version %1$s or greater is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
132
+					'event_espresso'
133
+				),
134
+				$this->min_php_version
135
+			);
136
+		}
137
+		return sprintf(
138
+			esc_html__('OpenSSL v1 encryption using %1$s is available for use.', 'event_espresso'),
139
+			OpenSSLv1::CIPHER_METHOD
140
+		);
141
+	}
142
+
143
+
144
+	/**
145
+	 * Computes the digest hash value using the specified digest method.
146
+	 * If that digest method fails to produce a valid hash value,
147
+	 * then we'll grab the next digest method and recursively try again until something works.
148
+	 *
149
+	 * @param string $encryption_key
150
+	 * @param string $digest_method
151
+	 * @param bool   $return_raw_data
152
+	 * @return string
153
+	 * @throws RuntimeException
154
+	 */
155
+	protected function getDigestHashValue(
156
+		$encryption_key,
157
+		$digest_method = OpenSSL::DEFAULT_DIGEST_METHOD,
158
+		$return_raw_data = false
159
+	) {
160
+		$digest_hash_value = openssl_digest($encryption_key, $digest_method, $return_raw_data);
161
+		if ($digest_hash_value === false) {
162
+			return $this->getDigestHashValue($this->getDigestMethod());
163
+		}
164
+		return $digest_hash_value;
165
+	}
166
+
167
+
168
+	/**
169
+	 * Returns the NEXT element in the $digest_methods array.
170
+	 * If the $digest_methods array is empty, then we populate it
171
+	 * with the available values returned from openssl_get_md_methods().
172
+	 *
173
+	 * @return string
174
+	 * @throws RuntimeException
175
+	 */
176
+	private function getDigestMethod()
177
+	{
178
+		$digest_method = prev($this->digest_methods);
179
+		if (empty($this->digest_methods)) {
180
+			$this->digest_methods = openssl_get_md_methods();
181
+			$digest_method        = end($this->digest_methods);
182
+		}
183
+		if ($digest_method === false) {
184
+			throw new RuntimeException(
185
+				esc_html__(
186
+					'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
187
+					'event_espresso'
188
+				)
189
+			);
190
+		}
191
+		return $digest_method;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param string $encryption_key
197
+	 * @return int
198
+	 */
199
+	protected function calculateHashLength($encryption_key)
200
+	{
201
+		// get existing key length
202
+		$prev_key_length = $this->encryption_key_manager->keyLength();
203
+		// set it to something HUGE
204
+		$this->encryption_key_manager->setKeyLength(512);
205
+		// generate a new weak key, which should just be a really long random string
206
+		$test_text = $this->encryption_key_manager->generateEncryptionKey(false);
207
+		// generate a hash using our test string and our real $encryption_key
208
+		$hash = hash_hmac($this->getHashAlgorithm(), $test_text, $encryption_key, true);
209
+		// reset key length back to original value
210
+		$this->encryption_key_manager->setKeyLength($prev_key_length);
211
+		// return the length of the hash
212
+		return strlen($hash);
213
+	}
214
+
215
+
216
+	/**
217
+	 * @return string
218
+	 */
219
+	protected function getHashAlgorithm()
220
+	{
221
+		if (! $this->hash_algorithm) {
222
+			// get installed hashing algorithms
223
+			$hash_algorithms = hash_algos();
224
+			// filter array for "sha" algorithms
225
+			$hash_algorithms = preg_grep('/^sha\d{3}$/i', $hash_algorithms);
226
+			// if no sha algorithms are installed, then just use md5
227
+			if (empty($hash_algorithms)) {
228
+				$this->hash_algorithm = 'md5';
229
+				return $this->hash_algorithm;
230
+			}
231
+			// sort ascending using "natural ordering"
232
+			sort($hash_algorithms, SORT_NATURAL);
233
+			// return last item from array, which should be the strongest installed sha hash
234
+			$this->hash_algorithm = array_pop($hash_algorithms);
235
+		}
236
+		return $this->hash_algorithm;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param string $encrypted_text
242
+	 * @throws RuntimeException
243
+	 */
244
+	protected function validateEncryption($encrypted_text)
245
+	{
246
+		if ($encrypted_text === false) {
247
+			throw new RuntimeException(
248
+				sprintf(
249
+					esc_html__('The following error occurred during OpenSSL encryption: %1$s', 'event_espresso'),
250
+					$this->getOpenSslError()
251
+				)
252
+			);
253
+		}
254
+	}
255
+
256
+
257
+	/**
258
+	 * @return false|string
259
+	 */
260
+	private function getOpenSslError()
261
+	{
262
+		$error = openssl_error_string();
263
+		return $error ?: esc_html__('Unknown Error', 'event_espresso');
264
+	}
265
+
266
+
267
+	/**
268
+	 * @param string $encrypted_text
269
+	 * @throws RuntimeException
270
+	 */
271
+	protected function validateDecryption($encrypted_text)
272
+	{
273
+		if ($encrypted_text === false) {
274
+			throw new RuntimeException(
275
+				sprintf(
276
+					esc_html__('OpenSSL decryption failed for the following reason: %1$s', 'event_espresso'),
277
+					$this->getOpenSslError()
278
+				)
279
+			);
280
+		}
281
+	}
282 282
 }
Please login to merge, or discard this patch.
core/services/json/JsonDataNodeHandler.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
                 if ($child_node instanceof PrimaryJsonDataNode || $depth > 512) {
79 79
                     continue;
80 80
                 }
81
-                $data[ $child_node_name ] = $child_node instanceof JsonDataNode
81
+                $data[$child_node_name] = $child_node instanceof JsonDataNode
82 82
                     // feed data node back into this function
83 83
                     ? $this->initializeDataNodes($child_node, $depth)
84 84
                     // or assign data directly
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
      */
95 95
     public function printDataNode()
96 96
     {
97
-        if (!$this->primary_data_node instanceof PrimaryJsonDataNode) {
97
+        if ( ! $this->primary_data_node instanceof PrimaryJsonDataNode) {
98 98
             return;
99 99
         }
100 100
         // validate that the domain, node name, and target script are set
101 101
         $domain = $this->primary_data_node->domain();
102 102
         $node_name = $this->primary_data_node->nodeName();
103
-        $data_valid =  $this->validator->validateCriticalProperty($domain, 'domain route', false)
103
+        $data_valid = $this->validator->validateCriticalProperty($domain, 'domain route', false)
104 104
                        && $this->validator->validateCriticalProperty($node_name, 'node name', false);
105
-        if (! $data_valid) {
105
+        if ( ! $data_valid) {
106 106
             return;
107 107
         }
108 108
         // initialize and parse data from primary data node
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             $this->setPrimaryDataNode($data_node);
133 133
         }
134 134
         // and don't allow other nodes to be set until a primary is set
135
-        if (! $this->primary_data_node instanceof PrimaryJsonDataNode) {
135
+        if ( ! $this->primary_data_node instanceof PrimaryJsonDataNode) {
136 136
             throw new DomainException(
137 137
                 esc_html__(
138 138
                     'A PrimaryJsonDataNode needs to be set before data nodes can be added.',
Please login to merge, or discard this patch.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -17,127 +17,127 @@
 block discarded – undo
17 17
  */
18 18
 class JsonDataNodeHandler
19 19
 {
20
-    /**
21
-     * @var PrimaryJsonDataNode $primary_data_node
22
-     */
23
-    private $primary_data_node;
24
-
25
-    /**
26
-     * @var JsonDataNodeValidator $validator
27
-     */
28
-    private $validator;
29
-
30
-
31
-    /**
32
-     * @param JsonDataNodeValidator $validator
33
-     */
34
-    public function __construct(JsonDataNodeValidator $validator)
35
-    {
36
-        $this->validator = $validator;
37
-    }
38
-
39
-
40
-    /**
41
-     * @param JsonDataNode $data_node
42
-     * @throws DomainException
43
-     */
44
-    public function addDataNode(JsonDataNode $data_node)
45
-    {
46
-        if ($data_node->isNotInitialized()) {
47
-            $this->validatePrimaryDataNode($data_node);
48
-            $this->primary_data_node->addDataNode($data_node);
49
-        }
50
-    }
51
-
52
-
53
-    /**
54
-     * @param PrimaryJsonDataNode $primary_data_node
55
-     */
56
-    public function setPrimaryDataNode(PrimaryJsonDataNode $primary_data_node)
57
-    {
58
-        $this->primary_data_node = $primary_data_node;
59
-    }
60
-
61
-
62
-    /**
63
-     * @param JsonDataNode $data_node
64
-     * @param int                $depth
65
-     * @return array
66
-     */
67
-    private function initializeDataNodes(JsonDataNode $data_node, int $depth = 0): array
68
-    {
69
-        $depth++;
70
-        $data = [];
71
-        // initialize the data node if not done already
72
-        if ($data_node->isNotInitialized()) {
73
-            $data_node->initialize();
74
-            // loop thru the data node's data array
75
-            foreach ($data_node->data(true) as $child_node_name => $child_node) {
76
-                // don't parse node if it's the primary, OR if depth has exceeded wp_json_encode() limit
77
-                if ($child_node instanceof PrimaryJsonDataNode || $depth > 512) {
78
-                    continue;
79
-                }
80
-                $data[ $child_node_name ] = $child_node instanceof JsonDataNode
81
-                    // feed data node back into this function
82
-                    ? $this->initializeDataNodes($child_node, $depth)
83
-                    // or assign data directly
84
-                    : $child_node;
85
-            }
86
-        }
87
-        return $data;
88
-    }
89
-
90
-
91
-    /**
92
-     * @throws DomainException
93
-     */
94
-    public function printDataNode()
95
-    {
96
-        if (!$this->primary_data_node instanceof PrimaryJsonDataNode) {
97
-            return;
98
-        }
99
-        // validate that the domain, node name, and target script are set
100
-        $domain = $this->primary_data_node->domain();
101
-        $node_name = $this->primary_data_node->nodeName();
102
-        $data_valid =  $this->validator->validateCriticalProperty($domain, 'domain route', false)
103
-                       && $this->validator->validateCriticalProperty($node_name, 'node name', false);
104
-        if (! $data_valid) {
105
-            return;
106
-        }
107
-        // initialize and parse data from primary data node
108
-        $data = $this->initializeDataNodes($this->primary_data_node);
109
-        // this prepends the current domain "use case" to the front of the array
110
-        $data = ['domain' => $domain] + $data;
111
-        // add legacy i18n strings
112
-        $data['eei18n'] = EE_Registry::sanitize_i18n_js_strings();
113
-        // and finally, print the JSON encoded data to the DOM
114
-        printf(
115
-            "<script type='text/javascript' id='%s'>\nvar %s = %s\n</script>\n",
116
-            $node_name,
117
-            $node_name,
118
-            json_encode($data)
119
-        );
120
-    }
121
-
122
-
123
-    /**
124
-     * @param JsonDataNode $data_node
125
-     * @throws DomainException
126
-     */
127
-    private function validatePrimaryDataNode(JsonDataNode $data_node)
128
-    {
129
-        // set primary data node if that's what the incoming node is
130
-        if ($data_node instanceof PrimaryJsonDataNode) {
131
-            $this->setPrimaryDataNode($data_node);
132
-        }
133
-        // and don't allow other nodes to be set until a primary is set
134
-        if (! $this->primary_data_node instanceof PrimaryJsonDataNode) {
135
-            throw new DomainException(
136
-                esc_html__(
137
-                    'A PrimaryJsonDataNode needs to be set before data nodes can be added.',
138
-                    'event_espresso'
139
-                )
140
-            );
141
-        }
142
-    }
20
+	/**
21
+	 * @var PrimaryJsonDataNode $primary_data_node
22
+	 */
23
+	private $primary_data_node;
24
+
25
+	/**
26
+	 * @var JsonDataNodeValidator $validator
27
+	 */
28
+	private $validator;
29
+
30
+
31
+	/**
32
+	 * @param JsonDataNodeValidator $validator
33
+	 */
34
+	public function __construct(JsonDataNodeValidator $validator)
35
+	{
36
+		$this->validator = $validator;
37
+	}
38
+
39
+
40
+	/**
41
+	 * @param JsonDataNode $data_node
42
+	 * @throws DomainException
43
+	 */
44
+	public function addDataNode(JsonDataNode $data_node)
45
+	{
46
+		if ($data_node->isNotInitialized()) {
47
+			$this->validatePrimaryDataNode($data_node);
48
+			$this->primary_data_node->addDataNode($data_node);
49
+		}
50
+	}
51
+
52
+
53
+	/**
54
+	 * @param PrimaryJsonDataNode $primary_data_node
55
+	 */
56
+	public function setPrimaryDataNode(PrimaryJsonDataNode $primary_data_node)
57
+	{
58
+		$this->primary_data_node = $primary_data_node;
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param JsonDataNode $data_node
64
+	 * @param int                $depth
65
+	 * @return array
66
+	 */
67
+	private function initializeDataNodes(JsonDataNode $data_node, int $depth = 0): array
68
+	{
69
+		$depth++;
70
+		$data = [];
71
+		// initialize the data node if not done already
72
+		if ($data_node->isNotInitialized()) {
73
+			$data_node->initialize();
74
+			// loop thru the data node's data array
75
+			foreach ($data_node->data(true) as $child_node_name => $child_node) {
76
+				// don't parse node if it's the primary, OR if depth has exceeded wp_json_encode() limit
77
+				if ($child_node instanceof PrimaryJsonDataNode || $depth > 512) {
78
+					continue;
79
+				}
80
+				$data[ $child_node_name ] = $child_node instanceof JsonDataNode
81
+					// feed data node back into this function
82
+					? $this->initializeDataNodes($child_node, $depth)
83
+					// or assign data directly
84
+					: $child_node;
85
+			}
86
+		}
87
+		return $data;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @throws DomainException
93
+	 */
94
+	public function printDataNode()
95
+	{
96
+		if (!$this->primary_data_node instanceof PrimaryJsonDataNode) {
97
+			return;
98
+		}
99
+		// validate that the domain, node name, and target script are set
100
+		$domain = $this->primary_data_node->domain();
101
+		$node_name = $this->primary_data_node->nodeName();
102
+		$data_valid =  $this->validator->validateCriticalProperty($domain, 'domain route', false)
103
+					   && $this->validator->validateCriticalProperty($node_name, 'node name', false);
104
+		if (! $data_valid) {
105
+			return;
106
+		}
107
+		// initialize and parse data from primary data node
108
+		$data = $this->initializeDataNodes($this->primary_data_node);
109
+		// this prepends the current domain "use case" to the front of the array
110
+		$data = ['domain' => $domain] + $data;
111
+		// add legacy i18n strings
112
+		$data['eei18n'] = EE_Registry::sanitize_i18n_js_strings();
113
+		// and finally, print the JSON encoded data to the DOM
114
+		printf(
115
+			"<script type='text/javascript' id='%s'>\nvar %s = %s\n</script>\n",
116
+			$node_name,
117
+			$node_name,
118
+			json_encode($data)
119
+		);
120
+	}
121
+
122
+
123
+	/**
124
+	 * @param JsonDataNode $data_node
125
+	 * @throws DomainException
126
+	 */
127
+	private function validatePrimaryDataNode(JsonDataNode $data_node)
128
+	{
129
+		// set primary data node if that's what the incoming node is
130
+		if ($data_node instanceof PrimaryJsonDataNode) {
131
+			$this->setPrimaryDataNode($data_node);
132
+		}
133
+		// and don't allow other nodes to be set until a primary is set
134
+		if (! $this->primary_data_node instanceof PrimaryJsonDataNode) {
135
+			throw new DomainException(
136
+				esc_html__(
137
+					'A PrimaryJsonDataNode needs to be set before data nodes can be added.',
138
+					'event_espresso'
139
+				)
140
+			);
141
+		}
142
+	}
143 143
 }
Please login to merge, or discard this patch.
core/services/encryption/openssl/OpenSSLv1.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@
 block discarded – undo
122 122
         // hash the raw encrypted text
123 123
         $hmac = hash_hmac($this->getHashAlgorithm(), $encrypted_text, $key, true);
124 124
         // concatenate everything into one big string and encode it again
125
-        return $this->base64_encoder->encodeString($iv . $hmac . $encrypted_text);
125
+        return $this->base64_encoder->encodeString($iv.$hmac.$encrypted_text);
126 126
     }
127 127
 
128 128
 
Please login to merge, or discard this patch.
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -17,155 +17,155 @@
 block discarded – undo
17 17
  */
18 18
 class OpenSSLv1 extends OpenSSL
19 19
 {
20
-    /**
21
-     * name used for a default encryption key in case no others are set
22
-     */
23
-    const DEFAULT_ENCRYPTION_KEY_ID = 'default_openssl_v1_key';
20
+	/**
21
+	 * name used for a default encryption key in case no others are set
22
+	 */
23
+	const DEFAULT_ENCRYPTION_KEY_ID = 'default_openssl_v1_key';
24 24
 
25
-    /**
26
-     * name used for saving encryption keys to the wp_options table
27
-     */
28
-    const ENCRYPTION_KEYS_OPTION_NAME = 'ee_openssl_v1_encryption_keys';
25
+	/**
26
+	 * name used for saving encryption keys to the wp_options table
27
+	 */
28
+	const ENCRYPTION_KEYS_OPTION_NAME = 'ee_openssl_v1_encryption_keys';
29 29
 
30
-    /**
31
-     * the OPENSSL cipher method used
32
-     */
33
-    const CIPHER_METHOD = 'aes-128-cbc';
30
+	/**
31
+	 * the OPENSSL cipher method used
32
+	 */
33
+	const CIPHER_METHOD = 'aes-128-cbc';
34 34
 
35
-    /**
36
-     * WP "options_name" used to store a verified available cipher method
37
-     */
38
-    const CIPHER_METHOD_OPTION_NAME = 'ee_openssl_v1_cipher_method';
35
+	/**
36
+	 * WP "options_name" used to store a verified available cipher method
37
+	 */
38
+	const CIPHER_METHOD_OPTION_NAME = 'ee_openssl_v1_cipher_method';
39 39
 
40 40
 
41
-    /**
42
-     * To use custom a cipher method and/or encryption keys and/or minimum PHP version:
43
-     *  - extend this class
44
-     *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
45
-     *  - pass those to this constructor, like so:
46
-     *
47
-     *      public function __construct(Base64Encoder $base64_encoder) {
48
-     *          parent::__construct(
49
-     *              $base64_encoder,
50
-     *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME),
51
-     *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME),
52
-     *              '7.1.0'
53
-     *          );
54
-     *      }
55
-     *
56
-     * @param Base64Encoder                      $base64_encoder
57
-     * @param CipherMethod|null                  $cipher_method
58
-     * @param EncryptionKeyManagerInterface|null $encryption_key_manager
59
-     * @param string                             $min_php_version defaults to 5.3.0 (when openssl added)
60
-     */
61
-    public function __construct(
62
-        Base64Encoder $base64_encoder,
63
-        CipherMethod $cipher_method = null,
64
-        EncryptionKeyManagerInterface $encryption_key_manager = null,
65
-        $min_php_version = '5.3.0'
66
-    ) {
67
-        parent::__construct(
68
-            $base64_encoder,
69
-            $cipher_method instanceof CipherMethod
70
-                ? $cipher_method
71
-                : new CipherMethod(
72
-                    OpenSSLv1::CIPHER_METHOD,
73
-                    OpenSSLv1::CIPHER_METHOD_OPTION_NAME
74
-                ),
75
-            $encryption_key_manager instanceof EncryptionKeyManager
76
-                ? $encryption_key_manager
77
-                : new EncryptionKeyManager(
78
-                    $base64_encoder,
79
-                    OpenSSLv1::DEFAULT_ENCRYPTION_KEY_ID,
80
-                    OpenSSLv1::ENCRYPTION_KEYS_OPTION_NAME
81
-                ),
82
-            $min_php_version
83
-        );
84
-    }
41
+	/**
42
+	 * To use custom a cipher method and/or encryption keys and/or minimum PHP version:
43
+	 *  - extend this class
44
+	 *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
45
+	 *  - pass those to this constructor, like so:
46
+	 *
47
+	 *      public function __construct(Base64Encoder $base64_encoder) {
48
+	 *          parent::__construct(
49
+	 *              $base64_encoder,
50
+	 *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME),
51
+	 *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME),
52
+	 *              '7.1.0'
53
+	 *          );
54
+	 *      }
55
+	 *
56
+	 * @param Base64Encoder                      $base64_encoder
57
+	 * @param CipherMethod|null                  $cipher_method
58
+	 * @param EncryptionKeyManagerInterface|null $encryption_key_manager
59
+	 * @param string                             $min_php_version defaults to 5.3.0 (when openssl added)
60
+	 */
61
+	public function __construct(
62
+		Base64Encoder $base64_encoder,
63
+		CipherMethod $cipher_method = null,
64
+		EncryptionKeyManagerInterface $encryption_key_manager = null,
65
+		$min_php_version = '5.3.0'
66
+	) {
67
+		parent::__construct(
68
+			$base64_encoder,
69
+			$cipher_method instanceof CipherMethod
70
+				? $cipher_method
71
+				: new CipherMethod(
72
+					OpenSSLv1::CIPHER_METHOD,
73
+					OpenSSLv1::CIPHER_METHOD_OPTION_NAME
74
+				),
75
+			$encryption_key_manager instanceof EncryptionKeyManager
76
+				? $encryption_key_manager
77
+				: new EncryptionKeyManager(
78
+					$base64_encoder,
79
+					OpenSSLv1::DEFAULT_ENCRYPTION_KEY_ID,
80
+					OpenSSLv1::ENCRYPTION_KEYS_OPTION_NAME
81
+				),
82
+			$min_php_version
83
+		);
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * encrypts data
89
-     *
90
-     * @param string $text_to_encrypt           - the text to be encrypted
91
-     * @param string $encryption_key_identifier - cryptographically secure passphrase. will generate if necessary
92
-     * @return string
93
-     */
94
-    public function encrypt($text_to_encrypt, $encryption_key_identifier = '')
95
-    {
96
-        $cipher_method  = $this->cipher_method->getCipherMethod();
97
-        $encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
98
-        // get initialization vector size
99
-        $iv_length = openssl_cipher_iv_length($cipher_method);
100
-        // generate initialization vector.
101
-        // The second parameter ("crypto_strong") is passed by reference,
102
-        // and is used to determines if the algorithm used was "cryptographically strong"
103
-        // openssl_random_pseudo_bytes() will toggle it to either true or false
104
-        $iv = openssl_random_pseudo_bytes($iv_length, $is_strong);
105
-        if ($iv === false || $is_strong === false) {
106
-            throw new RuntimeException(
107
-                esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
108
-            );
109
-        }
110
-        $key = $this->getDigestHashValue($encryption_key);
111
-        // encrypt it
112
-        $encrypted_text = openssl_encrypt(
113
-            $this->base64_encoder->encodeString($text_to_encrypt), // encode to remove special characters
114
-            $cipher_method,
115
-            $key,
116
-            0,
117
-            $iv
118
-        );
119
-        $this->validateEncryption($encrypted_text);
120
-        $encrypted_text = trim($encrypted_text);
121
-        // hash the raw encrypted text
122
-        $hmac = hash_hmac($this->getHashAlgorithm(), $encrypted_text, $key, true);
123
-        // concatenate everything into one big string and encode it again
124
-        return $this->base64_encoder->encodeString($iv . $hmac . $encrypted_text);
125
-    }
87
+	/**
88
+	 * encrypts data
89
+	 *
90
+	 * @param string $text_to_encrypt           - the text to be encrypted
91
+	 * @param string $encryption_key_identifier - cryptographically secure passphrase. will generate if necessary
92
+	 * @return string
93
+	 */
94
+	public function encrypt($text_to_encrypt, $encryption_key_identifier = '')
95
+	{
96
+		$cipher_method  = $this->cipher_method->getCipherMethod();
97
+		$encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
98
+		// get initialization vector size
99
+		$iv_length = openssl_cipher_iv_length($cipher_method);
100
+		// generate initialization vector.
101
+		// The second parameter ("crypto_strong") is passed by reference,
102
+		// and is used to determines if the algorithm used was "cryptographically strong"
103
+		// openssl_random_pseudo_bytes() will toggle it to either true or false
104
+		$iv = openssl_random_pseudo_bytes($iv_length, $is_strong);
105
+		if ($iv === false || $is_strong === false) {
106
+			throw new RuntimeException(
107
+				esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
108
+			);
109
+		}
110
+		$key = $this->getDigestHashValue($encryption_key);
111
+		// encrypt it
112
+		$encrypted_text = openssl_encrypt(
113
+			$this->base64_encoder->encodeString($text_to_encrypt), // encode to remove special characters
114
+			$cipher_method,
115
+			$key,
116
+			0,
117
+			$iv
118
+		);
119
+		$this->validateEncryption($encrypted_text);
120
+		$encrypted_text = trim($encrypted_text);
121
+		// hash the raw encrypted text
122
+		$hmac = hash_hmac($this->getHashAlgorithm(), $encrypted_text, $key, true);
123
+		// concatenate everything into one big string and encode it again
124
+		return $this->base64_encoder->encodeString($iv . $hmac . $encrypted_text);
125
+	}
126 126
 
127 127
 
128
-    /**
129
-     * decrypts data
130
-     *
131
-     * @param string $encrypted_text            - the text to be decrypted
132
-     * @param string $encryption_key_identifier - cryptographically secure passphrase. will use default if necessary
133
-     * @return string
134
-     */
135
-    public function decrypt($encrypted_text, $encryption_key_identifier = '')
136
-    {
137
-        $cipher_method  = $this->cipher_method->getCipherMethod();
138
-        $encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
139
-        $key            = $this->getDigestHashValue($encryption_key);
140
-        // decode our concatenated string
141
-        $encrypted_text = $this->base64_encoder->decodeString($encrypted_text);
142
-        // get the string lengths used for the hash and iv
143
-        $hash_length = $this->calculateHashLength($encryption_key);
144
-        $iv_length   = openssl_cipher_iv_length($cipher_method);
145
-        // use the above lengths to snip the required values from the decoded string
146
-        $iv                 = substr($encrypted_text, 0, $iv_length);
147
-        $hmac               = substr($encrypted_text, $iv_length, $hash_length);
148
-        $encrypted_text_raw = substr($encrypted_text, $iv_length + $hash_length);
149
-        // rehash the original raw encrypted text
150
-        $rehash_mac = hash_hmac($this->getHashAlgorithm(), $encrypted_text_raw, $key, true);
151
-        // timing attack safe comparison to determine if anything has changed
152
-        if (hash_equals($hmac, $rehash_mac)) {
153
-            // looks good, decrypt it, trim it, and return it
154
-            $decrypted_text = openssl_decrypt(
155
-                $encrypted_text_raw,
156
-                $this->cipher_method->getCipherMethod(),
157
-                $key,
158
-                0,
159
-                $iv
160
-            );
161
-            $this->validateDecryption($decrypted_text);
162
-            return trim($this->base64_encoder->decodeString($decrypted_text));
163
-        }
164
-        throw new RuntimeException(
165
-            esc_html__(
166
-                'Decryption failed because a hash comparison of the original text and the decrypted text was not the same, meaning something in the system or the encrypted data has changed.',
167
-                'event_espresso'
168
-            )
169
-        );
170
-    }
128
+	/**
129
+	 * decrypts data
130
+	 *
131
+	 * @param string $encrypted_text            - the text to be decrypted
132
+	 * @param string $encryption_key_identifier - cryptographically secure passphrase. will use default if necessary
133
+	 * @return string
134
+	 */
135
+	public function decrypt($encrypted_text, $encryption_key_identifier = '')
136
+	{
137
+		$cipher_method  = $this->cipher_method->getCipherMethod();
138
+		$encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
139
+		$key            = $this->getDigestHashValue($encryption_key);
140
+		// decode our concatenated string
141
+		$encrypted_text = $this->base64_encoder->decodeString($encrypted_text);
142
+		// get the string lengths used for the hash and iv
143
+		$hash_length = $this->calculateHashLength($encryption_key);
144
+		$iv_length   = openssl_cipher_iv_length($cipher_method);
145
+		// use the above lengths to snip the required values from the decoded string
146
+		$iv                 = substr($encrypted_text, 0, $iv_length);
147
+		$hmac               = substr($encrypted_text, $iv_length, $hash_length);
148
+		$encrypted_text_raw = substr($encrypted_text, $iv_length + $hash_length);
149
+		// rehash the original raw encrypted text
150
+		$rehash_mac = hash_hmac($this->getHashAlgorithm(), $encrypted_text_raw, $key, true);
151
+		// timing attack safe comparison to determine if anything has changed
152
+		if (hash_equals($hmac, $rehash_mac)) {
153
+			// looks good, decrypt it, trim it, and return it
154
+			$decrypted_text = openssl_decrypt(
155
+				$encrypted_text_raw,
156
+				$this->cipher_method->getCipherMethod(),
157
+				$key,
158
+				0,
159
+				$iv
160
+			);
161
+			$this->validateDecryption($decrypted_text);
162
+			return trim($this->base64_encoder->decodeString($decrypted_text));
163
+		}
164
+		throw new RuntimeException(
165
+			esc_html__(
166
+				'Decryption failed because a hash comparison of the original text and the decrypted text was not the same, meaning something in the system or the encrypted data has changed.',
167
+				'event_espresso'
168
+			)
169
+		);
170
+	}
171 171
 }
Please login to merge, or discard this patch.