@@ -70,7 +70,7 @@ |
||
70 | 70 | $text .= '<span class="drk-grey-text">'; |
71 | 71 | $text .= '<span class="dashicons dashicons-calendar"></span>'; |
72 | 72 | $text .= $datetime->name(); |
73 | - $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
73 | + $text .= ' ( '.$datetime->start_date().' )'; |
|
74 | 74 | $text .= '</span></h3>'; |
75 | 75 | } |
76 | 76 | } |
@@ -22,57 +22,57 @@ |
||
22 | 22 | */ |
23 | 23 | class DateFilterHeader extends AdminPageHeaderDecorator |
24 | 24 | { |
25 | - /** |
|
26 | - * @var EEM_Datetime $datetime_model |
|
27 | - */ |
|
28 | - private $datetime_model; |
|
25 | + /** |
|
26 | + * @var EEM_Datetime $datetime_model |
|
27 | + */ |
|
28 | + private $datetime_model; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * DateFilterHeader constructor. |
|
33 | - * |
|
34 | - * @param RequestInterface $request |
|
35 | - * @param EEM_Datetime $datetime_model |
|
36 | - */ |
|
37 | - public function __construct(RequestInterface $request, EEM_Datetime $datetime_model) |
|
38 | - { |
|
39 | - parent::__construct($request); |
|
40 | - $this->datetime_model = $datetime_model; |
|
41 | - } |
|
31 | + /** |
|
32 | + * DateFilterHeader constructor. |
|
33 | + * |
|
34 | + * @param RequestInterface $request |
|
35 | + * @param EEM_Datetime $datetime_model |
|
36 | + */ |
|
37 | + public function __construct(RequestInterface $request, EEM_Datetime $datetime_model) |
|
38 | + { |
|
39 | + parent::__construct($request); |
|
40 | + $this->datetime_model = $datetime_model; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param string $text |
|
46 | - * @return string |
|
47 | - * @throws EE_Error |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws ReflectionException |
|
52 | - * @since 4.10.2.p |
|
53 | - */ |
|
54 | - public function getHeaderText($text = '') |
|
55 | - { |
|
56 | - $DTT_ID = $this->request->getRequestParam('DTT_ID'); |
|
57 | - $DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID, 'int'); |
|
58 | - if ($DTT_ID) { |
|
59 | - $datetime = $this->datetime_model->get_one_by_ID($DTT_ID); |
|
60 | - if ($datetime instanceof EE_Datetime && $text !== '') { |
|
61 | - // remove the closing h3 heading tag if it exists |
|
62 | - $text = str_replace( |
|
63 | - '</h3>', |
|
64 | - '', |
|
65 | - $text |
|
66 | - ); |
|
67 | - $text .= ' '; |
|
68 | - $text .= '<span class="drk-grey-text">'; |
|
69 | - $text .= '<span class="dashicons dashicons-calendar"></span>'; |
|
70 | - $text .= $datetime->name(); |
|
71 | - $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
72 | - $text .= '</span></h3>'; |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @param string $text |
|
46 | + * @return string |
|
47 | + * @throws EE_Error |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws ReflectionException |
|
52 | + * @since 4.10.2.p |
|
53 | + */ |
|
54 | + public function getHeaderText($text = '') |
|
55 | + { |
|
56 | + $DTT_ID = $this->request->getRequestParam('DTT_ID'); |
|
57 | + $DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID, 'int'); |
|
58 | + if ($DTT_ID) { |
|
59 | + $datetime = $this->datetime_model->get_one_by_ID($DTT_ID); |
|
60 | + if ($datetime instanceof EE_Datetime && $text !== '') { |
|
61 | + // remove the closing h3 heading tag if it exists |
|
62 | + $text = str_replace( |
|
63 | + '</h3>', |
|
64 | + '', |
|
65 | + $text |
|
66 | + ); |
|
67 | + $text .= ' '; |
|
68 | + $text .= '<span class="drk-grey-text">'; |
|
69 | + $text .= '<span class="dashicons dashicons-calendar"></span>'; |
|
70 | + $text .= $datetime->name(); |
|
71 | + $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
72 | + $text .= '</span></h3>'; |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - return $text; |
|
77 | - } |
|
76 | + return $text; |
|
77 | + } |
|
78 | 78 | } |
@@ -59,13 +59,13 @@ |
||
59 | 59 | 'event_espresso' |
60 | 60 | ), |
61 | 61 | '<h3 style="line-height:1.5em;">', |
62 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
62 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
63 | 63 | array( |
64 | 64 | 'action' => 'edit_attendee', |
65 | 65 | 'post' => $ATT_ID, |
66 | 66 | ), |
67 | 67 | REG_ADMIN_URL |
68 | - ) . '">' . $attendee->full_name() . '</a>', |
|
68 | + ).'">'.$attendee->full_name().'</a>', |
|
69 | 69 | '</h3>' |
70 | 70 | ); |
71 | 71 | } |
@@ -19,55 +19,55 @@ |
||
19 | 19 | */ |
20 | 20 | class AttendeeFilterHeader extends AdminPageHeaderDecorator |
21 | 21 | { |
22 | - /** |
|
23 | - * @var EEM_Attendee $attendee_model |
|
24 | - */ |
|
25 | - private $attendee_model; |
|
22 | + /** |
|
23 | + * @var EEM_Attendee $attendee_model |
|
24 | + */ |
|
25 | + private $attendee_model; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * AttendeeFilterHeader constructor. |
|
30 | - * |
|
31 | - * @param RequestInterface $request |
|
32 | - * @param EEM_Attendee $attendee_model |
|
33 | - */ |
|
34 | - public function __construct(RequestInterface $request, EEM_Attendee $attendee_model) |
|
35 | - { |
|
36 | - parent::__construct($request); |
|
37 | - $this->attendee_model = $attendee_model; |
|
38 | - } |
|
28 | + /** |
|
29 | + * AttendeeFilterHeader constructor. |
|
30 | + * |
|
31 | + * @param RequestInterface $request |
|
32 | + * @param EEM_Attendee $attendee_model |
|
33 | + */ |
|
34 | + public function __construct(RequestInterface $request, EEM_Attendee $attendee_model) |
|
35 | + { |
|
36 | + parent::__construct($request); |
|
37 | + $this->attendee_model = $attendee_model; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $text |
|
43 | - * @return string |
|
44 | - * @throws EE_Error |
|
45 | - * @since 4.10.2.p |
|
46 | - */ |
|
47 | - public function getHeaderText($text = '') |
|
48 | - { |
|
49 | - $ATT_ID = $this->request->getRequestParam('ATT_ID'); |
|
50 | - $ATT_ID = $this->request->getRequestParam('attendee_id', $ATT_ID, 'int'); |
|
51 | - if ($ATT_ID) { |
|
52 | - $attendee = $this->attendee_model->get_one_by_ID($ATT_ID); |
|
53 | - if ($attendee instanceof EE_Attendee) { |
|
54 | - $text .= sprintf( |
|
55 | - esc_html__( |
|
56 | - '%1$s Viewing registrations for %2$s%3$s', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - '<h3 style="line-height:1.5em;">', |
|
60 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
61 | - array( |
|
62 | - 'action' => 'edit_attendee', |
|
63 | - 'post' => $ATT_ID, |
|
64 | - ), |
|
65 | - REG_ADMIN_URL |
|
66 | - ) . '">' . $attendee->full_name() . '</a>', |
|
67 | - '</h3>' |
|
68 | - ); |
|
69 | - } |
|
70 | - } |
|
71 | - return $text; |
|
72 | - } |
|
41 | + /** |
|
42 | + * @param string $text |
|
43 | + * @return string |
|
44 | + * @throws EE_Error |
|
45 | + * @since 4.10.2.p |
|
46 | + */ |
|
47 | + public function getHeaderText($text = '') |
|
48 | + { |
|
49 | + $ATT_ID = $this->request->getRequestParam('ATT_ID'); |
|
50 | + $ATT_ID = $this->request->getRequestParam('attendee_id', $ATT_ID, 'int'); |
|
51 | + if ($ATT_ID) { |
|
52 | + $attendee = $this->attendee_model->get_one_by_ID($ATT_ID); |
|
53 | + if ($attendee instanceof EE_Attendee) { |
|
54 | + $text .= sprintf( |
|
55 | + esc_html__( |
|
56 | + '%1$s Viewing registrations for %2$s%3$s', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + '<h3 style="line-height:1.5em;">', |
|
60 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
61 | + array( |
|
62 | + 'action' => 'edit_attendee', |
|
63 | + 'post' => $ATT_ID, |
|
64 | + ), |
|
65 | + REG_ADMIN_URL |
|
66 | + ) . '">' . $attendee->full_name() . '</a>', |
|
67 | + '</h3>' |
|
68 | + ); |
|
69 | + } |
|
70 | + } |
|
71 | + return $text; |
|
72 | + } |
|
73 | 73 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $jsonDates = []; |
38 | 38 | foreach ($datetimes as $datetime) { |
39 | 39 | if ($datetime instanceof EE_Datetime) { |
40 | - $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime); |
|
40 | + $jsonDates[$datetime->ID()] = $this->convertAndEncode($datetime); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | return $jsonDates; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $arrayOfDates = []; |
76 | 76 | foreach ($datetimes as $datetime) { |
77 | 77 | if ($datetime instanceof EE_Datetime) { |
78 | - $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime); |
|
78 | + $arrayOfDates[$datetime->ID()] = $this->convert($datetime); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | return $arrayOfDates; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $jsonDates = []; |
128 | 128 | foreach ($datetimes as $datetime) { |
129 | 129 | if ($datetime instanceof EE_Datetime) { |
130 | - $jsonDates[ $datetime->ID() ] = $this->encode($datetime); |
|
130 | + $jsonDates[$datetime->ID()] = $this->encode($datetime); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | return $jsonDates; |
@@ -21,125 +21,125 @@ |
||
21 | 21 | */ |
22 | 22 | class DatetimeToJson implements ModelObjectToJsonConverterInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * @param EE_Datetime[] $datetimes |
|
26 | - * @return array |
|
27 | - * @throws EE_Error |
|
28 | - * @throws InvalidArgumentException |
|
29 | - * @throws InvalidDataTypeException |
|
30 | - * @throws InvalidInterfaceException |
|
31 | - * @throws ReflectionException |
|
32 | - * @since 5.0.0.p |
|
33 | - */ |
|
34 | - public function convertAndEncodeArrayOf(array $datetimes) |
|
35 | - { |
|
36 | - $jsonDates = []; |
|
37 | - foreach ($datetimes as $datetime) { |
|
38 | - if ($datetime instanceof EE_Datetime) { |
|
39 | - $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime); |
|
40 | - } |
|
41 | - } |
|
42 | - return $jsonDates; |
|
43 | - } |
|
24 | + /** |
|
25 | + * @param EE_Datetime[] $datetimes |
|
26 | + * @return array |
|
27 | + * @throws EE_Error |
|
28 | + * @throws InvalidArgumentException |
|
29 | + * @throws InvalidDataTypeException |
|
30 | + * @throws InvalidInterfaceException |
|
31 | + * @throws ReflectionException |
|
32 | + * @since 5.0.0.p |
|
33 | + */ |
|
34 | + public function convertAndEncodeArrayOf(array $datetimes) |
|
35 | + { |
|
36 | + $jsonDates = []; |
|
37 | + foreach ($datetimes as $datetime) { |
|
38 | + if ($datetime instanceof EE_Datetime) { |
|
39 | + $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime); |
|
40 | + } |
|
41 | + } |
|
42 | + return $jsonDates; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @param EE_Datetime $datetime |
|
48 | - * @return false|string |
|
49 | - * @throws EE_Error |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws InvalidDataTypeException |
|
52 | - * @throws InvalidInterfaceException |
|
53 | - * @throws ReflectionException |
|
54 | - * @since 5.0.0.p |
|
55 | - */ |
|
56 | - public function convertAndEncode($datetime) |
|
57 | - { |
|
58 | - return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false; |
|
59 | - } |
|
46 | + /** |
|
47 | + * @param EE_Datetime $datetime |
|
48 | + * @return false|string |
|
49 | + * @throws EE_Error |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws InvalidDataTypeException |
|
52 | + * @throws InvalidInterfaceException |
|
53 | + * @throws ReflectionException |
|
54 | + * @since 5.0.0.p |
|
55 | + */ |
|
56 | + public function convertAndEncode($datetime) |
|
57 | + { |
|
58 | + return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * @param EE_Datetime[] $datetimes |
|
64 | - * @return array |
|
65 | - * @throws EE_Error |
|
66 | - * @throws InvalidArgumentException |
|
67 | - * @throws InvalidDataTypeException |
|
68 | - * @throws InvalidInterfaceException |
|
69 | - * @throws ReflectionException |
|
70 | - * @since 5.0.0.p |
|
71 | - */ |
|
72 | - public function convertArrayOf(array $datetimes) |
|
73 | - { |
|
74 | - $arrayOfDates = []; |
|
75 | - foreach ($datetimes as $datetime) { |
|
76 | - if ($datetime instanceof EE_Datetime) { |
|
77 | - $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime); |
|
78 | - } |
|
79 | - } |
|
80 | - return $arrayOfDates; |
|
81 | - } |
|
62 | + /** |
|
63 | + * @param EE_Datetime[] $datetimes |
|
64 | + * @return array |
|
65 | + * @throws EE_Error |
|
66 | + * @throws InvalidArgumentException |
|
67 | + * @throws InvalidDataTypeException |
|
68 | + * @throws InvalidInterfaceException |
|
69 | + * @throws ReflectionException |
|
70 | + * @since 5.0.0.p |
|
71 | + */ |
|
72 | + public function convertArrayOf(array $datetimes) |
|
73 | + { |
|
74 | + $arrayOfDates = []; |
|
75 | + foreach ($datetimes as $datetime) { |
|
76 | + if ($datetime instanceof EE_Datetime) { |
|
77 | + $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime); |
|
78 | + } |
|
79 | + } |
|
80 | + return $arrayOfDates; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * @param EE_Datetime $datetime |
|
86 | - * @return array |
|
87 | - * @throws EE_Error |
|
88 | - * @throws InvalidDataTypeException |
|
89 | - * @throws InvalidInterfaceException |
|
90 | - * @throws InvalidArgumentException |
|
91 | - * @throws ReflectionException |
|
92 | - * @since 5.0.0.p |
|
93 | - */ |
|
94 | - public function convert($datetime) |
|
95 | - { |
|
96 | - return $datetime instanceof EE_Datetime ? [ |
|
97 | - 'DTT_ID' => $datetime->ID(), |
|
98 | - 'EVT_ID' => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0, |
|
99 | - 'DTT_name' => $datetime->name(), |
|
100 | - 'DTT_description' => $datetime->description(), |
|
101 | - 'DTT_EVT_start' => $datetime->start_date(DATE_ATOM), |
|
102 | - 'DTT_EVT_end' => $datetime->end_date(DATE_ATOM), |
|
103 | - 'DTT_sold' => $datetime->sold(), |
|
104 | - 'DTT_reserved' => $datetime->reserved(), |
|
105 | - 'DTT_reg_limit' => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(), |
|
106 | - 'DTT_is_primary' => $datetime->get_active_status(), |
|
107 | - 'DTT_order' => $datetime->order(), |
|
108 | - 'DTT_parent' => $datetime->parent(), |
|
109 | - 'DTT_deleted' => $datetime->get('DTT_deleted'), |
|
110 | - ] : []; |
|
111 | - } |
|
84 | + /** |
|
85 | + * @param EE_Datetime $datetime |
|
86 | + * @return array |
|
87 | + * @throws EE_Error |
|
88 | + * @throws InvalidDataTypeException |
|
89 | + * @throws InvalidInterfaceException |
|
90 | + * @throws InvalidArgumentException |
|
91 | + * @throws ReflectionException |
|
92 | + * @since 5.0.0.p |
|
93 | + */ |
|
94 | + public function convert($datetime) |
|
95 | + { |
|
96 | + return $datetime instanceof EE_Datetime ? [ |
|
97 | + 'DTT_ID' => $datetime->ID(), |
|
98 | + 'EVT_ID' => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0, |
|
99 | + 'DTT_name' => $datetime->name(), |
|
100 | + 'DTT_description' => $datetime->description(), |
|
101 | + 'DTT_EVT_start' => $datetime->start_date(DATE_ATOM), |
|
102 | + 'DTT_EVT_end' => $datetime->end_date(DATE_ATOM), |
|
103 | + 'DTT_sold' => $datetime->sold(), |
|
104 | + 'DTT_reserved' => $datetime->reserved(), |
|
105 | + 'DTT_reg_limit' => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(), |
|
106 | + 'DTT_is_primary' => $datetime->get_active_status(), |
|
107 | + 'DTT_order' => $datetime->order(), |
|
108 | + 'DTT_parent' => $datetime->parent(), |
|
109 | + 'DTT_deleted' => $datetime->get('DTT_deleted'), |
|
110 | + ] : []; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * @param EE_Datetime[] $datetimes |
|
116 | - * @return array |
|
117 | - * @throws EE_Error |
|
118 | - * @throws InvalidArgumentException |
|
119 | - * @throws InvalidDataTypeException |
|
120 | - * @throws InvalidInterfaceException |
|
121 | - * @throws ReflectionException |
|
122 | - * @since 5.0.0.p |
|
123 | - */ |
|
124 | - public function encodeArrayOf(array $datetimes) |
|
125 | - { |
|
126 | - $jsonDates = []; |
|
127 | - foreach ($datetimes as $datetime) { |
|
128 | - if ($datetime instanceof EE_Datetime) { |
|
129 | - $jsonDates[ $datetime->ID() ] = $this->encode($datetime); |
|
130 | - } |
|
131 | - } |
|
132 | - return $jsonDates; |
|
133 | - } |
|
114 | + /** |
|
115 | + * @param EE_Datetime[] $datetimes |
|
116 | + * @return array |
|
117 | + * @throws EE_Error |
|
118 | + * @throws InvalidArgumentException |
|
119 | + * @throws InvalidDataTypeException |
|
120 | + * @throws InvalidInterfaceException |
|
121 | + * @throws ReflectionException |
|
122 | + * @since 5.0.0.p |
|
123 | + */ |
|
124 | + public function encodeArrayOf(array $datetimes) |
|
125 | + { |
|
126 | + $jsonDates = []; |
|
127 | + foreach ($datetimes as $datetime) { |
|
128 | + if ($datetime instanceof EE_Datetime) { |
|
129 | + $jsonDates[ $datetime->ID() ] = $this->encode($datetime); |
|
130 | + } |
|
131 | + } |
|
132 | + return $jsonDates; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * @param array $datetime_array |
|
138 | - * @return false|string |
|
139 | - * @since 5.0.0.p |
|
140 | - */ |
|
141 | - public function encode(array $datetime_array) |
|
142 | - { |
|
143 | - return wp_json_encode($datetime_array); |
|
144 | - } |
|
136 | + /** |
|
137 | + * @param array $datetime_array |
|
138 | + * @return false|string |
|
139 | + * @since 5.0.0.p |
|
140 | + */ |
|
141 | + public function encode(array $datetime_array) |
|
142 | + { |
|
143 | + return wp_json_encode($datetime_array); |
|
144 | + } |
|
145 | 145 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function getOneApiResult(EEM_Base $model, array $query_params, $include = '') |
118 | 118 | { |
119 | - if (! array_key_exists('limit', $query_params)) { |
|
119 | + if ( ! array_key_exists('limit', $query_params)) { |
|
120 | 120 | $query_params['limit'] = 1; |
121 | 121 | } |
122 | 122 | $result = $this->getApiResults($model, $query_params, $include); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function getApiResults(EEM_Base $model, array $query_params, $include = '') |
145 | 145 | { |
146 | - if (! array_key_exists('caps', $query_params)) { |
|
146 | + if ( ! array_key_exists('caps', $query_params)) { |
|
147 | 147 | $query_params['caps'] = EEM_Base::caps_read_admin; |
148 | 148 | } |
149 | - if (! array_key_exists('default_where_conditions', $query_params)) { |
|
149 | + if ( ! array_key_exists('default_where_conditions', $query_params)) { |
|
150 | 150 | $query_params['default_where_conditions'] = 'none'; |
151 | 151 | } |
152 | 152 | /** @type array $results */ |
@@ -49,137 +49,137 @@ |
||
49 | 49 | */ |
50 | 50 | class RestApiSpoofer |
51 | 51 | { |
52 | - /** |
|
53 | - * @var WP_REST_Server $wp_rest_server |
|
54 | - */ |
|
55 | - protected $wp_rest_server; |
|
52 | + /** |
|
53 | + * @var WP_REST_Server $wp_rest_server |
|
54 | + */ |
|
55 | + protected $wp_rest_server; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @var Read |
|
59 | - */ |
|
60 | - protected $rest_controller; |
|
57 | + /** |
|
58 | + * @var Read |
|
59 | + */ |
|
60 | + protected $rest_controller; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var EED_Core_Rest_Api $rest_module |
|
64 | - */ |
|
65 | - protected $rest_module; |
|
62 | + /** |
|
63 | + * @var EED_Core_Rest_Api $rest_module |
|
64 | + */ |
|
65 | + protected $rest_module; |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * RestApiSpoofer constructor. |
|
70 | - * |
|
71 | - * @param WP_REST_Server $wp_rest_server |
|
72 | - * @param EED_Core_Rest_Api $rest_module |
|
73 | - * @param Read $rest_api |
|
74 | - * @param string $api_version |
|
75 | - */ |
|
76 | - public function __construct( |
|
77 | - WP_REST_Server $wp_rest_server, |
|
78 | - EED_Core_Rest_Api $rest_module, |
|
79 | - Read $rest_api, |
|
80 | - $api_version = '4.8.36' |
|
81 | - ) { |
|
82 | - $this->wp_rest_server = $wp_rest_server; |
|
83 | - $this->rest_module = $rest_module; |
|
84 | - $this->rest_controller = $rest_api; |
|
85 | - $this->rest_controller->setRequestedVersion($api_version); |
|
86 | - $this->setUpRestServer(); |
|
87 | - } |
|
68 | + /** |
|
69 | + * RestApiSpoofer constructor. |
|
70 | + * |
|
71 | + * @param WP_REST_Server $wp_rest_server |
|
72 | + * @param EED_Core_Rest_Api $rest_module |
|
73 | + * @param Read $rest_api |
|
74 | + * @param string $api_version |
|
75 | + */ |
|
76 | + public function __construct( |
|
77 | + WP_REST_Server $wp_rest_server, |
|
78 | + EED_Core_Rest_Api $rest_module, |
|
79 | + Read $rest_api, |
|
80 | + $api_version = '4.8.36' |
|
81 | + ) { |
|
82 | + $this->wp_rest_server = $wp_rest_server; |
|
83 | + $this->rest_module = $rest_module; |
|
84 | + $this->rest_controller = $rest_api; |
|
85 | + $this->rest_controller->setRequestedVersion($api_version); |
|
86 | + $this->setUpRestServer(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - private function setUpRestServer() |
|
91 | - { |
|
92 | - /* @var WP_REST_Server $wp_rest_server */ |
|
93 | - global $wp_rest_server; |
|
94 | - $wp_rest_server = $this->wp_rest_server; |
|
95 | - EED_Core_Rest_Api::set_hooks_both(); |
|
96 | - do_action('rest_api_init', $this->wp_rest_server); |
|
97 | - } |
|
90 | + private function setUpRestServer() |
|
91 | + { |
|
92 | + /* @var WP_REST_Server $wp_rest_server */ |
|
93 | + global $wp_rest_server; |
|
94 | + $wp_rest_server = $this->wp_rest_server; |
|
95 | + EED_Core_Rest_Api::set_hooks_both(); |
|
96 | + do_action('rest_api_init', $this->wp_rest_server); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param EEM_Base $model |
|
101 | - * @param array $query_params |
|
102 | - * @param string $include |
|
103 | - * @return array |
|
104 | - * @throws EE_Error |
|
105 | - * @throws InvalidArgumentException |
|
106 | - * @throws InvalidDataTypeException |
|
107 | - * @throws InvalidInterfaceException |
|
108 | - * @throws ModelConfigurationException |
|
109 | - * @throws ReflectionException |
|
110 | - * @throws RestException |
|
111 | - * @throws RestPasswordIncorrectException |
|
112 | - * @throws RestPasswordRequiredException |
|
113 | - * @throws UnexpectedEntityException |
|
114 | - * @throws DomainException |
|
115 | - * @since 5.0.0.p |
|
116 | - */ |
|
117 | - public function getOneApiResult(EEM_Base $model, array $query_params, $include = '') |
|
118 | - { |
|
119 | - if (! array_key_exists('limit', $query_params)) { |
|
120 | - $query_params['limit'] = 1; |
|
121 | - } |
|
122 | - $result = $this->getApiResults($model, $query_params, $include); |
|
123 | - return is_array($result) && isset($result[0]) ? $result[0] : []; |
|
124 | - } |
|
99 | + /** |
|
100 | + * @param EEM_Base $model |
|
101 | + * @param array $query_params |
|
102 | + * @param string $include |
|
103 | + * @return array |
|
104 | + * @throws EE_Error |
|
105 | + * @throws InvalidArgumentException |
|
106 | + * @throws InvalidDataTypeException |
|
107 | + * @throws InvalidInterfaceException |
|
108 | + * @throws ModelConfigurationException |
|
109 | + * @throws ReflectionException |
|
110 | + * @throws RestException |
|
111 | + * @throws RestPasswordIncorrectException |
|
112 | + * @throws RestPasswordRequiredException |
|
113 | + * @throws UnexpectedEntityException |
|
114 | + * @throws DomainException |
|
115 | + * @since 5.0.0.p |
|
116 | + */ |
|
117 | + public function getOneApiResult(EEM_Base $model, array $query_params, $include = '') |
|
118 | + { |
|
119 | + if (! array_key_exists('limit', $query_params)) { |
|
120 | + $query_params['limit'] = 1; |
|
121 | + } |
|
122 | + $result = $this->getApiResults($model, $query_params, $include); |
|
123 | + return is_array($result) && isset($result[0]) ? $result[0] : []; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param EEM_Base $model |
|
128 | - * @param array $query_params |
|
129 | - * @param string $include |
|
130 | - * @return array |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidInterfaceException |
|
135 | - * @throws ModelConfigurationException |
|
136 | - * @throws ReflectionException |
|
137 | - * @throws RestException |
|
138 | - * @throws RestPasswordIncorrectException |
|
139 | - * @throws RestPasswordRequiredException |
|
140 | - * @throws UnexpectedEntityException |
|
141 | - * @throws DomainException |
|
142 | - * @since 5.0.0.p |
|
143 | - */ |
|
144 | - public function getApiResults(EEM_Base $model, array $query_params, $include = '') |
|
145 | - { |
|
146 | - if (! array_key_exists('caps', $query_params)) { |
|
147 | - $query_params['caps'] = EEM_Base::caps_read_admin; |
|
148 | - } |
|
149 | - if (! array_key_exists('default_where_conditions', $query_params)) { |
|
150 | - $query_params['default_where_conditions'] = 'none'; |
|
151 | - } |
|
152 | - /** @type array $results */ |
|
153 | - $results = $model->get_all_wpdb_results($query_params); |
|
154 | - $rest_request = new WP_REST_Request(); |
|
155 | - $rest_request->set_param('include', $include); |
|
156 | - $rest_request->set_param('caps', 'edit'); |
|
157 | - $nice_results = array(); |
|
158 | - foreach ($results as $result) { |
|
159 | - $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
160 | - $model, |
|
161 | - $result, |
|
162 | - $rest_request |
|
163 | - ); |
|
164 | - } |
|
165 | - return $nice_results; |
|
166 | - } |
|
126 | + /** |
|
127 | + * @param EEM_Base $model |
|
128 | + * @param array $query_params |
|
129 | + * @param string $include |
|
130 | + * @return array |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidInterfaceException |
|
135 | + * @throws ModelConfigurationException |
|
136 | + * @throws ReflectionException |
|
137 | + * @throws RestException |
|
138 | + * @throws RestPasswordIncorrectException |
|
139 | + * @throws RestPasswordRequiredException |
|
140 | + * @throws UnexpectedEntityException |
|
141 | + * @throws DomainException |
|
142 | + * @since 5.0.0.p |
|
143 | + */ |
|
144 | + public function getApiResults(EEM_Base $model, array $query_params, $include = '') |
|
145 | + { |
|
146 | + if (! array_key_exists('caps', $query_params)) { |
|
147 | + $query_params['caps'] = EEM_Base::caps_read_admin; |
|
148 | + } |
|
149 | + if (! array_key_exists('default_where_conditions', $query_params)) { |
|
150 | + $query_params['default_where_conditions'] = 'none'; |
|
151 | + } |
|
152 | + /** @type array $results */ |
|
153 | + $results = $model->get_all_wpdb_results($query_params); |
|
154 | + $rest_request = new WP_REST_Request(); |
|
155 | + $rest_request->set_param('include', $include); |
|
156 | + $rest_request->set_param('caps', 'edit'); |
|
157 | + $nice_results = array(); |
|
158 | + foreach ($results as $result) { |
|
159 | + $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
160 | + $model, |
|
161 | + $result, |
|
162 | + $rest_request |
|
163 | + ); |
|
164 | + } |
|
165 | + return $nice_results; |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * @param string $endpoint |
|
171 | - * @return array |
|
172 | - * @throws EE_Error |
|
173 | - * @since 5.0.0.p |
|
174 | - */ |
|
175 | - public function getModelSchema($endpoint) |
|
176 | - { |
|
177 | - $response = $this->wp_rest_server->dispatch( |
|
178 | - new WP_REST_Request( |
|
179 | - 'OPTIONS', |
|
180 | - "/ee/v4.8.36/{$endpoint}" |
|
181 | - ) |
|
182 | - ); |
|
183 | - return $response->get_data(); |
|
184 | - } |
|
169 | + /** |
|
170 | + * @param string $endpoint |
|
171 | + * @return array |
|
172 | + * @throws EE_Error |
|
173 | + * @since 5.0.0.p |
|
174 | + */ |
|
175 | + public function getModelSchema($endpoint) |
|
176 | + { |
|
177 | + $response = $this->wp_rest_server->dispatch( |
|
178 | + new WP_REST_Request( |
|
179 | + 'OPTIONS', |
|
180 | + "/ee/v4.8.36/{$endpoint}" |
|
181 | + ) |
|
182 | + ); |
|
183 | + return $response->get_data(); |
|
184 | + } |
|
185 | 185 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | $config = $field->toArray(); |
76 | 76 | if ($field->useForInput()) { |
77 | 77 | // Register input fields for existing mutations. |
78 | - register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
79 | - register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
78 | + register_graphql_field('Update'.$typeName.'Input', $fieldName, $config); |
|
79 | + register_graphql_field('Create'.$typeName.'Input', $fieldName, $config); |
|
80 | 80 | } |
81 | 81 | if ($field->useForOutput()) { |
82 | 82 | $config['resolve'] = [$type, 'resolveField']; |
@@ -102,15 +102,15 @@ discard block |
||
102 | 102 | $fieldName = $field->name(); |
103 | 103 | $config = $field->toArray(); |
104 | 104 | if ($field->useForInput()) { |
105 | - $inputFields[ $fieldName ] = $config; |
|
105 | + $inputFields[$fieldName] = $config; |
|
106 | 106 | } |
107 | 107 | if ($field->useForOutput()) { |
108 | 108 | $config['resolve'] = [$type, 'resolveField']; |
109 | - $outputFields[ $fieldName ] = $config; |
|
109 | + $outputFields[$fieldName] = $config; |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | $typeName = $type->name(); |
113 | - if (! empty($outputFields)) { |
|
113 | + if ( ! empty($outputFields)) { |
|
114 | 114 | // Register the object type. |
115 | 115 | register_graphql_object_type( |
116 | 116 | $typeName, |
@@ -17,110 +17,110 @@ |
||
17 | 17 | */ |
18 | 18 | class TypesManager implements GQLManagerInterface |
19 | 19 | { |
20 | - /** |
|
21 | - * @var TypeCollection|TypeInterface[] $types |
|
22 | - */ |
|
23 | - private $types; |
|
20 | + /** |
|
21 | + * @var TypeCollection|TypeInterface[] $types |
|
22 | + */ |
|
23 | + private $types; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * TypesManager constructor. |
|
28 | - * |
|
29 | - * @param TypeCollection|TypeInterface[] $types |
|
30 | - */ |
|
31 | - public function __construct(TypeCollection $types) |
|
32 | - { |
|
33 | - $this->types = $types; |
|
34 | - } |
|
26 | + /** |
|
27 | + * TypesManager constructor. |
|
28 | + * |
|
29 | + * @param TypeCollection|TypeInterface[] $types |
|
30 | + */ |
|
31 | + public function __construct(TypeCollection $types) |
|
32 | + { |
|
33 | + $this->types = $types; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @throws CollectionDetailsException |
|
39 | - * @throws CollectionLoaderException |
|
40 | - * @since 5.0.0.p |
|
41 | - */ |
|
42 | - public function init() |
|
43 | - { |
|
44 | - $this->types->loadTypes(); |
|
45 | - add_action('graphql_register_types', [$this, 'configureTypes'], 10); |
|
46 | - } |
|
37 | + /** |
|
38 | + * @throws CollectionDetailsException |
|
39 | + * @throws CollectionLoaderException |
|
40 | + * @since 5.0.0.p |
|
41 | + */ |
|
42 | + public function init() |
|
43 | + { |
|
44 | + $this->types->loadTypes(); |
|
45 | + add_action('graphql_register_types', [$this, 'configureTypes'], 10); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @since 5.0.0.p |
|
51 | - */ |
|
52 | - public function configureTypes() |
|
53 | - { |
|
54 | - // loop through the collection of types and register their fields |
|
55 | - foreach ($this->types as $type) { |
|
56 | - if ($type->isCustomPostType()) { |
|
57 | - $this->extendCustomPostType($type); |
|
58 | - } else { |
|
59 | - $this->registerType($type); |
|
60 | - } |
|
61 | - } |
|
62 | - } |
|
49 | + /** |
|
50 | + * @since 5.0.0.p |
|
51 | + */ |
|
52 | + public function configureTypes() |
|
53 | + { |
|
54 | + // loop through the collection of types and register their fields |
|
55 | + foreach ($this->types as $type) { |
|
56 | + if ($type->isCustomPostType()) { |
|
57 | + $this->extendCustomPostType($type); |
|
58 | + } else { |
|
59 | + $this->registerType($type); |
|
60 | + } |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @param TypeInterface $type |
|
67 | - * @since 5.0.0.p |
|
68 | - */ |
|
69 | - public function extendCustomPostType(TypeInterface $type) |
|
70 | - { |
|
71 | - $typeName = $type->name(); |
|
72 | - foreach ($type->fields() as $field) { |
|
73 | - $fieldName = $field->name(); |
|
74 | - $config = $field->toArray(); |
|
75 | - if ($field->useForInput()) { |
|
76 | - // Register input fields for existing mutations. |
|
77 | - register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
78 | - register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
79 | - } |
|
80 | - if ($field->useForOutput()) { |
|
81 | - $config['resolve'] = [$type, 'resolveField']; |
|
82 | - // Register fields for queries. |
|
83 | - register_graphql_field($typeName, $fieldName, $config); |
|
84 | - } |
|
85 | - } |
|
86 | - if (is_callable([$type, 'extendMutations'])) { |
|
87 | - $type->extendMutations(); |
|
88 | - } |
|
89 | - } |
|
65 | + /** |
|
66 | + * @param TypeInterface $type |
|
67 | + * @since 5.0.0.p |
|
68 | + */ |
|
69 | + public function extendCustomPostType(TypeInterface $type) |
|
70 | + { |
|
71 | + $typeName = $type->name(); |
|
72 | + foreach ($type->fields() as $field) { |
|
73 | + $fieldName = $field->name(); |
|
74 | + $config = $field->toArray(); |
|
75 | + if ($field->useForInput()) { |
|
76 | + // Register input fields for existing mutations. |
|
77 | + register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
78 | + register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
79 | + } |
|
80 | + if ($field->useForOutput()) { |
|
81 | + $config['resolve'] = [$type, 'resolveField']; |
|
82 | + // Register fields for queries. |
|
83 | + register_graphql_field($typeName, $fieldName, $config); |
|
84 | + } |
|
85 | + } |
|
86 | + if (is_callable([$type, 'extendMutations'])) { |
|
87 | + $type->extendMutations(); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * @param TypeInterface $type |
|
94 | - * @since 5.0.0.p |
|
95 | - */ |
|
96 | - public function registerType(TypeInterface $type) |
|
97 | - { |
|
98 | - $outputFields = []; |
|
99 | - $inputFields = []; |
|
100 | - foreach ($type->fields() as $field) { |
|
101 | - $fieldName = $field->name(); |
|
102 | - $config = $field->toArray(); |
|
103 | - if ($field->useForInput()) { |
|
104 | - $inputFields[ $fieldName ] = $config; |
|
105 | - } |
|
106 | - if ($field->useForOutput()) { |
|
107 | - $config['resolve'] = [$type, 'resolveField']; |
|
108 | - $outputFields[ $fieldName ] = $config; |
|
109 | - } |
|
110 | - } |
|
111 | - $typeName = $type->name(); |
|
112 | - if (! empty($outputFields)) { |
|
113 | - // Register the object type. |
|
114 | - register_graphql_object_type( |
|
115 | - $typeName, |
|
116 | - [ |
|
117 | - 'description' => $type->description(), |
|
118 | - 'fields' => $outputFields, |
|
119 | - ] |
|
120 | - ); |
|
121 | - } |
|
122 | - if (is_callable([$type, 'registerMutations'])) { |
|
123 | - $type->registerMutations($inputFields); |
|
124 | - } |
|
125 | - } |
|
92 | + /** |
|
93 | + * @param TypeInterface $type |
|
94 | + * @since 5.0.0.p |
|
95 | + */ |
|
96 | + public function registerType(TypeInterface $type) |
|
97 | + { |
|
98 | + $outputFields = []; |
|
99 | + $inputFields = []; |
|
100 | + foreach ($type->fields() as $field) { |
|
101 | + $fieldName = $field->name(); |
|
102 | + $config = $field->toArray(); |
|
103 | + if ($field->useForInput()) { |
|
104 | + $inputFields[ $fieldName ] = $config; |
|
105 | + } |
|
106 | + if ($field->useForOutput()) { |
|
107 | + $config['resolve'] = [$type, 'resolveField']; |
|
108 | + $outputFields[ $fieldName ] = $config; |
|
109 | + } |
|
110 | + } |
|
111 | + $typeName = $type->name(); |
|
112 | + if (! empty($outputFields)) { |
|
113 | + // Register the object type. |
|
114 | + register_graphql_object_type( |
|
115 | + $typeName, |
|
116 | + [ |
|
117 | + 'description' => $type->description(), |
|
118 | + 'fields' => $outputFields, |
|
119 | + ] |
|
120 | + ); |
|
121 | + } |
|
122 | + if (is_callable([$type, 'registerMutations'])) { |
|
123 | + $type->registerMutations($inputFields); |
|
124 | + } |
|
125 | + } |
|
126 | 126 | } |
@@ -155,7 +155,7 @@ |
||
155 | 155 | $fields = []; |
156 | 156 | foreach ($this->fields() as $field) { |
157 | 157 | if ($field->useForOutput()) { |
158 | - $fields[ $field->name() ] = $field; |
|
158 | + $fields[$field->name()] = $field; |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | return $fields; |
@@ -34,270 +34,270 @@ |
||
34 | 34 | */ |
35 | 35 | abstract class TypeBase implements TypeInterface |
36 | 36 | { |
37 | - /** |
|
38 | - * @var string $namespace The graphql namespace/prefix. |
|
39 | - */ |
|
40 | - protected $namespace = 'Espresso'; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EEM_Base $model |
|
44 | - */ |
|
45 | - protected $model; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string $name |
|
49 | - */ |
|
50 | - protected $name = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string $description |
|
54 | - */ |
|
55 | - protected $description = ''; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var GraphQLFieldInterface[] $fields |
|
59 | - */ |
|
60 | - protected $fields = []; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var array $graphql_to_model_map |
|
64 | - */ |
|
65 | - protected $graphql_to_model_map = []; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var FieldResolver $field_resolver |
|
69 | - */ |
|
70 | - protected $field_resolver; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var bool $is_custom_post_type |
|
74 | - */ |
|
75 | - protected $is_custom_post_type = false; |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * TypeBase constructor. |
|
80 | - * |
|
81 | - * @param EEM_Base|null $model |
|
82 | - */ |
|
83 | - public function __construct(EEM_Base $model = null) |
|
84 | - { |
|
85 | - $this->model = $model; |
|
86 | - $this->setFields($this->getFields()); |
|
87 | - $this->field_resolver = new FieldResolver( |
|
88 | - $this->model, |
|
89 | - $this->getFieldsForResolver() |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return GraphQLFieldInterface[] |
|
96 | - * @since 5.0.0.p |
|
97 | - */ |
|
98 | - abstract protected function getFields(): array; |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function name(): string |
|
105 | - { |
|
106 | - return $this->name; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @param string $name |
|
112 | - */ |
|
113 | - protected function setName(string $name) |
|
114 | - { |
|
115 | - $this->name = $name; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function description(): string |
|
123 | - { |
|
124 | - return $this->description; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $description |
|
130 | - */ |
|
131 | - protected function setDescription(string $description) |
|
132 | - { |
|
133 | - $this->description = $description; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @return GraphQLFieldInterface[] |
|
139 | - * @since 5.0.0.p |
|
140 | - */ |
|
141 | - public function fields(): array |
|
142 | - { |
|
143 | - return (array) $this->fields; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @param GraphQLFieldInterface[] $fields |
|
149 | - */ |
|
150 | - protected function setFields(array $fields) |
|
151 | - { |
|
152 | - foreach ($fields as $field) { |
|
153 | - if ($field instanceof GraphQLField) { |
|
154 | - $this->fields[] = $field; |
|
155 | - } |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Creates a key map for internal resolver. |
|
162 | - * |
|
163 | - * @return array |
|
164 | - * @since 5.0.0.p |
|
165 | - */ |
|
166 | - public function getFieldsForResolver(): array |
|
167 | - { |
|
168 | - $fields = []; |
|
169 | - foreach ($this->fields() as $field) { |
|
170 | - if ($field->useForOutput()) { |
|
171 | - $fields[ $field->name() ] = $field; |
|
172 | - } |
|
173 | - } |
|
174 | - return $fields; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function isCustomPostType(): bool |
|
182 | - { |
|
183 | - return $this->is_custom_post_type; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @param bool $is_custom_post_type |
|
189 | - */ |
|
190 | - protected function setIsCustomPostType(bool $is_custom_post_type) |
|
191 | - { |
|
192 | - $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @param int|float $value |
|
198 | - * @return int |
|
199 | - * @since 5.0.0.p |
|
200 | - */ |
|
201 | - public function parseInfiniteValue($value): int |
|
202 | - { |
|
203 | - $value = trim($value); |
|
204 | - return $value === null |
|
205 | - || $value === '' |
|
206 | - || $value === '∞' |
|
207 | - || $value === 'INF' |
|
208 | - || $value === INF |
|
209 | - || $value === EE_INF |
|
210 | - || is_infinite((float) $value) |
|
211 | - ? -1 |
|
212 | - : $value; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param mixed $source |
|
218 | - * @return EE_Base_Class|null |
|
219 | - * @throws EE_Error |
|
220 | - */ |
|
221 | - private function getModel($source): ?EE_Base_Class |
|
222 | - { |
|
223 | - // If it comes from a custom connection |
|
224 | - // where the $source is already instantiated. |
|
225 | - if ($source instanceof EE_Base_Class) { |
|
226 | - return $source; |
|
227 | - } |
|
228 | - return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
234 | - * @param array $args The inputArgs on the field |
|
235 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
236 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
237 | - * @return EE_Base_Class|Deferred|string|null |
|
238 | - * @throws EE_Error |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - * @throws InvalidInterfaceException |
|
241 | - * @throws UnexpectedEntityException |
|
242 | - * @throws UserError |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws ReflectionException |
|
245 | - * @since 5.0.0.p |
|
246 | - */ |
|
247 | - public function resolveField($source, array $args, AppContext $context, ResolveInfo $info) |
|
248 | - { |
|
249 | - $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
250 | - |
|
251 | - return $this->field_resolver->resolve($source, $args, $context, $info); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param mixed $payload The payload returned after mutation |
|
257 | - * @param array $args The inputArgs on the field |
|
258 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
259 | - * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null |
|
260 | - * @throws EE_Error |
|
261 | - */ |
|
262 | - public function resolveFromPayload($payload, array $args, AppContext $context) |
|
263 | - { |
|
264 | - if (empty($payload['id'])) { |
|
265 | - return null; |
|
266 | - } |
|
267 | - return $this->model->get_one_by_ID($payload['id']); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Prepares a datetime value in ISO8601/RFC3339 format. |
|
273 | - * It is assumed that the value of $datetime is in the format |
|
274 | - * returned by EE_Base_Class::get_format(). |
|
275 | - * |
|
276 | - * @param string $datetime The datetime value. |
|
277 | - * @param EE_Base_Class $source The source object. |
|
278 | - * @return string ISO8601/RFC3339 formatted datetime. |
|
279 | - */ |
|
280 | - public function formatDatetime(string $datetime, EE_Base_Class $source): string |
|
281 | - { |
|
282 | - $format = $source->get_format(); |
|
283 | - // create date object based on local timezone |
|
284 | - $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
285 | - // change the timezone to UTC |
|
286 | - $datetime->setTimezone(new DateTimeZone('UTC')); |
|
287 | - |
|
288 | - return $datetime->format(DateTime::RFC3339); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Converts an object to JSON. The object must have a "toJson" method. |
|
294 | - * |
|
295 | - * @param string $object The object/value. |
|
296 | - * @param EE_Base_Class $source The source object. |
|
297 | - * @return string JSON representation of the object. |
|
298 | - */ |
|
299 | - public function toJson(JsonableInterface $object, EE_Base_Class $source): string |
|
300 | - { |
|
301 | - return $object->toJson(); |
|
302 | - } |
|
37 | + /** |
|
38 | + * @var string $namespace The graphql namespace/prefix. |
|
39 | + */ |
|
40 | + protected $namespace = 'Espresso'; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EEM_Base $model |
|
44 | + */ |
|
45 | + protected $model; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string $name |
|
49 | + */ |
|
50 | + protected $name = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string $description |
|
54 | + */ |
|
55 | + protected $description = ''; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var GraphQLFieldInterface[] $fields |
|
59 | + */ |
|
60 | + protected $fields = []; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var array $graphql_to_model_map |
|
64 | + */ |
|
65 | + protected $graphql_to_model_map = []; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var FieldResolver $field_resolver |
|
69 | + */ |
|
70 | + protected $field_resolver; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var bool $is_custom_post_type |
|
74 | + */ |
|
75 | + protected $is_custom_post_type = false; |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * TypeBase constructor. |
|
80 | + * |
|
81 | + * @param EEM_Base|null $model |
|
82 | + */ |
|
83 | + public function __construct(EEM_Base $model = null) |
|
84 | + { |
|
85 | + $this->model = $model; |
|
86 | + $this->setFields($this->getFields()); |
|
87 | + $this->field_resolver = new FieldResolver( |
|
88 | + $this->model, |
|
89 | + $this->getFieldsForResolver() |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return GraphQLFieldInterface[] |
|
96 | + * @since 5.0.0.p |
|
97 | + */ |
|
98 | + abstract protected function getFields(): array; |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function name(): string |
|
105 | + { |
|
106 | + return $this->name; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @param string $name |
|
112 | + */ |
|
113 | + protected function setName(string $name) |
|
114 | + { |
|
115 | + $this->name = $name; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function description(): string |
|
123 | + { |
|
124 | + return $this->description; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $description |
|
130 | + */ |
|
131 | + protected function setDescription(string $description) |
|
132 | + { |
|
133 | + $this->description = $description; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @return GraphQLFieldInterface[] |
|
139 | + * @since 5.0.0.p |
|
140 | + */ |
|
141 | + public function fields(): array |
|
142 | + { |
|
143 | + return (array) $this->fields; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @param GraphQLFieldInterface[] $fields |
|
149 | + */ |
|
150 | + protected function setFields(array $fields) |
|
151 | + { |
|
152 | + foreach ($fields as $field) { |
|
153 | + if ($field instanceof GraphQLField) { |
|
154 | + $this->fields[] = $field; |
|
155 | + } |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Creates a key map for internal resolver. |
|
162 | + * |
|
163 | + * @return array |
|
164 | + * @since 5.0.0.p |
|
165 | + */ |
|
166 | + public function getFieldsForResolver(): array |
|
167 | + { |
|
168 | + $fields = []; |
|
169 | + foreach ($this->fields() as $field) { |
|
170 | + if ($field->useForOutput()) { |
|
171 | + $fields[ $field->name() ] = $field; |
|
172 | + } |
|
173 | + } |
|
174 | + return $fields; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function isCustomPostType(): bool |
|
182 | + { |
|
183 | + return $this->is_custom_post_type; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @param bool $is_custom_post_type |
|
189 | + */ |
|
190 | + protected function setIsCustomPostType(bool $is_custom_post_type) |
|
191 | + { |
|
192 | + $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param int|float $value |
|
198 | + * @return int |
|
199 | + * @since 5.0.0.p |
|
200 | + */ |
|
201 | + public function parseInfiniteValue($value): int |
|
202 | + { |
|
203 | + $value = trim($value); |
|
204 | + return $value === null |
|
205 | + || $value === '' |
|
206 | + || $value === '∞' |
|
207 | + || $value === 'INF' |
|
208 | + || $value === INF |
|
209 | + || $value === EE_INF |
|
210 | + || is_infinite((float) $value) |
|
211 | + ? -1 |
|
212 | + : $value; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param mixed $source |
|
218 | + * @return EE_Base_Class|null |
|
219 | + * @throws EE_Error |
|
220 | + */ |
|
221 | + private function getModel($source): ?EE_Base_Class |
|
222 | + { |
|
223 | + // If it comes from a custom connection |
|
224 | + // where the $source is already instantiated. |
|
225 | + if ($source instanceof EE_Base_Class) { |
|
226 | + return $source; |
|
227 | + } |
|
228 | + return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
234 | + * @param array $args The inputArgs on the field |
|
235 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
236 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
237 | + * @return EE_Base_Class|Deferred|string|null |
|
238 | + * @throws EE_Error |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + * @throws InvalidInterfaceException |
|
241 | + * @throws UnexpectedEntityException |
|
242 | + * @throws UserError |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws ReflectionException |
|
245 | + * @since 5.0.0.p |
|
246 | + */ |
|
247 | + public function resolveField($source, array $args, AppContext $context, ResolveInfo $info) |
|
248 | + { |
|
249 | + $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
250 | + |
|
251 | + return $this->field_resolver->resolve($source, $args, $context, $info); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param mixed $payload The payload returned after mutation |
|
257 | + * @param array $args The inputArgs on the field |
|
258 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
259 | + * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null |
|
260 | + * @throws EE_Error |
|
261 | + */ |
|
262 | + public function resolveFromPayload($payload, array $args, AppContext $context) |
|
263 | + { |
|
264 | + if (empty($payload['id'])) { |
|
265 | + return null; |
|
266 | + } |
|
267 | + return $this->model->get_one_by_ID($payload['id']); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Prepares a datetime value in ISO8601/RFC3339 format. |
|
273 | + * It is assumed that the value of $datetime is in the format |
|
274 | + * returned by EE_Base_Class::get_format(). |
|
275 | + * |
|
276 | + * @param string $datetime The datetime value. |
|
277 | + * @param EE_Base_Class $source The source object. |
|
278 | + * @return string ISO8601/RFC3339 formatted datetime. |
|
279 | + */ |
|
280 | + public function formatDatetime(string $datetime, EE_Base_Class $source): string |
|
281 | + { |
|
282 | + $format = $source->get_format(); |
|
283 | + // create date object based on local timezone |
|
284 | + $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
285 | + // change the timezone to UTC |
|
286 | + $datetime->setTimezone(new DateTimeZone('UTC')); |
|
287 | + |
|
288 | + return $datetime->format(DateTime::RFC3339); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Converts an object to JSON. The object must have a "toJson" method. |
|
294 | + * |
|
295 | + * @param string $object The object/value. |
|
296 | + * @param EE_Base_Class $source The source object. |
|
297 | + * @return string JSON representation of the object. |
|
298 | + */ |
|
299 | + public function toJson(JsonableInterface $object, EE_Base_Class $source): string |
|
300 | + { |
|
301 | + return $object->toJson(); |
|
302 | + } |
|
303 | 303 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | */ |
50 | 50 | private function loadCollection() |
51 | 51 | { |
52 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | + if ( ! $this->loader instanceof CollectionLoader) { |
|
53 | 53 | $this->loader = new CollectionLoader( |
54 | 54 | new CollectionDetails( |
55 | 55 | // collection name |
@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | class ResolverCollection extends Collection |
22 | 22 | { |
23 | - const COLLECTION_NAME = 'espresso_graphql_resolvers'; |
|
23 | + const COLLECTION_NAME = 'espresso_graphql_resolvers'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionLoader $loader |
|
27 | - */ |
|
28 | - protected $loader; |
|
25 | + /** |
|
26 | + * @var CollectionLoader $loader |
|
27 | + */ |
|
28 | + protected $loader; |
|
29 | 29 | |
30 | - /** |
|
31 | - * ResolverCollection constructor |
|
32 | - * |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - parent::__construct( |
|
38 | - 'EventEspresso\core\services\graphql\ResolverInterface', |
|
39 | - ResolverCollection::COLLECTION_NAME |
|
40 | - ); |
|
41 | - } |
|
30 | + /** |
|
31 | + * ResolverCollection constructor |
|
32 | + * |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + parent::__construct( |
|
38 | + 'EventEspresso\core\services\graphql\ResolverInterface', |
|
39 | + ResolverCollection::COLLECTION_NAME |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @throws CollectionDetailsException |
|
46 | - * @throws CollectionLoaderException |
|
47 | - * @since 5.0.0.p |
|
48 | - */ |
|
49 | - private function loadCollection() |
|
50 | - { |
|
51 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | - $this->loader = new CollectionLoader( |
|
53 | - new CollectionDetails( |
|
54 | - // collection name |
|
55 | - ResolverCollection::COLLECTION_NAME, |
|
56 | - // collection interface |
|
57 | - 'EventEspresso\core\services\graphql\ResolverInterface', |
|
58 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | - apply_filters( |
|
60 | - 'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs', |
|
61 | - ['EventEspresso\core\domain\services\graphql\resolvers'] |
|
62 | - ), |
|
63 | - // filepaths to classes to add |
|
64 | - array(), |
|
65 | - // file mask to use if parsing folder for files to add |
|
66 | - '', |
|
67 | - // what to use as identifier for collection entities |
|
68 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | - CollectionDetails::ID_CLASS_NAME |
|
70 | - ), |
|
71 | - $this |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @throws CollectionDetailsException |
|
46 | + * @throws CollectionLoaderException |
|
47 | + * @since 5.0.0.p |
|
48 | + */ |
|
49 | + private function loadCollection() |
|
50 | + { |
|
51 | + if (! $this->loader instanceof CollectionLoader) { |
|
52 | + $this->loader = new CollectionLoader( |
|
53 | + new CollectionDetails( |
|
54 | + // collection name |
|
55 | + ResolverCollection::COLLECTION_NAME, |
|
56 | + // collection interface |
|
57 | + 'EventEspresso\core\services\graphql\ResolverInterface', |
|
58 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | + apply_filters( |
|
60 | + 'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs', |
|
61 | + ['EventEspresso\core\domain\services\graphql\resolvers'] |
|
62 | + ), |
|
63 | + // filepaths to classes to add |
|
64 | + array(), |
|
65 | + // file mask to use if parsing folder for files to add |
|
66 | + '', |
|
67 | + // what to use as identifier for collection entities |
|
68 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | + CollectionDetails::ID_CLASS_NAME |
|
70 | + ), |
|
71 | + $this |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @return CollectionInterface |
|
79 | - * @throws CollectionDetailsException |
|
80 | - * @throws CollectionLoaderException |
|
81 | - * @since 5.0.0.p |
|
82 | - */ |
|
83 | - public function loadResolvers() |
|
84 | - { |
|
85 | - $this->loadCollection(); |
|
86 | - return $this->loader->getCollection(); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return CollectionInterface |
|
79 | + * @throws CollectionDetailsException |
|
80 | + * @throws CollectionLoaderException |
|
81 | + * @since 5.0.0.p |
|
82 | + */ |
|
83 | + public function loadResolvers() |
|
84 | + { |
|
85 | + $this->loadCollection(); |
|
86 | + return $this->loader->getCollection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * getIdentifier |
|
92 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | - * |
|
95 | - * @param $object |
|
96 | - * @param mixed $identifier |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function getIdentifier($object, $identifier = null) |
|
100 | - { |
|
101 | - return ! empty($identifier) |
|
102 | - ? $identifier |
|
103 | - : get_class($object); |
|
104 | - } |
|
90 | + /** |
|
91 | + * getIdentifier |
|
92 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | + * |
|
95 | + * @param $object |
|
96 | + * @param mixed $identifier |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function getIdentifier($object, $identifier = null) |
|
100 | + { |
|
101 | + return ! empty($identifier) |
|
102 | + ? $identifier |
|
103 | + : get_class($object); |
|
104 | + } |
|
105 | 105 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | */ |
50 | 50 | private function loadCollection() |
51 | 51 | { |
52 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | + if ( ! $this->loader instanceof CollectionLoader) { |
|
53 | 53 | $this->loader = new CollectionLoader( |
54 | 54 | new CollectionDetails( |
55 | 55 | // collection name |
@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | class EnumCollection extends Collection |
22 | 22 | { |
23 | - const COLLECTION_NAME = 'espresso_graphql_enums'; |
|
23 | + const COLLECTION_NAME = 'espresso_graphql_enums'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionLoader $loader |
|
27 | - */ |
|
28 | - protected $loader; |
|
25 | + /** |
|
26 | + * @var CollectionLoader $loader |
|
27 | + */ |
|
28 | + protected $loader; |
|
29 | 29 | |
30 | - /** |
|
31 | - * EnumCollection constructor |
|
32 | - * |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - parent::__construct( |
|
38 | - 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
39 | - EnumCollection::COLLECTION_NAME |
|
40 | - ); |
|
41 | - } |
|
30 | + /** |
|
31 | + * EnumCollection constructor |
|
32 | + * |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + parent::__construct( |
|
38 | + 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
39 | + EnumCollection::COLLECTION_NAME |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @throws CollectionDetailsException |
|
46 | - * @throws CollectionLoaderException |
|
47 | - * @since 5.0.0.p |
|
48 | - */ |
|
49 | - private function loadCollection() |
|
50 | - { |
|
51 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | - $this->loader = new CollectionLoader( |
|
53 | - new CollectionDetails( |
|
54 | - // collection name |
|
55 | - EnumCollection::COLLECTION_NAME, |
|
56 | - // collection interface |
|
57 | - 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
58 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | - apply_filters( |
|
60 | - 'FHEE__EventEspresso_core_services_graphql_EnumCollection__loadCollection__collection_FQCNs', |
|
61 | - ['EventEspresso\core\domain\services\graphql\enums'] |
|
62 | - ), |
|
63 | - // filepaths to classes to add |
|
64 | - array(), |
|
65 | - // file mask to use if parsing folder for files to add |
|
66 | - '', |
|
67 | - // what to use as identifier for collection entities |
|
68 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | - CollectionDetails::ID_CLASS_NAME |
|
70 | - ), |
|
71 | - $this |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @throws CollectionDetailsException |
|
46 | + * @throws CollectionLoaderException |
|
47 | + * @since 5.0.0.p |
|
48 | + */ |
|
49 | + private function loadCollection() |
|
50 | + { |
|
51 | + if (! $this->loader instanceof CollectionLoader) { |
|
52 | + $this->loader = new CollectionLoader( |
|
53 | + new CollectionDetails( |
|
54 | + // collection name |
|
55 | + EnumCollection::COLLECTION_NAME, |
|
56 | + // collection interface |
|
57 | + 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
58 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | + apply_filters( |
|
60 | + 'FHEE__EventEspresso_core_services_graphql_EnumCollection__loadCollection__collection_FQCNs', |
|
61 | + ['EventEspresso\core\domain\services\graphql\enums'] |
|
62 | + ), |
|
63 | + // filepaths to classes to add |
|
64 | + array(), |
|
65 | + // file mask to use if parsing folder for files to add |
|
66 | + '', |
|
67 | + // what to use as identifier for collection entities |
|
68 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | + CollectionDetails::ID_CLASS_NAME |
|
70 | + ), |
|
71 | + $this |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @return CollectionInterface |
|
79 | - * @throws CollectionDetailsException |
|
80 | - * @throws CollectionLoaderException |
|
81 | - * @since 5.0.0.p |
|
82 | - */ |
|
83 | - public function loadEnums() |
|
84 | - { |
|
85 | - $this->loadCollection(); |
|
86 | - return $this->loader->getCollection(); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return CollectionInterface |
|
79 | + * @throws CollectionDetailsException |
|
80 | + * @throws CollectionLoaderException |
|
81 | + * @since 5.0.0.p |
|
82 | + */ |
|
83 | + public function loadEnums() |
|
84 | + { |
|
85 | + $this->loadCollection(); |
|
86 | + return $this->loader->getCollection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * getIdentifier |
|
92 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | - * |
|
95 | - * @param $object |
|
96 | - * @param mixed $identifier |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function getIdentifier($object, $identifier = null) |
|
100 | - { |
|
101 | - return ! empty($identifier) |
|
102 | - ? $identifier |
|
103 | - : get_class($object); |
|
104 | - } |
|
90 | + /** |
|
91 | + * getIdentifier |
|
92 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | + * |
|
95 | + * @param $object |
|
96 | + * @param mixed $identifier |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function getIdentifier($object, $identifier = null) |
|
100 | + { |
|
101 | + return ! empty($identifier) |
|
102 | + ? $identifier |
|
103 | + : get_class($object); |
|
104 | + } |
|
105 | 105 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | */ |
50 | 50 | private function loadCollection() |
51 | 51 | { |
52 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | + if ( ! $this->loader instanceof CollectionLoader) { |
|
53 | 53 | $this->loader = new CollectionLoader( |
54 | 54 | new CollectionDetails( |
55 | 55 | // collection name |
@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | class InputCollection extends Collection |
22 | 22 | { |
23 | - const COLLECTION_NAME = 'espresso_graphql_inputs'; |
|
23 | + const COLLECTION_NAME = 'espresso_graphql_inputs'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionLoader $loader |
|
27 | - */ |
|
28 | - protected $loader; |
|
25 | + /** |
|
26 | + * @var CollectionLoader $loader |
|
27 | + */ |
|
28 | + protected $loader; |
|
29 | 29 | |
30 | - /** |
|
31 | - * InputCollection constructor |
|
32 | - * |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - parent::__construct( |
|
38 | - 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
39 | - InputCollection::COLLECTION_NAME |
|
40 | - ); |
|
41 | - } |
|
30 | + /** |
|
31 | + * InputCollection constructor |
|
32 | + * |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + parent::__construct( |
|
38 | + 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
39 | + InputCollection::COLLECTION_NAME |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @throws CollectionDetailsException |
|
46 | - * @throws CollectionLoaderException |
|
47 | - * @since 5.0.0.p |
|
48 | - */ |
|
49 | - private function loadCollection() |
|
50 | - { |
|
51 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | - $this->loader = new CollectionLoader( |
|
53 | - new CollectionDetails( |
|
54 | - // collection name |
|
55 | - InputCollection::COLLECTION_NAME, |
|
56 | - // collection interface |
|
57 | - 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
58 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | - apply_filters( |
|
60 | - 'FHEE__EventEspresso_core_services_graphql_InputCollection__loadCollection__collection_FQCNs', |
|
61 | - ['EventEspresso\core\domain\services\graphql\inputs'] |
|
62 | - ), |
|
63 | - // filepaths to classes to add |
|
64 | - array(), |
|
65 | - // file mask to use if parsing folder for files to add |
|
66 | - '', |
|
67 | - // what to use as identifier for collection entities |
|
68 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | - CollectionDetails::ID_CLASS_NAME |
|
70 | - ), |
|
71 | - $this |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @throws CollectionDetailsException |
|
46 | + * @throws CollectionLoaderException |
|
47 | + * @since 5.0.0.p |
|
48 | + */ |
|
49 | + private function loadCollection() |
|
50 | + { |
|
51 | + if (! $this->loader instanceof CollectionLoader) { |
|
52 | + $this->loader = new CollectionLoader( |
|
53 | + new CollectionDetails( |
|
54 | + // collection name |
|
55 | + InputCollection::COLLECTION_NAME, |
|
56 | + // collection interface |
|
57 | + 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
58 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | + apply_filters( |
|
60 | + 'FHEE__EventEspresso_core_services_graphql_InputCollection__loadCollection__collection_FQCNs', |
|
61 | + ['EventEspresso\core\domain\services\graphql\inputs'] |
|
62 | + ), |
|
63 | + // filepaths to classes to add |
|
64 | + array(), |
|
65 | + // file mask to use if parsing folder for files to add |
|
66 | + '', |
|
67 | + // what to use as identifier for collection entities |
|
68 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | + CollectionDetails::ID_CLASS_NAME |
|
70 | + ), |
|
71 | + $this |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @return CollectionInterface |
|
79 | - * @throws CollectionDetailsException |
|
80 | - * @throws CollectionLoaderException |
|
81 | - * @since 5.0.0.p |
|
82 | - */ |
|
83 | - public function loadInputs() |
|
84 | - { |
|
85 | - $this->loadCollection(); |
|
86 | - return $this->loader->getCollection(); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return CollectionInterface |
|
79 | + * @throws CollectionDetailsException |
|
80 | + * @throws CollectionLoaderException |
|
81 | + * @since 5.0.0.p |
|
82 | + */ |
|
83 | + public function loadInputs() |
|
84 | + { |
|
85 | + $this->loadCollection(); |
|
86 | + return $this->loader->getCollection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * getIdentifier |
|
92 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | - * |
|
95 | - * @param $object |
|
96 | - * @param mixed $identifier |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function getIdentifier($object, $identifier = null) |
|
100 | - { |
|
101 | - return ! empty($identifier) |
|
102 | - ? $identifier |
|
103 | - : get_class($object); |
|
104 | - } |
|
90 | + /** |
|
91 | + * getIdentifier |
|
92 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | + * |
|
95 | + * @param $object |
|
96 | + * @param mixed $identifier |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function getIdentifier($object, $identifier = null) |
|
100 | + { |
|
101 | + return ! empty($identifier) |
|
102 | + ? $identifier |
|
103 | + : get_class($object); |
|
104 | + } |
|
105 | 105 | } |