@@ -15,173 +15,173 @@ |
||
| 15 | 15 | class FormLabel implements JsonableInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var JsonDataHandler |
|
| 20 | - */ |
|
| 21 | - private $json_data_handler; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Input label displayed in the admin to help differentiate input from others |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - private $adminLabel; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Input label displayed on public forms, ie: the actual question text. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - private $publicLabel; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var bool |
|
| 39 | - */ |
|
| 40 | - private $showLabel; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The HTML block displayed for block elements. |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - private $html; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * FormLabel constructor. |
|
| 52 | - * |
|
| 53 | - * @param JsonDataHandler $json_data_handler |
|
| 54 | - * @param string $adminLabel |
|
| 55 | - * @param string $publicLabel |
|
| 56 | - * @param bool $showLabel |
|
| 57 | - */ |
|
| 58 | - public function __construct( |
|
| 59 | - JsonDataHandler $json_data_handler, |
|
| 60 | - string $adminLabel, |
|
| 61 | - string $publicLabel, |
|
| 62 | - bool $showLabel, |
|
| 63 | - string $html |
|
| 64 | - ) { |
|
| 65 | - $this->json_data_handler = $json_data_handler; |
|
| 66 | - $this->setAdminLabel($adminLabel); |
|
| 67 | - $this->setPublicLabel($publicLabel); |
|
| 68 | - $this->setShowLabel($showLabel); |
|
| 69 | - $this->setHtml($html); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param string $json |
|
| 75 | - * @return FormLabel |
|
| 76 | - */ |
|
| 77 | - public static function fromJson(string $json): FormLabel |
|
| 78 | - { |
|
| 79 | - $json_data_handler = new JsonDataHandler(); |
|
| 80 | - $json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT); |
|
| 81 | - $data = $json_data_handler->decodeJson($json); |
|
| 82 | - $adminLabel = $data->adminLabel ?? ''; |
|
| 83 | - $publicLabel = $data->publicLabel ?? ''; |
|
| 84 | - $showLabel = $data->showLabel ?? false; |
|
| 85 | - $html = $data->html ?? ''; |
|
| 86 | - return new FormLabel($json_data_handler, $adminLabel, $publicLabel, $showLabel, $html); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function toArray(): array |
|
| 94 | - { |
|
| 95 | - return [ |
|
| 96 | - 'adminLabel' => $this->adminLabel, |
|
| 97 | - 'publicLabel' => $this->publicLabel, |
|
| 98 | - 'showLabel' => $this->showLabel, |
|
| 99 | - 'html' => $this->html, |
|
| 100 | - ]; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return string |
|
| 106 | - */ |
|
| 107 | - public function toJson(): string |
|
| 108 | - { |
|
| 109 | - return $this->json_data_handler->encodeData($this->toArray()); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Input label displayed in the admin to help differentiate input from others |
|
| 115 | - * |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - public function adminLabel(): string |
|
| 119 | - { |
|
| 120 | - return $this->adminLabel; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param string $adminLabel |
|
| 126 | - */ |
|
| 127 | - public function setAdminLabel(string $adminLabel): void |
|
| 128 | - { |
|
| 129 | - $this->adminLabel = sanitize_title($adminLabel); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Input label displayed on public forms, ie: the actual question text. |
|
| 135 | - * |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - public function publicLabel(): string |
|
| 139 | - { |
|
| 140 | - return $this->publicLabel; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param string $publicLabel |
|
| 146 | - */ |
|
| 147 | - public function setPublicLabel(string $publicLabel): void |
|
| 148 | - { |
|
| 149 | - $this->publicLabel = sanitize_title($publicLabel); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - public function showLabel(): bool |
|
| 157 | - { |
|
| 158 | - return $this->showLabel; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param bool|int|string $showLabel |
|
| 164 | - */ |
|
| 165 | - public function setShowLabel($showLabel): void |
|
| 166 | - { |
|
| 167 | - $this->showLabel = filter_var($showLabel, FILTER_VALIDATE_BOOLEAN); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @return string |
|
| 173 | - */ |
|
| 174 | - public function html(): string |
|
| 175 | - { |
|
| 176 | - return $this->html; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @param string $html |
|
| 182 | - */ |
|
| 183 | - public function setHtml(string $html): void |
|
| 184 | - { |
|
| 185 | - $this->html = wp_kses_post($html); |
|
| 186 | - } |
|
| 18 | + /** |
|
| 19 | + * @var JsonDataHandler |
|
| 20 | + */ |
|
| 21 | + private $json_data_handler; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Input label displayed in the admin to help differentiate input from others |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + private $adminLabel; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Input label displayed on public forms, ie: the actual question text. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + private $publicLabel; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var bool |
|
| 39 | + */ |
|
| 40 | + private $showLabel; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The HTML block displayed for block elements. |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + private $html; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * FormLabel constructor. |
|
| 52 | + * |
|
| 53 | + * @param JsonDataHandler $json_data_handler |
|
| 54 | + * @param string $adminLabel |
|
| 55 | + * @param string $publicLabel |
|
| 56 | + * @param bool $showLabel |
|
| 57 | + */ |
|
| 58 | + public function __construct( |
|
| 59 | + JsonDataHandler $json_data_handler, |
|
| 60 | + string $adminLabel, |
|
| 61 | + string $publicLabel, |
|
| 62 | + bool $showLabel, |
|
| 63 | + string $html |
|
| 64 | + ) { |
|
| 65 | + $this->json_data_handler = $json_data_handler; |
|
| 66 | + $this->setAdminLabel($adminLabel); |
|
| 67 | + $this->setPublicLabel($publicLabel); |
|
| 68 | + $this->setShowLabel($showLabel); |
|
| 69 | + $this->setHtml($html); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param string $json |
|
| 75 | + * @return FormLabel |
|
| 76 | + */ |
|
| 77 | + public static function fromJson(string $json): FormLabel |
|
| 78 | + { |
|
| 79 | + $json_data_handler = new JsonDataHandler(); |
|
| 80 | + $json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT); |
|
| 81 | + $data = $json_data_handler->decodeJson($json); |
|
| 82 | + $adminLabel = $data->adminLabel ?? ''; |
|
| 83 | + $publicLabel = $data->publicLabel ?? ''; |
|
| 84 | + $showLabel = $data->showLabel ?? false; |
|
| 85 | + $html = $data->html ?? ''; |
|
| 86 | + return new FormLabel($json_data_handler, $adminLabel, $publicLabel, $showLabel, $html); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function toArray(): array |
|
| 94 | + { |
|
| 95 | + return [ |
|
| 96 | + 'adminLabel' => $this->adminLabel, |
|
| 97 | + 'publicLabel' => $this->publicLabel, |
|
| 98 | + 'showLabel' => $this->showLabel, |
|
| 99 | + 'html' => $this->html, |
|
| 100 | + ]; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return string |
|
| 106 | + */ |
|
| 107 | + public function toJson(): string |
|
| 108 | + { |
|
| 109 | + return $this->json_data_handler->encodeData($this->toArray()); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Input label displayed in the admin to help differentiate input from others |
|
| 115 | + * |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + public function adminLabel(): string |
|
| 119 | + { |
|
| 120 | + return $this->adminLabel; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param string $adminLabel |
|
| 126 | + */ |
|
| 127 | + public function setAdminLabel(string $adminLabel): void |
|
| 128 | + { |
|
| 129 | + $this->adminLabel = sanitize_title($adminLabel); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Input label displayed on public forms, ie: the actual question text. |
|
| 135 | + * |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + public function publicLabel(): string |
|
| 139 | + { |
|
| 140 | + return $this->publicLabel; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param string $publicLabel |
|
| 146 | + */ |
|
| 147 | + public function setPublicLabel(string $publicLabel): void |
|
| 148 | + { |
|
| 149 | + $this->publicLabel = sanitize_title($publicLabel); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + public function showLabel(): bool |
|
| 157 | + { |
|
| 158 | + return $this->showLabel; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param bool|int|string $showLabel |
|
| 164 | + */ |
|
| 165 | + public function setShowLabel($showLabel): void |
|
| 166 | + { |
|
| 167 | + $this->showLabel = filter_var($showLabel, FILTER_VALIDATE_BOOLEAN); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @return string |
|
| 173 | + */ |
|
| 174 | + public function html(): string |
|
| 175 | + { |
|
| 176 | + return $this->html; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @param string $html |
|
| 182 | + */ |
|
| 183 | + public function setHtml(string $html): void |
|
| 184 | + { |
|
| 185 | + $this->html = wp_kses_post($html); |
|
| 186 | + } |
|
| 187 | 187 | } |
@@ -17,196 +17,196 @@ |
||
| 17 | 17 | class Attributes implements JsonableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var JsonDataHandler |
|
| 22 | - */ |
|
| 23 | - private $json_data_handler; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var InputTypes |
|
| 27 | - */ |
|
| 28 | - private $input_types; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private $attributes = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - private $attribute_types = [ |
|
| 39 | - 'accept' => 'string', |
|
| 40 | - 'accesskey' => 'string', |
|
| 41 | - 'alt' => 'string', |
|
| 42 | - 'autocomplete' => 'bool', |
|
| 43 | - 'autofocus' => 'bool', |
|
| 44 | - 'checked' => 'bool', |
|
| 45 | - // Custom HTML classes to be applied to the form input's container |
|
| 46 | - 'class' => 'string', |
|
| 47 | - 'contenteditable' => 'bool', |
|
| 48 | - 'dir' => 'string', |
|
| 49 | - 'disabled' => 'bool', |
|
| 50 | - 'height' => 'string', |
|
| 51 | - 'hidden' => 'bool', |
|
| 52 | - 'id' => 'string', |
|
| 53 | - 'list' => 'string', |
|
| 54 | - // Maximum numeric value allowed for form input answer. |
|
| 55 | - 'max' => 'int', |
|
| 56 | - // Maximum characters allowed for form input answer. |
|
| 57 | - 'maxlength' => 'int', |
|
| 58 | - // Minimum numeric value allowed for form input answer. |
|
| 59 | - 'min' => 'int', |
|
| 60 | - 'multiple' => 'bool', |
|
| 61 | - 'name' => 'string', |
|
| 62 | - 'pattern' => 'string', |
|
| 63 | - // Example text displayed within an input to assist users with completing the form. |
|
| 64 | - 'placeholder' => 'string', |
|
| 65 | - 'readonly' => 'bool', |
|
| 66 | - 'size' => 'int', |
|
| 67 | - 'spellcheck' => 'bool', |
|
| 68 | - 'step' => 'float', |
|
| 69 | - 'style' => 'string', |
|
| 70 | - 'tabindex' => 'int', |
|
| 71 | - 'title' => 'string', |
|
| 72 | - 'translate' => 'bool', |
|
| 73 | - // Form input type. Values correspond to the Input::TYPE_* constants. |
|
| 74 | - 'type' => 'string', |
|
| 75 | - 'value' => 'string', |
|
| 76 | - 'width' => 'string', |
|
| 77 | - ]; |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Attributes constructor. |
|
| 82 | - * |
|
| 83 | - * @param JsonDataHandler $json_data_handler |
|
| 84 | - * @param InputTypes $element_types |
|
| 85 | - * @param array $attributes |
|
| 86 | - */ |
|
| 87 | - public function __construct(JsonDataHandler $json_data_handler, array $attributes, InputTypes $element_types) |
|
| 88 | - { |
|
| 89 | - $this->json_data_handler = $json_data_handler; |
|
| 90 | - $this->input_types = $element_types; |
|
| 91 | - $this->setAttributes($attributes); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @param string $json |
|
| 97 | - * @return Attributes |
|
| 98 | - */ |
|
| 99 | - public static function fromJson(string $json): Attributes |
|
| 100 | - { |
|
| 101 | - $json_data_handler = new JsonDataHandler(); |
|
| 102 | - $json_data_handler->configure(JsonDataHandler::DATA_TYPE_ARRAY); |
|
| 103 | - $attributes = $json_data_handler->decodeJson($json); |
|
| 104 | - /** @var InputTypes */ |
|
| 105 | - $element_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes'); |
|
| 106 | - return LoaderFactory::getNew(Attributes::class, [ $json_data_handler, $attributes, $element_types ]); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function toArray(): array |
|
| 114 | - { |
|
| 115 | - return $this->attributes(); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public function toJson(): string |
|
| 123 | - { |
|
| 124 | - return $this->json_data_handler->encodeData($this->attributes()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param string $attribute |
|
| 130 | - * @param bool|float|int|string $value |
|
| 131 | - * @return bool|float|int|string |
|
| 132 | - */ |
|
| 133 | - private function sanitize(string $attribute, $value) |
|
| 134 | - { |
|
| 135 | - if ($attribute === 'type') { |
|
| 136 | - $valid_types = $this->input_types->validTypeOptions(); |
|
| 137 | - return in_array($value, $valid_types, true) ?: Text::TYPE_TEXT; |
|
| 138 | - } |
|
| 139 | - $type = $this->attribute_types[ $attribute ] ?? 'string'; |
|
| 140 | - switch ($type) { |
|
| 141 | - case 'bool': |
|
| 142 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
| 143 | - case 'int': |
|
| 144 | - return filter_var($value, FILTER_SANITIZE_NUMBER_INT); |
|
| 145 | - case 'float': |
|
| 146 | - return filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 147 | - case 'string': |
|
| 148 | - default: |
|
| 149 | - return filter_var( |
|
| 150 | - $value, |
|
| 151 | - FILTER_SANITIZE_STRING, |
|
| 152 | - FILTER_FLAG_ENCODE_LOW | FILTER_FLAG_ENCODE_HIGH | FILTER_FLAG_ENCODE_AMP |
|
| 153 | - ); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Custom HTML classes to be applied to this form input's help text. |
|
| 160 | - * returns a concatenated string unless $as_array is set to true |
|
| 161 | - * |
|
| 162 | - * @return array |
|
| 163 | - */ |
|
| 164 | - public function attributes(): array |
|
| 165 | - { |
|
| 166 | - return $this->attributes; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $attribute |
|
| 172 | - * @param bool|float|int|string $value |
|
| 173 | - */ |
|
| 174 | - public function addAttribute(string $attribute, $value): void |
|
| 175 | - { |
|
| 176 | - if (array_key_exists($attribute, $this->attribute_types)) { |
|
| 177 | - $this->attributes[ $attribute ] = $this->sanitize($attribute, $value); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @param string $attribute |
|
| 184 | - * @return bool|float|int|string |
|
| 185 | - */ |
|
| 186 | - public function getAttribute(string $attribute) |
|
| 187 | - { |
|
| 188 | - return array_key_exists($attribute, $this->attributes) |
|
| 189 | - ? $this->attributes[ $attribute ] |
|
| 190 | - : $this->sanitize($attribute, null); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param string $attribute |
|
| 196 | - */ |
|
| 197 | - public function removeAttribute(string $attribute): void |
|
| 198 | - { |
|
| 199 | - unset($this->attributes[ $attribute ]); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param array $attributes array where keys are the attribute name and values are the attribute's value |
|
| 205 | - */ |
|
| 206 | - public function setAttributes(array $attributes): void |
|
| 207 | - { |
|
| 208 | - foreach ($attributes as $attribute => $value) { |
|
| 209 | - $this->addAttribute($attribute, $value); |
|
| 210 | - } |
|
| 211 | - } |
|
| 20 | + /** |
|
| 21 | + * @var JsonDataHandler |
|
| 22 | + */ |
|
| 23 | + private $json_data_handler; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var InputTypes |
|
| 27 | + */ |
|
| 28 | + private $input_types; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private $attributes = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + private $attribute_types = [ |
|
| 39 | + 'accept' => 'string', |
|
| 40 | + 'accesskey' => 'string', |
|
| 41 | + 'alt' => 'string', |
|
| 42 | + 'autocomplete' => 'bool', |
|
| 43 | + 'autofocus' => 'bool', |
|
| 44 | + 'checked' => 'bool', |
|
| 45 | + // Custom HTML classes to be applied to the form input's container |
|
| 46 | + 'class' => 'string', |
|
| 47 | + 'contenteditable' => 'bool', |
|
| 48 | + 'dir' => 'string', |
|
| 49 | + 'disabled' => 'bool', |
|
| 50 | + 'height' => 'string', |
|
| 51 | + 'hidden' => 'bool', |
|
| 52 | + 'id' => 'string', |
|
| 53 | + 'list' => 'string', |
|
| 54 | + // Maximum numeric value allowed for form input answer. |
|
| 55 | + 'max' => 'int', |
|
| 56 | + // Maximum characters allowed for form input answer. |
|
| 57 | + 'maxlength' => 'int', |
|
| 58 | + // Minimum numeric value allowed for form input answer. |
|
| 59 | + 'min' => 'int', |
|
| 60 | + 'multiple' => 'bool', |
|
| 61 | + 'name' => 'string', |
|
| 62 | + 'pattern' => 'string', |
|
| 63 | + // Example text displayed within an input to assist users with completing the form. |
|
| 64 | + 'placeholder' => 'string', |
|
| 65 | + 'readonly' => 'bool', |
|
| 66 | + 'size' => 'int', |
|
| 67 | + 'spellcheck' => 'bool', |
|
| 68 | + 'step' => 'float', |
|
| 69 | + 'style' => 'string', |
|
| 70 | + 'tabindex' => 'int', |
|
| 71 | + 'title' => 'string', |
|
| 72 | + 'translate' => 'bool', |
|
| 73 | + // Form input type. Values correspond to the Input::TYPE_* constants. |
|
| 74 | + 'type' => 'string', |
|
| 75 | + 'value' => 'string', |
|
| 76 | + 'width' => 'string', |
|
| 77 | + ]; |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Attributes constructor. |
|
| 82 | + * |
|
| 83 | + * @param JsonDataHandler $json_data_handler |
|
| 84 | + * @param InputTypes $element_types |
|
| 85 | + * @param array $attributes |
|
| 86 | + */ |
|
| 87 | + public function __construct(JsonDataHandler $json_data_handler, array $attributes, InputTypes $element_types) |
|
| 88 | + { |
|
| 89 | + $this->json_data_handler = $json_data_handler; |
|
| 90 | + $this->input_types = $element_types; |
|
| 91 | + $this->setAttributes($attributes); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param string $json |
|
| 97 | + * @return Attributes |
|
| 98 | + */ |
|
| 99 | + public static function fromJson(string $json): Attributes |
|
| 100 | + { |
|
| 101 | + $json_data_handler = new JsonDataHandler(); |
|
| 102 | + $json_data_handler->configure(JsonDataHandler::DATA_TYPE_ARRAY); |
|
| 103 | + $attributes = $json_data_handler->decodeJson($json); |
|
| 104 | + /** @var InputTypes */ |
|
| 105 | + $element_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes'); |
|
| 106 | + return LoaderFactory::getNew(Attributes::class, [ $json_data_handler, $attributes, $element_types ]); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function toArray(): array |
|
| 114 | + { |
|
| 115 | + return $this->attributes(); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public function toJson(): string |
|
| 123 | + { |
|
| 124 | + return $this->json_data_handler->encodeData($this->attributes()); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param string $attribute |
|
| 130 | + * @param bool|float|int|string $value |
|
| 131 | + * @return bool|float|int|string |
|
| 132 | + */ |
|
| 133 | + private function sanitize(string $attribute, $value) |
|
| 134 | + { |
|
| 135 | + if ($attribute === 'type') { |
|
| 136 | + $valid_types = $this->input_types->validTypeOptions(); |
|
| 137 | + return in_array($value, $valid_types, true) ?: Text::TYPE_TEXT; |
|
| 138 | + } |
|
| 139 | + $type = $this->attribute_types[ $attribute ] ?? 'string'; |
|
| 140 | + switch ($type) { |
|
| 141 | + case 'bool': |
|
| 142 | + return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
| 143 | + case 'int': |
|
| 144 | + return filter_var($value, FILTER_SANITIZE_NUMBER_INT); |
|
| 145 | + case 'float': |
|
| 146 | + return filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 147 | + case 'string': |
|
| 148 | + default: |
|
| 149 | + return filter_var( |
|
| 150 | + $value, |
|
| 151 | + FILTER_SANITIZE_STRING, |
|
| 152 | + FILTER_FLAG_ENCODE_LOW | FILTER_FLAG_ENCODE_HIGH | FILTER_FLAG_ENCODE_AMP |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Custom HTML classes to be applied to this form input's help text. |
|
| 160 | + * returns a concatenated string unless $as_array is set to true |
|
| 161 | + * |
|
| 162 | + * @return array |
|
| 163 | + */ |
|
| 164 | + public function attributes(): array |
|
| 165 | + { |
|
| 166 | + return $this->attributes; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $attribute |
|
| 172 | + * @param bool|float|int|string $value |
|
| 173 | + */ |
|
| 174 | + public function addAttribute(string $attribute, $value): void |
|
| 175 | + { |
|
| 176 | + if (array_key_exists($attribute, $this->attribute_types)) { |
|
| 177 | + $this->attributes[ $attribute ] = $this->sanitize($attribute, $value); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @param string $attribute |
|
| 184 | + * @return bool|float|int|string |
|
| 185 | + */ |
|
| 186 | + public function getAttribute(string $attribute) |
|
| 187 | + { |
|
| 188 | + return array_key_exists($attribute, $this->attributes) |
|
| 189 | + ? $this->attributes[ $attribute ] |
|
| 190 | + : $this->sanitize($attribute, null); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param string $attribute |
|
| 196 | + */ |
|
| 197 | + public function removeAttribute(string $attribute): void |
|
| 198 | + { |
|
| 199 | + unset($this->attributes[ $attribute ]); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param array $attributes array where keys are the attribute name and values are the attribute's value |
|
| 205 | + */ |
|
| 206 | + public function setAttributes(array $attributes): void |
|
| 207 | + { |
|
| 208 | + foreach ($attributes as $attribute => $value) { |
|
| 209 | + $this->addAttribute($attribute, $value); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $attributes = $json_data_handler->decodeJson($json); |
| 104 | 104 | /** @var InputTypes */ |
| 105 | 105 | $element_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes'); |
| 106 | - return LoaderFactory::getNew(Attributes::class, [ $json_data_handler, $attributes, $element_types ]); |
|
| 106 | + return LoaderFactory::getNew(Attributes::class, [$json_data_handler, $attributes, $element_types]); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $valid_types = $this->input_types->validTypeOptions(); |
| 137 | 137 | return in_array($value, $valid_types, true) ?: Text::TYPE_TEXT; |
| 138 | 138 | } |
| 139 | - $type = $this->attribute_types[ $attribute ] ?? 'string'; |
|
| 139 | + $type = $this->attribute_types[$attribute] ?? 'string'; |
|
| 140 | 140 | switch ($type) { |
| 141 | 141 | case 'bool': |
| 142 | 142 | return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | public function addAttribute(string $attribute, $value): void |
| 175 | 175 | { |
| 176 | 176 | if (array_key_exists($attribute, $this->attribute_types)) { |
| 177 | - $this->attributes[ $attribute ] = $this->sanitize($attribute, $value); |
|
| 177 | + $this->attributes[$attribute] = $this->sanitize($attribute, $value); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | public function getAttribute(string $attribute) |
| 187 | 187 | { |
| 188 | 188 | return array_key_exists($attribute, $this->attributes) |
| 189 | - ? $this->attributes[ $attribute ] |
|
| 189 | + ? $this->attributes[$attribute] |
|
| 190 | 190 | : $this->sanitize($attribute, null); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function removeAttribute(string $attribute): void |
| 198 | 198 | { |
| 199 | - unset($this->attributes[ $attribute ]); |
|
| 199 | + unset($this->attributes[$attribute]); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | |
@@ -23,614 +23,614 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | interface FormSectionProperInterface |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Finishes construction given the parent form section and this form section's name |
|
| 28 | - * |
|
| 29 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 30 | - * @param string $name |
|
| 31 | - * @throws EE_Error |
|
| 32 | - */ |
|
| 33 | - public function _construct_finalize($parent_form_section, $name); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Gets the layout strategy for this form section |
|
| 38 | - * |
|
| 39 | - * @return EE_Form_Section_Layout_Base |
|
| 40 | - */ |
|
| 41 | - public function get_layout_strategy(); |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Gets the HTML for a single input for this form section according |
|
| 46 | - * to the layout strategy |
|
| 47 | - * |
|
| 48 | - * @param EE_Form_Input_Base $input |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function get_html_for_input($input); |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * was_submitted - checks if form inputs are present in request data |
|
| 56 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 57 | - * proper form sections and form inputs) |
|
| 58 | - * |
|
| 59 | - * @param null $form_data |
|
| 60 | - * @return boolean |
|
| 61 | - * @throws EE_Error |
|
| 62 | - */ |
|
| 63 | - public function was_submitted($form_data = null); |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 68 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 69 | - * |
|
| 70 | - * @param array|null $req_data should usually be $_POST (the default). |
|
| 71 | - * However, you CAN supply a different array. |
|
| 72 | - * Consider using set_defaults() instead however. |
|
| 73 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 74 | - * the inputs will have the correct name in the request data for this function |
|
| 75 | - * to find them and populate the form with them. |
|
| 76 | - * If you have a flat form (with only input subsections), |
|
| 77 | - * you can supply a flat array where keys |
|
| 78 | - * are the form input names and values are their values) |
|
| 79 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 80 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 81 | - * But if the data has already been validated |
|
| 82 | - * (eg you validated the data then stored it in the DB) |
|
| 83 | - * you may want to skip this step. |
|
| 84 | - * @throws InvalidArgumentException |
|
| 85 | - * @throws InvalidInterfaceException |
|
| 86 | - * @throws InvalidDataTypeException |
|
| 87 | - * @throws EE_Error |
|
| 88 | - */ |
|
| 89 | - public function receive_form_submission($req_data = null, $validate = true); |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Populates this form and its subsections with data from the session. |
|
| 94 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 95 | - * validation errors when displaying too) |
|
| 96 | - * Returns true if the form was populated from the session, false otherwise |
|
| 97 | - * |
|
| 98 | - * @return boolean |
|
| 99 | - * @throws InvalidArgumentException |
|
| 100 | - * @throws InvalidInterfaceException |
|
| 101 | - * @throws InvalidDataTypeException |
|
| 102 | - * @throws EE_Error |
|
| 103 | - */ |
|
| 104 | - public function populate_from_session(); |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Populates the default data for the form, given an array where keys are |
|
| 109 | - * the input names, and values are their values (preferably normalized to be their |
|
| 110 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 111 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 112 | - * the value being an array formatted in teh same way |
|
| 113 | - * |
|
| 114 | - * @param array $default_data |
|
| 115 | - * @throws EE_Error |
|
| 116 | - */ |
|
| 117 | - public function populate_defaults($default_data); |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * returns true if subsection exists |
|
| 122 | - * |
|
| 123 | - * @param string $name |
|
| 124 | - * @return boolean |
|
| 125 | - */ |
|
| 126 | - public function subsection_exists($name); |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Gets the subsection specified by its name |
|
| 131 | - * |
|
| 132 | - * @param string $name |
|
| 133 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 134 | - * so that the inputs will be properly configured. |
|
| 135 | - * However, some client code may be ok |
|
| 136 | - * with construction finalize being called later |
|
| 137 | - * (realizing that the subsections' html names |
|
| 138 | - * might not be set yet, etc.) |
|
| 139 | - * @return EE_Form_Section_Base |
|
| 140 | - * @throws EE_Error |
|
| 141 | - */ |
|
| 142 | - public function get_subsection($name, $require_construction_to_be_finalized = true); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Gets all the validatable subsections of this form section |
|
| 147 | - * |
|
| 148 | - * @return EE_Form_Section_Validatable[] |
|
| 149 | - * @throws EE_Error |
|
| 150 | - */ |
|
| 151 | - public function get_validatable_subsections(); |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 156 | - * throw an EE_Error. |
|
| 157 | - * |
|
| 158 | - * @param string $name |
|
| 159 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 160 | - * leave this as TRUE so that the inputs will be properly |
|
| 161 | - * configured. However, some client code may be ok with |
|
| 162 | - * construction finalize being called later |
|
| 163 | - * (realizing that the subsections' html names might not be |
|
| 164 | - * set yet, etc.) |
|
| 165 | - * @return EE_Form_Input_Base |
|
| 166 | - * @throws EE_Error |
|
| 167 | - */ |
|
| 168 | - public function get_input($name, $require_construction_to_be_finalized = true); |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 173 | - * otherwise throws an EE_Error |
|
| 174 | - * |
|
| 175 | - * @param string $name |
|
| 176 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 177 | - * leave this as TRUE so that the inputs will be properly |
|
| 178 | - * configured. However, some client code may be ok with |
|
| 179 | - * construction finalize being called later |
|
| 180 | - * (realizing that the subsections' html names might not be |
|
| 181 | - * set yet, etc.) |
|
| 182 | - * @return EE_Form_Section_Proper |
|
| 183 | - * @throws EE_Error |
|
| 184 | - */ |
|
| 185 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true); |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 190 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 191 | - * |
|
| 192 | - * @param string $name |
|
| 193 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - public function get_input_value($name); |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 201 | - * |
|
| 202 | - * @return boolean |
|
| 203 | - * @throws EE_Error |
|
| 204 | - */ |
|
| 205 | - public function is_valid(); |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 210 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 211 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 212 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 213 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 214 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 215 | - * any CSS. |
|
| 216 | - * |
|
| 217 | - * @throws InvalidArgumentException |
|
| 218 | - * @throws InvalidInterfaceException |
|
| 219 | - * @throws InvalidDataTypeException |
|
| 220 | - * @throws EE_Error |
|
| 221 | - */ |
|
| 222 | - public function get_html_and_js(); |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 227 | - * |
|
| 228 | - * @param bool $display_previously_submitted_data |
|
| 229 | - * @return string |
|
| 230 | - * @throws InvalidArgumentException |
|
| 231 | - * @throws InvalidInterfaceException |
|
| 232 | - * @throws InvalidDataTypeException |
|
| 233 | - * @throws EE_Error |
|
| 234 | - * @throws EE_Error |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - public function get_html($display_previously_submitted_data = true); |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * enqueues JS and CSS for the form. |
|
| 242 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 243 | - * scripts and styles can be put in the header, but if called later |
|
| 244 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 245 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 246 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 247 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 248 | - * |
|
| 249 | - * @return void |
|
| 250 | - * @throws EE_Error |
|
| 251 | - */ |
|
| 252 | - public function enqueue_js(); |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * gets the variables used by form_section_validation.js. |
|
| 257 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 258 | - * but before the wordpress hook wp_loaded |
|
| 259 | - * |
|
| 260 | - * @throws EE_Error |
|
| 261 | - */ |
|
| 262 | - public function _enqueue_and_localize_form_js(); |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * add our form section data to a static variable accessible by all form sections |
|
| 267 | - * |
|
| 268 | - * @param bool $return_for_subsection |
|
| 269 | - * @return void |
|
| 270 | - * @throws EE_Error |
|
| 271 | - */ |
|
| 272 | - public function localize_validation_rules($return_for_subsection = false); |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 277 | - * This is primarily data added by inputs and forms in addition to any |
|
| 278 | - * scripts they might enqueue |
|
| 279 | - * |
|
| 280 | - * @param array $form_other_js_data |
|
| 281 | - * @return array |
|
| 282 | - * @throws EE_Error |
|
| 283 | - */ |
|
| 284 | - public function get_other_js_data($form_other_js_data = []); |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 289 | - * Keys are their form names, and values are the inputs themselves |
|
| 290 | - * |
|
| 291 | - * @return EE_Form_Input_Base |
|
| 292 | - * @throws EE_Error |
|
| 293 | - */ |
|
| 294 | - public function inputs_in_subsections(); |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Gets a flat array of all the validation errors. |
|
| 299 | - * Keys are html names (because those should be unique) |
|
| 300 | - * and values are a string of all their validation errors |
|
| 301 | - * |
|
| 302 | - * @return string[] |
|
| 303 | - * @throws EE_Error |
|
| 304 | - */ |
|
| 305 | - public function subsection_validation_errors_by_html_name(); |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * ensure_scripts_localized |
|
| 310 | - * |
|
| 311 | - * @throws EE_Error |
|
| 312 | - */ |
|
| 313 | - public function ensure_scripts_localized(); |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 318 | - * See parent function for more... |
|
| 319 | - * |
|
| 320 | - * @return array |
|
| 321 | - * @throws EE_Error |
|
| 322 | - */ |
|
| 323 | - public function get_jquery_validation_rules(); |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Gets all the validated inputs for the form section |
|
| 328 | - * |
|
| 329 | - * @return array |
|
| 330 | - * @throws EE_Error |
|
| 331 | - */ |
|
| 332 | - public function valid_data(); |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Gets all the inputs on this form section |
|
| 337 | - * |
|
| 338 | - * @return EE_Form_Input_Base[] |
|
| 339 | - * @throws EE_Error |
|
| 340 | - */ |
|
| 341 | - public function inputs(); |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Gets all the subsections which are a proper form |
|
| 346 | - * |
|
| 347 | - * @return EE_Form_Section_Proper[] |
|
| 348 | - * @throws EE_Error |
|
| 349 | - */ |
|
| 350 | - public function subforms(); |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 355 | - * Consider using inputs() or subforms() |
|
| 356 | - * if you only want form inputs or proper form sections. |
|
| 357 | - * |
|
| 358 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 359 | - * leave this as TRUE so that the inputs will be properly |
|
| 360 | - * configured. However, some client code may be ok with |
|
| 361 | - * construction finalize being called later |
|
| 362 | - * (realizing that the subsections' html names might not be |
|
| 363 | - * set yet, etc.) |
|
| 364 | - * @return EE_Form_Section_Proper[] |
|
| 365 | - * @throws EE_Error |
|
| 366 | - */ |
|
| 367 | - public function subsections($require_construction_to_be_finalized = true); |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Returns whether this form has any subforms or inputs |
|
| 372 | - * |
|
| 373 | - * @return bool |
|
| 374 | - */ |
|
| 375 | - public function hasSubsections(); |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 380 | - * values. (Similar to calling get_input_value on inputs) |
|
| 381 | - * |
|
| 382 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 383 | - * or just this forms' direct children inputs |
|
| 384 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 385 | - * or allow multidimensional array |
|
| 386 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 387 | - * with array keys being input names |
|
| 388 | - * (regardless of whether they are from a subsection or not), |
|
| 389 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 390 | - * where keys are always subsection names and values are either |
|
| 391 | - * the input's normalized value, or an array like the top-level array |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function input_values($include_subform_inputs = false, $flatten = false); |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 399 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 400 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 401 | - * where keys are the input names, and values are their display values |
|
| 402 | - * |
|
| 403 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 404 | - * or just this forms' direct children inputs |
|
| 405 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 406 | - * or allow multidimensional array |
|
| 407 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 408 | - * with array keys being input names |
|
| 409 | - * (regardless of whether they are from a subsection or not), |
|
| 410 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 411 | - * where keys are always subsection names and values are either |
|
| 412 | - * the input's normalized value, or an array like the top-level array |
|
| 413 | - * @throws EE_Error |
|
| 414 | - */ |
|
| 415 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false); |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Gets the input values from the form |
|
| 420 | - * |
|
| 421 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 422 | - * or just the normalized value |
|
| 423 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 424 | - * or just this forms' direct children inputs |
|
| 425 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 426 | - * or allow multidimensional array |
|
| 427 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 428 | - * input names (regardless of whether they are from a subsection or not), |
|
| 429 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 430 | - * where keys are always subsection names and values are either |
|
| 431 | - * the input's normalized value, or an array like the top-level array |
|
| 432 | - * @throws EE_Error |
|
| 433 | - */ |
|
| 434 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false); |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Gets the originally submitted input values from the form |
|
| 439 | - * |
|
| 440 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 441 | - * or just this forms' direct children inputs |
|
| 442 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 443 | - * with array keys being input names |
|
| 444 | - * (regardless of whether they are from a subsection or not), |
|
| 445 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 446 | - * where keys are always subsection names and values are either |
|
| 447 | - * the input's normalized value, or an array like the top-level array |
|
| 448 | - * @throws EE_Error |
|
| 449 | - */ |
|
| 450 | - public function submitted_values($include_subforms = false); |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Indicates whether or not this form has received a submission yet |
|
| 455 | - * (ie, had receive_form_submission called on it yet) |
|
| 456 | - * |
|
| 457 | - * @return boolean |
|
| 458 | - * @throws EE_Error |
|
| 459 | - */ |
|
| 460 | - public function has_received_submission(); |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 465 | - * Removes the listed inputs from the form |
|
| 466 | - * |
|
| 467 | - * @param array $inputs_to_exclude values are the input names |
|
| 468 | - * @return void |
|
| 469 | - */ |
|
| 470 | - public function exclude(array $inputs_to_exclude = []); |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 475 | - * |
|
| 476 | - * @param array $inputs_to_hide |
|
| 477 | - * @throws EE_Error |
|
| 478 | - */ |
|
| 479 | - public function hide(array $inputs_to_hide = []); |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * add_subsections |
|
| 484 | - * Adds the listed subsections to the form section. |
|
| 485 | - * If $subsection_name_to_target is provided, |
|
| 486 | - * then new subsections are added before or after that subsection, |
|
| 487 | - * otherwise to the start or end of the entire subsections array. |
|
| 488 | - * |
|
| 489 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 490 | - * where keys are their names |
|
| 491 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 492 | - * should be added before or after |
|
| 493 | - * IF $subsection_name_to_target is null, |
|
| 494 | - * then $new_subsections will be added to |
|
| 495 | - * the beginning or end of the entire subsections array |
|
| 496 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 497 | - * $subsection_name_to_target, |
|
| 498 | - * or if $subsection_name_to_target is null, |
|
| 499 | - * before or after entire subsections array |
|
| 500 | - * @return void |
|
| 501 | - * @throws EE_Error |
|
| 502 | - */ |
|
| 503 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true); |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @param string $subsection_name |
|
| 508 | - * @param bool $recursive |
|
| 509 | - * @return bool |
|
| 510 | - */ |
|
| 511 | - public function has_subsection($subsection_name, $recursive = false); |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 516 | - * |
|
| 517 | - * @throws EE_Error |
|
| 518 | - */ |
|
| 519 | - public function clean_sensitive_data(); |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 524 | - * |
|
| 525 | - * @param string $form_submission_error_message |
|
| 526 | - * @param EE_Form_Section_Validatable $form_section unused |
|
| 527 | - * @throws EE_Error |
|
| 528 | - */ |
|
| 529 | - public function set_submission_error_message($form_submission_error_message = ''); |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
| 534 | - * (called during receive_form_submission) but it can be explicitly set using |
|
| 535 | - * set_submission_error_message |
|
| 536 | - * |
|
| 537 | - * @return string |
|
| 538 | - */ |
|
| 539 | - public function submission_error_message(); |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Sets a message to display if the data submitted to the form was valid. |
|
| 544 | - * |
|
| 545 | - * @param string $form_submission_success_message |
|
| 546 | - */ |
|
| 547 | - public function set_submission_success_message($form_submission_success_message = ''); |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Gets a message appropriate for display when the form is correctly submitted |
|
| 552 | - * |
|
| 553 | - * @return string |
|
| 554 | - */ |
|
| 555 | - public function submission_success_message(); |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Returns the prefix that should be used on child of this form section for |
|
| 560 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 561 | - * prefix onto this form section's prefix. Used primarily by |
|
| 562 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 563 | - * |
|
| 564 | - * @return string |
|
| 565 | - * @throws EE_Error |
|
| 566 | - */ |
|
| 567 | - public function html_name_prefix(); |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 572 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 573 | - * was set, which is probably nothing, or the classname) |
|
| 574 | - * |
|
| 575 | - * @return string |
|
| 576 | - * @throws EE_Error |
|
| 577 | - */ |
|
| 578 | - public function name(); |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @return EE_Form_Section_Proper |
|
| 583 | - * @throws EE_Error |
|
| 584 | - */ |
|
| 585 | - public function parent_section(); |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 590 | - * |
|
| 591 | - * @return void |
|
| 592 | - * @throws EE_Error |
|
| 593 | - */ |
|
| 594 | - public function ensure_construct_finalized_called(); |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 599 | - * are in teh form data. If any are found, returns true. Else false |
|
| 600 | - * |
|
| 601 | - * @param array $req_data |
|
| 602 | - * @return boolean |
|
| 603 | - * @throws EE_Error |
|
| 604 | - */ |
|
| 605 | - public function form_data_present_in($req_data = null); |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Gets validation errors for this form section and subsections |
|
| 610 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 611 | - * gets the validation errors for ALL subsection |
|
| 612 | - * |
|
| 613 | - * @return EE_Validation_Error[] |
|
| 614 | - * @throws EE_Error |
|
| 615 | - */ |
|
| 616 | - public function get_validation_errors_accumulated(); |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 621 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 622 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 623 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 624 | - * which will be returned. |
|
| 625 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 626 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 627 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 628 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 629 | - * Etc |
|
| 630 | - * |
|
| 631 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 632 | - * @return EE_Form_Section_Base |
|
| 633 | - * @throws EE_Error |
|
| 634 | - */ |
|
| 635 | - public function find_section_from_path($form_section_path); |
|
| 26 | + /** |
|
| 27 | + * Finishes construction given the parent form section and this form section's name |
|
| 28 | + * |
|
| 29 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 30 | + * @param string $name |
|
| 31 | + * @throws EE_Error |
|
| 32 | + */ |
|
| 33 | + public function _construct_finalize($parent_form_section, $name); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Gets the layout strategy for this form section |
|
| 38 | + * |
|
| 39 | + * @return EE_Form_Section_Layout_Base |
|
| 40 | + */ |
|
| 41 | + public function get_layout_strategy(); |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Gets the HTML for a single input for this form section according |
|
| 46 | + * to the layout strategy |
|
| 47 | + * |
|
| 48 | + * @param EE_Form_Input_Base $input |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function get_html_for_input($input); |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * was_submitted - checks if form inputs are present in request data |
|
| 56 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 57 | + * proper form sections and form inputs) |
|
| 58 | + * |
|
| 59 | + * @param null $form_data |
|
| 60 | + * @return boolean |
|
| 61 | + * @throws EE_Error |
|
| 62 | + */ |
|
| 63 | + public function was_submitted($form_data = null); |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 68 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 69 | + * |
|
| 70 | + * @param array|null $req_data should usually be $_POST (the default). |
|
| 71 | + * However, you CAN supply a different array. |
|
| 72 | + * Consider using set_defaults() instead however. |
|
| 73 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 74 | + * the inputs will have the correct name in the request data for this function |
|
| 75 | + * to find them and populate the form with them. |
|
| 76 | + * If you have a flat form (with only input subsections), |
|
| 77 | + * you can supply a flat array where keys |
|
| 78 | + * are the form input names and values are their values) |
|
| 79 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 80 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 81 | + * But if the data has already been validated |
|
| 82 | + * (eg you validated the data then stored it in the DB) |
|
| 83 | + * you may want to skip this step. |
|
| 84 | + * @throws InvalidArgumentException |
|
| 85 | + * @throws InvalidInterfaceException |
|
| 86 | + * @throws InvalidDataTypeException |
|
| 87 | + * @throws EE_Error |
|
| 88 | + */ |
|
| 89 | + public function receive_form_submission($req_data = null, $validate = true); |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Populates this form and its subsections with data from the session. |
|
| 94 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 95 | + * validation errors when displaying too) |
|
| 96 | + * Returns true if the form was populated from the session, false otherwise |
|
| 97 | + * |
|
| 98 | + * @return boolean |
|
| 99 | + * @throws InvalidArgumentException |
|
| 100 | + * @throws InvalidInterfaceException |
|
| 101 | + * @throws InvalidDataTypeException |
|
| 102 | + * @throws EE_Error |
|
| 103 | + */ |
|
| 104 | + public function populate_from_session(); |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Populates the default data for the form, given an array where keys are |
|
| 109 | + * the input names, and values are their values (preferably normalized to be their |
|
| 110 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 111 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 112 | + * the value being an array formatted in teh same way |
|
| 113 | + * |
|
| 114 | + * @param array $default_data |
|
| 115 | + * @throws EE_Error |
|
| 116 | + */ |
|
| 117 | + public function populate_defaults($default_data); |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * returns true if subsection exists |
|
| 122 | + * |
|
| 123 | + * @param string $name |
|
| 124 | + * @return boolean |
|
| 125 | + */ |
|
| 126 | + public function subsection_exists($name); |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Gets the subsection specified by its name |
|
| 131 | + * |
|
| 132 | + * @param string $name |
|
| 133 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 134 | + * so that the inputs will be properly configured. |
|
| 135 | + * However, some client code may be ok |
|
| 136 | + * with construction finalize being called later |
|
| 137 | + * (realizing that the subsections' html names |
|
| 138 | + * might not be set yet, etc.) |
|
| 139 | + * @return EE_Form_Section_Base |
|
| 140 | + * @throws EE_Error |
|
| 141 | + */ |
|
| 142 | + public function get_subsection($name, $require_construction_to_be_finalized = true); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Gets all the validatable subsections of this form section |
|
| 147 | + * |
|
| 148 | + * @return EE_Form_Section_Validatable[] |
|
| 149 | + * @throws EE_Error |
|
| 150 | + */ |
|
| 151 | + public function get_validatable_subsections(); |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 156 | + * throw an EE_Error. |
|
| 157 | + * |
|
| 158 | + * @param string $name |
|
| 159 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 160 | + * leave this as TRUE so that the inputs will be properly |
|
| 161 | + * configured. However, some client code may be ok with |
|
| 162 | + * construction finalize being called later |
|
| 163 | + * (realizing that the subsections' html names might not be |
|
| 164 | + * set yet, etc.) |
|
| 165 | + * @return EE_Form_Input_Base |
|
| 166 | + * @throws EE_Error |
|
| 167 | + */ |
|
| 168 | + public function get_input($name, $require_construction_to_be_finalized = true); |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 173 | + * otherwise throws an EE_Error |
|
| 174 | + * |
|
| 175 | + * @param string $name |
|
| 176 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 177 | + * leave this as TRUE so that the inputs will be properly |
|
| 178 | + * configured. However, some client code may be ok with |
|
| 179 | + * construction finalize being called later |
|
| 180 | + * (realizing that the subsections' html names might not be |
|
| 181 | + * set yet, etc.) |
|
| 182 | + * @return EE_Form_Section_Proper |
|
| 183 | + * @throws EE_Error |
|
| 184 | + */ |
|
| 185 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true); |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 190 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 191 | + * |
|
| 192 | + * @param string $name |
|
| 193 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + public function get_input_value($name); |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 201 | + * |
|
| 202 | + * @return boolean |
|
| 203 | + * @throws EE_Error |
|
| 204 | + */ |
|
| 205 | + public function is_valid(); |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 210 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 211 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 212 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 213 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 214 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 215 | + * any CSS. |
|
| 216 | + * |
|
| 217 | + * @throws InvalidArgumentException |
|
| 218 | + * @throws InvalidInterfaceException |
|
| 219 | + * @throws InvalidDataTypeException |
|
| 220 | + * @throws EE_Error |
|
| 221 | + */ |
|
| 222 | + public function get_html_and_js(); |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 227 | + * |
|
| 228 | + * @param bool $display_previously_submitted_data |
|
| 229 | + * @return string |
|
| 230 | + * @throws InvalidArgumentException |
|
| 231 | + * @throws InvalidInterfaceException |
|
| 232 | + * @throws InvalidDataTypeException |
|
| 233 | + * @throws EE_Error |
|
| 234 | + * @throws EE_Error |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + public function get_html($display_previously_submitted_data = true); |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * enqueues JS and CSS for the form. |
|
| 242 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 243 | + * scripts and styles can be put in the header, but if called later |
|
| 244 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 245 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 246 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 247 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 248 | + * |
|
| 249 | + * @return void |
|
| 250 | + * @throws EE_Error |
|
| 251 | + */ |
|
| 252 | + public function enqueue_js(); |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * gets the variables used by form_section_validation.js. |
|
| 257 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 258 | + * but before the wordpress hook wp_loaded |
|
| 259 | + * |
|
| 260 | + * @throws EE_Error |
|
| 261 | + */ |
|
| 262 | + public function _enqueue_and_localize_form_js(); |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * add our form section data to a static variable accessible by all form sections |
|
| 267 | + * |
|
| 268 | + * @param bool $return_for_subsection |
|
| 269 | + * @return void |
|
| 270 | + * @throws EE_Error |
|
| 271 | + */ |
|
| 272 | + public function localize_validation_rules($return_for_subsection = false); |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 277 | + * This is primarily data added by inputs and forms in addition to any |
|
| 278 | + * scripts they might enqueue |
|
| 279 | + * |
|
| 280 | + * @param array $form_other_js_data |
|
| 281 | + * @return array |
|
| 282 | + * @throws EE_Error |
|
| 283 | + */ |
|
| 284 | + public function get_other_js_data($form_other_js_data = []); |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 289 | + * Keys are their form names, and values are the inputs themselves |
|
| 290 | + * |
|
| 291 | + * @return EE_Form_Input_Base |
|
| 292 | + * @throws EE_Error |
|
| 293 | + */ |
|
| 294 | + public function inputs_in_subsections(); |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Gets a flat array of all the validation errors. |
|
| 299 | + * Keys are html names (because those should be unique) |
|
| 300 | + * and values are a string of all their validation errors |
|
| 301 | + * |
|
| 302 | + * @return string[] |
|
| 303 | + * @throws EE_Error |
|
| 304 | + */ |
|
| 305 | + public function subsection_validation_errors_by_html_name(); |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * ensure_scripts_localized |
|
| 310 | + * |
|
| 311 | + * @throws EE_Error |
|
| 312 | + */ |
|
| 313 | + public function ensure_scripts_localized(); |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 318 | + * See parent function for more... |
|
| 319 | + * |
|
| 320 | + * @return array |
|
| 321 | + * @throws EE_Error |
|
| 322 | + */ |
|
| 323 | + public function get_jquery_validation_rules(); |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Gets all the validated inputs for the form section |
|
| 328 | + * |
|
| 329 | + * @return array |
|
| 330 | + * @throws EE_Error |
|
| 331 | + */ |
|
| 332 | + public function valid_data(); |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Gets all the inputs on this form section |
|
| 337 | + * |
|
| 338 | + * @return EE_Form_Input_Base[] |
|
| 339 | + * @throws EE_Error |
|
| 340 | + */ |
|
| 341 | + public function inputs(); |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Gets all the subsections which are a proper form |
|
| 346 | + * |
|
| 347 | + * @return EE_Form_Section_Proper[] |
|
| 348 | + * @throws EE_Error |
|
| 349 | + */ |
|
| 350 | + public function subforms(); |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 355 | + * Consider using inputs() or subforms() |
|
| 356 | + * if you only want form inputs or proper form sections. |
|
| 357 | + * |
|
| 358 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 359 | + * leave this as TRUE so that the inputs will be properly |
|
| 360 | + * configured. However, some client code may be ok with |
|
| 361 | + * construction finalize being called later |
|
| 362 | + * (realizing that the subsections' html names might not be |
|
| 363 | + * set yet, etc.) |
|
| 364 | + * @return EE_Form_Section_Proper[] |
|
| 365 | + * @throws EE_Error |
|
| 366 | + */ |
|
| 367 | + public function subsections($require_construction_to_be_finalized = true); |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Returns whether this form has any subforms or inputs |
|
| 372 | + * |
|
| 373 | + * @return bool |
|
| 374 | + */ |
|
| 375 | + public function hasSubsections(); |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 380 | + * values. (Similar to calling get_input_value on inputs) |
|
| 381 | + * |
|
| 382 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 383 | + * or just this forms' direct children inputs |
|
| 384 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 385 | + * or allow multidimensional array |
|
| 386 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 387 | + * with array keys being input names |
|
| 388 | + * (regardless of whether they are from a subsection or not), |
|
| 389 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 390 | + * where keys are always subsection names and values are either |
|
| 391 | + * the input's normalized value, or an array like the top-level array |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function input_values($include_subform_inputs = false, $flatten = false); |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 399 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 400 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 401 | + * where keys are the input names, and values are their display values |
|
| 402 | + * |
|
| 403 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 404 | + * or just this forms' direct children inputs |
|
| 405 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 406 | + * or allow multidimensional array |
|
| 407 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 408 | + * with array keys being input names |
|
| 409 | + * (regardless of whether they are from a subsection or not), |
|
| 410 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 411 | + * where keys are always subsection names and values are either |
|
| 412 | + * the input's normalized value, or an array like the top-level array |
|
| 413 | + * @throws EE_Error |
|
| 414 | + */ |
|
| 415 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false); |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Gets the input values from the form |
|
| 420 | + * |
|
| 421 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 422 | + * or just the normalized value |
|
| 423 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 424 | + * or just this forms' direct children inputs |
|
| 425 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 426 | + * or allow multidimensional array |
|
| 427 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 428 | + * input names (regardless of whether they are from a subsection or not), |
|
| 429 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 430 | + * where keys are always subsection names and values are either |
|
| 431 | + * the input's normalized value, or an array like the top-level array |
|
| 432 | + * @throws EE_Error |
|
| 433 | + */ |
|
| 434 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false); |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Gets the originally submitted input values from the form |
|
| 439 | + * |
|
| 440 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 441 | + * or just this forms' direct children inputs |
|
| 442 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 443 | + * with array keys being input names |
|
| 444 | + * (regardless of whether they are from a subsection or not), |
|
| 445 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 446 | + * where keys are always subsection names and values are either |
|
| 447 | + * the input's normalized value, or an array like the top-level array |
|
| 448 | + * @throws EE_Error |
|
| 449 | + */ |
|
| 450 | + public function submitted_values($include_subforms = false); |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Indicates whether or not this form has received a submission yet |
|
| 455 | + * (ie, had receive_form_submission called on it yet) |
|
| 456 | + * |
|
| 457 | + * @return boolean |
|
| 458 | + * @throws EE_Error |
|
| 459 | + */ |
|
| 460 | + public function has_received_submission(); |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 465 | + * Removes the listed inputs from the form |
|
| 466 | + * |
|
| 467 | + * @param array $inputs_to_exclude values are the input names |
|
| 468 | + * @return void |
|
| 469 | + */ |
|
| 470 | + public function exclude(array $inputs_to_exclude = []); |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 475 | + * |
|
| 476 | + * @param array $inputs_to_hide |
|
| 477 | + * @throws EE_Error |
|
| 478 | + */ |
|
| 479 | + public function hide(array $inputs_to_hide = []); |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * add_subsections |
|
| 484 | + * Adds the listed subsections to the form section. |
|
| 485 | + * If $subsection_name_to_target is provided, |
|
| 486 | + * then new subsections are added before or after that subsection, |
|
| 487 | + * otherwise to the start or end of the entire subsections array. |
|
| 488 | + * |
|
| 489 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 490 | + * where keys are their names |
|
| 491 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 492 | + * should be added before or after |
|
| 493 | + * IF $subsection_name_to_target is null, |
|
| 494 | + * then $new_subsections will be added to |
|
| 495 | + * the beginning or end of the entire subsections array |
|
| 496 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 497 | + * $subsection_name_to_target, |
|
| 498 | + * or if $subsection_name_to_target is null, |
|
| 499 | + * before or after entire subsections array |
|
| 500 | + * @return void |
|
| 501 | + * @throws EE_Error |
|
| 502 | + */ |
|
| 503 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true); |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @param string $subsection_name |
|
| 508 | + * @param bool $recursive |
|
| 509 | + * @return bool |
|
| 510 | + */ |
|
| 511 | + public function has_subsection($subsection_name, $recursive = false); |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 516 | + * |
|
| 517 | + * @throws EE_Error |
|
| 518 | + */ |
|
| 519 | + public function clean_sensitive_data(); |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 524 | + * |
|
| 525 | + * @param string $form_submission_error_message |
|
| 526 | + * @param EE_Form_Section_Validatable $form_section unused |
|
| 527 | + * @throws EE_Error |
|
| 528 | + */ |
|
| 529 | + public function set_submission_error_message($form_submission_error_message = ''); |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
| 534 | + * (called during receive_form_submission) but it can be explicitly set using |
|
| 535 | + * set_submission_error_message |
|
| 536 | + * |
|
| 537 | + * @return string |
|
| 538 | + */ |
|
| 539 | + public function submission_error_message(); |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Sets a message to display if the data submitted to the form was valid. |
|
| 544 | + * |
|
| 545 | + * @param string $form_submission_success_message |
|
| 546 | + */ |
|
| 547 | + public function set_submission_success_message($form_submission_success_message = ''); |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Gets a message appropriate for display when the form is correctly submitted |
|
| 552 | + * |
|
| 553 | + * @return string |
|
| 554 | + */ |
|
| 555 | + public function submission_success_message(); |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Returns the prefix that should be used on child of this form section for |
|
| 560 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 561 | + * prefix onto this form section's prefix. Used primarily by |
|
| 562 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 563 | + * |
|
| 564 | + * @return string |
|
| 565 | + * @throws EE_Error |
|
| 566 | + */ |
|
| 567 | + public function html_name_prefix(); |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 572 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 573 | + * was set, which is probably nothing, or the classname) |
|
| 574 | + * |
|
| 575 | + * @return string |
|
| 576 | + * @throws EE_Error |
|
| 577 | + */ |
|
| 578 | + public function name(); |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @return EE_Form_Section_Proper |
|
| 583 | + * @throws EE_Error |
|
| 584 | + */ |
|
| 585 | + public function parent_section(); |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 590 | + * |
|
| 591 | + * @return void |
|
| 592 | + * @throws EE_Error |
|
| 593 | + */ |
|
| 594 | + public function ensure_construct_finalized_called(); |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 599 | + * are in teh form data. If any are found, returns true. Else false |
|
| 600 | + * |
|
| 601 | + * @param array $req_data |
|
| 602 | + * @return boolean |
|
| 603 | + * @throws EE_Error |
|
| 604 | + */ |
|
| 605 | + public function form_data_present_in($req_data = null); |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Gets validation errors for this form section and subsections |
|
| 610 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 611 | + * gets the validation errors for ALL subsection |
|
| 612 | + * |
|
| 613 | + * @return EE_Validation_Error[] |
|
| 614 | + * @throws EE_Error |
|
| 615 | + */ |
|
| 616 | + public function get_validation_errors_accumulated(); |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 621 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 622 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 623 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 624 | + * which will be returned. |
|
| 625 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 626 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 627 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 628 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 629 | + * Etc |
|
| 630 | + * |
|
| 631 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 632 | + * @return EE_Form_Section_Base |
|
| 633 | + * @throws EE_Error |
|
| 634 | + */ |
|
| 635 | + public function find_section_from_path($form_section_path); |
|
| 636 | 636 | } |
@@ -12,70 +12,70 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class JsonDataAPI |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var int |
|
| 17 | - */ |
|
| 18 | - protected $drill_down_depth; |
|
| 15 | + /** |
|
| 16 | + * @var int |
|
| 17 | + */ |
|
| 18 | + protected $drill_down_depth; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $json_data; |
|
| 20 | + /** |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $json_data; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var JsonDataHandler |
|
| 27 | - */ |
|
| 28 | - private $json_data_handler; |
|
| 25 | + /** |
|
| 26 | + * @var JsonDataHandler |
|
| 27 | + */ |
|
| 28 | + private $json_data_handler; |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param string $json_data JSON |
|
| 33 | - */ |
|
| 34 | - public function __construct(string $json_data, $drill_down_depth = 24) |
|
| 35 | - { |
|
| 36 | - $this->json_data_handler = new JsonDataHandler(); |
|
| 37 | - $this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_ARRAY); |
|
| 38 | - $this->json_data = $this->json_data_handler->decodeJson($json_data); |
|
| 39 | - $drill_down_depth = absint($drill_down_depth); |
|
| 40 | - $this->drill_down_depth = $drill_down_depth ?: 24; |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * @param string $json_data JSON |
|
| 33 | + */ |
|
| 34 | + public function __construct(string $json_data, $drill_down_depth = 24) |
|
| 35 | + { |
|
| 36 | + $this->json_data_handler = new JsonDataHandler(); |
|
| 37 | + $this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_ARRAY); |
|
| 38 | + $this->json_data = $this->json_data_handler->decodeJson($json_data); |
|
| 39 | + $drill_down_depth = absint($drill_down_depth); |
|
| 40 | + $this->drill_down_depth = $drill_down_depth ?: 24; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param string $path dot separated path (like object dot notation) ex: "path.to.deeply.nested.data" |
|
| 46 | - * @return mixed|null |
|
| 47 | - */ |
|
| 48 | - public function get(string $path) |
|
| 49 | - { |
|
| 50 | - return $this->drillDown(explode('.', $path), $this->json_data, $this->drill_down_depth); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * @param string $path dot separated path (like object dot notation) ex: "path.to.deeply.nested.data" |
|
| 46 | + * @return mixed|null |
|
| 47 | + */ |
|
| 48 | + public function get(string $path) |
|
| 49 | + { |
|
| 50 | + return $this->drillDown(explode('.', $path), $this->json_data, $this->drill_down_depth); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * recursively drills directly down through the array until the target is found, else null is returned |
|
| 56 | - * |
|
| 57 | - * @param array $keys path as an array of keys, ex: ["path", "to", "deeply", "nested", "data"] |
|
| 58 | - * @param array $data the data array at the current path position |
|
| 59 | - * @return mixed|null |
|
| 60 | - */ |
|
| 61 | - private function drillDown(array $keys, array $data, $depth) |
|
| 62 | - { |
|
| 63 | - $depth--; |
|
| 64 | - $key = array_shift($keys); |
|
| 65 | - if ($key === null || ! array_key_exists($key, $data)) { |
|
| 66 | - return null; |
|
| 67 | - } |
|
| 68 | - return $depth > 0 && count($keys) |
|
| 69 | - ? $this->drillDown($keys, $data[ $key ], $depth) |
|
| 70 | - : $data[ $key ]; |
|
| 71 | - } |
|
| 54 | + /** |
|
| 55 | + * recursively drills directly down through the array until the target is found, else null is returned |
|
| 56 | + * |
|
| 57 | + * @param array $keys path as an array of keys, ex: ["path", "to", "deeply", "nested", "data"] |
|
| 58 | + * @param array $data the data array at the current path position |
|
| 59 | + * @return mixed|null |
|
| 60 | + */ |
|
| 61 | + private function drillDown(array $keys, array $data, $depth) |
|
| 62 | + { |
|
| 63 | + $depth--; |
|
| 64 | + $key = array_shift($keys); |
|
| 65 | + if ($key === null || ! array_key_exists($key, $data)) { |
|
| 66 | + return null; |
|
| 67 | + } |
|
| 68 | + return $depth > 0 && count($keys) |
|
| 69 | + ? $this->drillDown($keys, $data[ $key ], $depth) |
|
| 70 | + : $data[ $key ]; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - public function jsonData(): array |
|
| 78 | - { |
|
| 79 | - return $this->json_data; |
|
| 80 | - } |
|
| 74 | + /** |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + public function jsonData(): array |
|
| 78 | + { |
|
| 79 | + return $this->json_data; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -66,8 +66,8 @@ |
||
| 66 | 66 | return null; |
| 67 | 67 | } |
| 68 | 68 | return $depth > 0 && count($keys) |
| 69 | - ? $this->drillDown($keys, $data[ $key ], $depth) |
|
| 70 | - : $data[ $key ]; |
|
| 69 | + ? $this->drillDown($keys, $data[$key], $depth) |
|
| 70 | + : $data[$key]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | |
@@ -5,153 +5,153 @@ |
||
| 5 | 5 | class EE_Form_Submission extends EE_Base_Class |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @param array $props_n_values |
|
| 10 | - * @return EE_Form_Submission |
|
| 11 | - * @throws EE_Error |
|
| 12 | - * @throws ReflectionException |
|
| 13 | - */ |
|
| 14 | - public static function new_instance(array $props_n_values = []): EE_Form_Submission |
|
| 15 | - { |
|
| 16 | - $props_n_values['FSB_submitted'] = new DateTime(); |
|
| 17 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 18 | - return $has_object ?: new self($props_n_values); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @param array $props_n_values |
|
| 24 | - * @return EE_Form_Submission |
|
| 25 | - * @throws EE_Error |
|
| 26 | - * @throws ReflectionException |
|
| 27 | - */ |
|
| 28 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Submission |
|
| 29 | - { |
|
| 30 | - return new self($props_n_values, true); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Form Section UUID (universally unique identifier) |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - * @throws EE_Error |
|
| 39 | - * @throws ReflectionException |
|
| 40 | - */ |
|
| 41 | - public function UUID(): string |
|
| 42 | - { |
|
| 43 | - return $this->get('FSB_UUID'); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param string $UUID |
|
| 49 | - * @throws EE_Error |
|
| 50 | - * @throws ReflectionException |
|
| 51 | - */ |
|
| 52 | - public function setUUID(string $UUID) |
|
| 53 | - { |
|
| 54 | - $this->set('FSB_UUID', $UUID); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * UUID or ID of related entity this form submission belongs to. |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - * @throws EE_Error |
|
| 63 | - * @throws ReflectionException |
|
| 64 | - */ |
|
| 65 | - public function formSection(): string |
|
| 66 | - { |
|
| 67 | - return $this->get('FSC_UUID'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param string $form_section_UUID |
|
| 73 | - * @throws EE_Error |
|
| 74 | - * @throws ReflectionException |
|
| 75 | - */ |
|
| 76 | - public function setFormSection(string $form_section_UUID) |
|
| 77 | - { |
|
| 78 | - $this->set('FSC_UUID', $form_section_UUID); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Returns the related EE_Transaction this form submission belongs to. |
|
| 84 | - * |
|
| 85 | - * @return EE_Transaction |
|
| 86 | - * @throws EE_Error |
|
| 87 | - * @throws EntityNotFoundException |
|
| 88 | - * @throws ReflectionException |
|
| 89 | - */ |
|
| 90 | - public function transaction(): EE_Transaction |
|
| 91 | - { |
|
| 92 | - $transaction = $this->get_first_related('Transaction'); |
|
| 93 | - if (! $transaction instanceof EE_Transaction) { |
|
| 94 | - throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
|
| 95 | - } |
|
| 96 | - return $transaction; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return int |
|
| 102 | - * @throws EE_Error |
|
| 103 | - * @throws ReflectionException |
|
| 104 | - */ |
|
| 105 | - public function transactionID(): int |
|
| 106 | - { |
|
| 107 | - return $this->get('TXN_ID'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param int $TXN_ID |
|
| 113 | - * @throws EE_Error |
|
| 114 | - * @throws ReflectionException |
|
| 115 | - */ |
|
| 116 | - public function setTransactionID(int $TXN_ID = 0) |
|
| 117 | - { |
|
| 118 | - $this->set('TXN_ID', $TXN_ID); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return string |
|
| 124 | - * @throws EE_Error |
|
| 125 | - * @throws ReflectionException |
|
| 126 | - */ |
|
| 127 | - public function data(): string |
|
| 128 | - { |
|
| 129 | - $form_data = $this->get('FSB_data'); |
|
| 130 | - return ! empty($form_data) ? $form_data : '{}'; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param array|string $data |
|
| 136 | - * @throws EE_Error |
|
| 137 | - * @throws ReflectionException |
|
| 138 | - */ |
|
| 139 | - public function setData($data) |
|
| 140 | - { |
|
| 141 | - $this->set('FSB_data', $data); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param bool $raw |
|
| 147 | - * @return int |
|
| 148 | - * @throws EE_Error |
|
| 149 | - * @throws ReflectionException |
|
| 150 | - */ |
|
| 151 | - public function submitted(bool $raw = false): int |
|
| 152 | - { |
|
| 153 | - return $raw |
|
| 154 | - ? $this->get_raw('FSB_submitted') |
|
| 155 | - : $this->get('FSB_submitted'); |
|
| 156 | - } |
|
| 8 | + /** |
|
| 9 | + * @param array $props_n_values |
|
| 10 | + * @return EE_Form_Submission |
|
| 11 | + * @throws EE_Error |
|
| 12 | + * @throws ReflectionException |
|
| 13 | + */ |
|
| 14 | + public static function new_instance(array $props_n_values = []): EE_Form_Submission |
|
| 15 | + { |
|
| 16 | + $props_n_values['FSB_submitted'] = new DateTime(); |
|
| 17 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 18 | + return $has_object ?: new self($props_n_values); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param array $props_n_values |
|
| 24 | + * @return EE_Form_Submission |
|
| 25 | + * @throws EE_Error |
|
| 26 | + * @throws ReflectionException |
|
| 27 | + */ |
|
| 28 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Submission |
|
| 29 | + { |
|
| 30 | + return new self($props_n_values, true); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Form Section UUID (universally unique identifier) |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + * @throws EE_Error |
|
| 39 | + * @throws ReflectionException |
|
| 40 | + */ |
|
| 41 | + public function UUID(): string |
|
| 42 | + { |
|
| 43 | + return $this->get('FSB_UUID'); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param string $UUID |
|
| 49 | + * @throws EE_Error |
|
| 50 | + * @throws ReflectionException |
|
| 51 | + */ |
|
| 52 | + public function setUUID(string $UUID) |
|
| 53 | + { |
|
| 54 | + $this->set('FSB_UUID', $UUID); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * UUID or ID of related entity this form submission belongs to. |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + * @throws EE_Error |
|
| 63 | + * @throws ReflectionException |
|
| 64 | + */ |
|
| 65 | + public function formSection(): string |
|
| 66 | + { |
|
| 67 | + return $this->get('FSC_UUID'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param string $form_section_UUID |
|
| 73 | + * @throws EE_Error |
|
| 74 | + * @throws ReflectionException |
|
| 75 | + */ |
|
| 76 | + public function setFormSection(string $form_section_UUID) |
|
| 77 | + { |
|
| 78 | + $this->set('FSC_UUID', $form_section_UUID); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Returns the related EE_Transaction this form submission belongs to. |
|
| 84 | + * |
|
| 85 | + * @return EE_Transaction |
|
| 86 | + * @throws EE_Error |
|
| 87 | + * @throws EntityNotFoundException |
|
| 88 | + * @throws ReflectionException |
|
| 89 | + */ |
|
| 90 | + public function transaction(): EE_Transaction |
|
| 91 | + { |
|
| 92 | + $transaction = $this->get_first_related('Transaction'); |
|
| 93 | + if (! $transaction instanceof EE_Transaction) { |
|
| 94 | + throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
|
| 95 | + } |
|
| 96 | + return $transaction; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return int |
|
| 102 | + * @throws EE_Error |
|
| 103 | + * @throws ReflectionException |
|
| 104 | + */ |
|
| 105 | + public function transactionID(): int |
|
| 106 | + { |
|
| 107 | + return $this->get('TXN_ID'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param int $TXN_ID |
|
| 113 | + * @throws EE_Error |
|
| 114 | + * @throws ReflectionException |
|
| 115 | + */ |
|
| 116 | + public function setTransactionID(int $TXN_ID = 0) |
|
| 117 | + { |
|
| 118 | + $this->set('TXN_ID', $TXN_ID); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return string |
|
| 124 | + * @throws EE_Error |
|
| 125 | + * @throws ReflectionException |
|
| 126 | + */ |
|
| 127 | + public function data(): string |
|
| 128 | + { |
|
| 129 | + $form_data = $this->get('FSB_data'); |
|
| 130 | + return ! empty($form_data) ? $form_data : '{}'; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param array|string $data |
|
| 136 | + * @throws EE_Error |
|
| 137 | + * @throws ReflectionException |
|
| 138 | + */ |
|
| 139 | + public function setData($data) |
|
| 140 | + { |
|
| 141 | + $this->set('FSB_data', $data); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param bool $raw |
|
| 147 | + * @return int |
|
| 148 | + * @throws EE_Error |
|
| 149 | + * @throws ReflectionException |
|
| 150 | + */ |
|
| 151 | + public function submitted(bool $raw = false): int |
|
| 152 | + { |
|
| 153 | + return $raw |
|
| 154 | + ? $this->get_raw('FSB_submitted') |
|
| 155 | + : $this->get('FSB_submitted'); |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -29,483 +29,483 @@ |
||
| 29 | 29 | class EE_Form_Element extends EE_Base_Class |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var Attributes |
|
| 34 | - */ |
|
| 35 | - private $attributes; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var FormLabel |
|
| 39 | - */ |
|
| 40 | - private $label; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var HelpText |
|
| 44 | - */ |
|
| 45 | - private $helpText; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var InputOptions |
|
| 49 | - */ |
|
| 50 | - private $options; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var Required |
|
| 54 | - */ |
|
| 55 | - private $required; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param array $props_n_values |
|
| 60 | - * @return EE_Form_Element |
|
| 61 | - * @throws EE_Error |
|
| 62 | - * @throws ReflectionException |
|
| 63 | - */ |
|
| 64 | - public static function new_instance(array $props_n_values = []): EE_Form_Element |
|
| 65 | - { |
|
| 66 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 67 | - return $has_object ?: new self($props_n_values); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param array $props_n_values |
|
| 73 | - * @return EE_Form_Element |
|
| 74 | - * @throws EE_Error |
|
| 75 | - * @throws ReflectionException |
|
| 76 | - */ |
|
| 77 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Element |
|
| 78 | - { |
|
| 79 | - return new self($props_n_values); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Form Element UUID (universally unique identifier) |
|
| 85 | - * |
|
| 86 | - * @return string |
|
| 87 | - * @throws EE_Error |
|
| 88 | - * @throws ReflectionException |
|
| 89 | - */ |
|
| 90 | - public function UUID(): string |
|
| 91 | - { |
|
| 92 | - return $this->get('FIN_UUID'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param string $UUID |
|
| 98 | - * @throws EE_Error |
|
| 99 | - * @throws ReflectionException |
|
| 100 | - */ |
|
| 101 | - public function setUUID(string $UUID) |
|
| 102 | - { |
|
| 103 | - $this->set('FIN_UUID', $UUID); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
| 109 | - * |
|
| 110 | - * @return bool |
|
| 111 | - * @throws EE_Error |
|
| 112 | - * @throws ReflectionException |
|
| 113 | - */ |
|
| 114 | - public function adminOnly(): ?bool |
|
| 115 | - { |
|
| 116 | - return $this->get('FIN_adminOnly'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param bool $admin_only |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws ReflectionException |
|
| 124 | - */ |
|
| 125 | - public function setAdminOnly(bool $admin_only) |
|
| 126 | - { |
|
| 127 | - $this->set('FIN_adminOnly', $admin_only); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * JSON string of HTML attributes such as class, max, min, placeholder, type, etc. |
|
| 133 | - * |
|
| 134 | - * @return Attributes |
|
| 135 | - * @throws EE_Error |
|
| 136 | - * @throws ReflectionException |
|
| 137 | - */ |
|
| 138 | - public function attributes(): ?Attributes |
|
| 139 | - { |
|
| 140 | - if (! $this->attributes instanceof Attributes) { |
|
| 141 | - $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
|
| 142 | - } |
|
| 143 | - return $this->attributes; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param string $attribute |
|
| 149 | - * @return bool|float|int|string |
|
| 150 | - * @throws EE_Error |
|
| 151 | - * @throws ReflectionException |
|
| 152 | - */ |
|
| 153 | - public function getAttribute(string $attribute) |
|
| 154 | - { |
|
| 155 | - return $this->attributes()->getAttribute($attribute); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param Attributes $attributes |
|
| 161 | - * @throws EE_Error |
|
| 162 | - * @throws ReflectionException |
|
| 163 | - */ |
|
| 164 | - public function setAttributes(Attributes $attributes) |
|
| 165 | - { |
|
| 166 | - // set local object |
|
| 167 | - $this->attributes = $attributes; |
|
| 168 | - // then pass to model as an array which will get converted to JSON by the model field |
|
| 169 | - $this->set('FIN_attributes', $attributes->toArray()); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * UUID of parent form section this form input belongs to. |
|
| 175 | - * |
|
| 176 | - * @return string |
|
| 177 | - * @throws EE_Error |
|
| 178 | - * @throws ReflectionException |
|
| 179 | - */ |
|
| 180 | - public function belongsTo(): string |
|
| 181 | - { |
|
| 182 | - return $this->get('FSC_UUID'); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param string $relation_UUID |
|
| 188 | - * @throws EE_Error |
|
| 189 | - * @throws ReflectionException |
|
| 190 | - */ |
|
| 191 | - public function setBelongsTo(string $relation_UUID) |
|
| 192 | - { |
|
| 193 | - $this->set('FSC_UUID', $relation_UUID); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * returns a HelpText object for managing input help text |
|
| 199 | - * |
|
| 200 | - * @return HelpText |
|
| 201 | - * @throws EE_Error |
|
| 202 | - * @throws ReflectionException |
|
| 203 | - */ |
|
| 204 | - public function helpText(): ?HelpText |
|
| 205 | - { |
|
| 206 | - if (! $this->helpText instanceof HelpText) { |
|
| 207 | - $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
|
| 208 | - } |
|
| 209 | - return $this->helpText; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @param HelpText $helpText |
|
| 215 | - * @throws EE_Error |
|
| 216 | - * @throws ReflectionException |
|
| 217 | - */ |
|
| 218 | - public function setHelpText(HelpText $helpText) |
|
| 219 | - { |
|
| 220 | - // set local object |
|
| 221 | - $this->helpText = $helpText; |
|
| 222 | - // then pass to model as an array which will get converted to JSON by the model field |
|
| 223 | - $this->set('FIN_helpText', $helpText->toArray()); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * returns a FormLabel object for managing input labels |
|
| 229 | - * |
|
| 230 | - * @return FormLabel |
|
| 231 | - * @throws EE_Error |
|
| 232 | - * @throws ReflectionException |
|
| 233 | - */ |
|
| 234 | - public function label(): ?FormLabel |
|
| 235 | - { |
|
| 236 | - if (! $this->label instanceof FormLabel) { |
|
| 237 | - $this->label = FormLabel::fromJson($this->get('FIN_label')); |
|
| 238 | - } |
|
| 239 | - return $this->label; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @param FormLabel $label |
|
| 245 | - * @throws EE_Error |
|
| 246 | - * @throws ReflectionException |
|
| 247 | - */ |
|
| 248 | - public function setLabel(FormLabel $label) |
|
| 249 | - { |
|
| 250 | - // set local object |
|
| 251 | - $this->label = $label; |
|
| 252 | - // then pass to model as an array which will get converted to JSON by the model field |
|
| 253 | - $this->set('FIN_label', $label->toArray()); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Model and Fields name that this input maps to; ex: Attendee.email |
|
| 259 | - * |
|
| 260 | - * @return string |
|
| 261 | - * @throws EE_Error |
|
| 262 | - * @throws ReflectionException |
|
| 263 | - */ |
|
| 264 | - public function mapsTo(): ?string |
|
| 265 | - { |
|
| 266 | - return $this->get('FIN_mapsTo'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @param string $model ex: Attendee |
|
| 272 | - * @param string $field ex: email |
|
| 273 | - * @throws EE_Error |
|
| 274 | - * @throws ReflectionException |
|
| 275 | - */ |
|
| 276 | - public function setMapsTo(string $model, string $field) |
|
| 277 | - { |
|
| 278 | - $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
|
| 279 | - if (! class_exists($model_name)) { |
|
| 280 | - throw new DomainException( |
|
| 281 | - sprintf( |
|
| 282 | - esc_html__( |
|
| 283 | - 'The %1$s model does not exist or can not be located. Please verify the spelling and whether it is loaded.', |
|
| 284 | - 'event_espresso' |
|
| 285 | - ), |
|
| 286 | - $model_name |
|
| 287 | - ) |
|
| 288 | - ); |
|
| 289 | - } |
|
| 290 | - $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
| 296 | - * |
|
| 297 | - * @return InputOptions |
|
| 298 | - * @throws EE_Error |
|
| 299 | - * @throws ReflectionException |
|
| 300 | - */ |
|
| 301 | - public function options(): ?InputOptions |
|
| 302 | - { |
|
| 303 | - if (! $this->options instanceof InputOptions) { |
|
| 304 | - $this->options = InputOptions::fromJson($this->get('FIN_options')); |
|
| 305 | - } |
|
| 306 | - return $this->options; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param InputOptions $options |
|
| 312 | - * @throws EE_Error |
|
| 313 | - * @throws ReflectionException |
|
| 314 | - */ |
|
| 315 | - public function setOptions(InputOptions $options) |
|
| 316 | - { |
|
| 317 | - // set local object |
|
| 318 | - $this->options = $options; |
|
| 319 | - // then pass to model as an array which will get converted to JSON by the model field |
|
| 320 | - $this->set('FIN_options', $options->toArray()); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Order in which form input appears in a form. |
|
| 327 | - * |
|
| 328 | - * @return int |
|
| 329 | - * @throws EE_Error |
|
| 330 | - * @throws ReflectionException |
|
| 331 | - */ |
|
| 332 | - public function order(): int |
|
| 333 | - { |
|
| 334 | - return $this->get('FIN_order'); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @param int $order |
|
| 340 | - * @throws EE_Error |
|
| 341 | - * @throws ReflectionException |
|
| 342 | - */ |
|
| 343 | - public function setOrder(int $order) |
|
| 344 | - { |
|
| 345 | - $this->set('FIN_order', $order); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Example text displayed within an input to assist users with completing the form. |
|
| 351 | - * |
|
| 352 | - * @return string |
|
| 353 | - * @throws EE_Error |
|
| 354 | - * @throws ReflectionException |
|
| 355 | - */ |
|
| 356 | - public function placeholder(): ?string |
|
| 357 | - { |
|
| 358 | - return $this->get('FIN_placeholder'); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @param string $placeholder |
|
| 364 | - * @throws EE_Error |
|
| 365 | - * @throws ReflectionException |
|
| 366 | - */ |
|
| 367 | - public function setPlaceholder(string $placeholder) |
|
| 368 | - { |
|
| 369 | - $this->set('FIN_placeholder', $placeholder); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Whether or not the input must be supplied with a value in order to complete the form. |
|
| 375 | - * |
|
| 376 | - * @return Required |
|
| 377 | - * @throws EE_Error |
|
| 378 | - * @throws ReflectionException |
|
| 379 | - */ |
|
| 380 | - public function required(): ?Required |
|
| 381 | - { |
|
| 382 | - if (! $this->required instanceof Required) { |
|
| 383 | - $this->required = Required::fromJson($this->get('FIN_required')); |
|
| 384 | - } |
|
| 385 | - return $this->required; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * @param Required $required |
|
| 391 | - * @throws EE_Error |
|
| 392 | - * @throws ReflectionException |
|
| 393 | - */ |
|
| 394 | - public function setRequired(Required $required) |
|
| 395 | - { |
|
| 396 | - // set local object |
|
| 397 | - $this->required = $required; |
|
| 398 | - // then pass to model as an array which will get converted to JSON by the model field |
|
| 399 | - $this->set('FIN_required', $required->toArray()); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * version of public label for use in identifiers |
|
| 405 | - * |
|
| 406 | - * @return string |
|
| 407 | - * @throws EE_Error |
|
| 408 | - * @throws ReflectionException |
|
| 409 | - */ |
|
| 410 | - public function slug(): ?string |
|
| 411 | - { |
|
| 412 | - return $this->label()->publicLabel(); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
| 418 | - * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
| 419 | - * |
|
| 420 | - * @return string |
|
| 421 | - * @throws EE_Error |
|
| 422 | - * @throws ReflectionException |
|
| 423 | - */ |
|
| 424 | - public function status(): string |
|
| 425 | - { |
|
| 426 | - return $this->get('FIN_status'); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
| 432 | - * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
| 433 | - * |
|
| 434 | - * @param string $status |
|
| 435 | - * @throws EE_Error |
|
| 436 | - * @throws ReflectionException |
|
| 437 | - */ |
|
| 438 | - public function setStatus(string $status) |
|
| 439 | - { |
|
| 440 | - $this->set('FIN_status', $status); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Form input type. |
|
| 446 | - * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
| 447 | - * |
|
| 448 | - * @return string |
|
| 449 | - * @throws EE_Error |
|
| 450 | - * @throws ReflectionException |
|
| 451 | - */ |
|
| 452 | - public function type(): ?string |
|
| 453 | - { |
|
| 454 | - return $this->get('FIN_type'); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @param string $type |
|
| 460 | - * @throws EE_Error |
|
| 461 | - * @throws ReflectionException |
|
| 462 | - */ |
|
| 463 | - public function setType(string $type) |
|
| 464 | - { |
|
| 465 | - $this->set('FIN_type', $type); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * ID of the WP User that created this form input. |
|
| 471 | - * |
|
| 472 | - * @return int |
|
| 473 | - * @throws EE_Error |
|
| 474 | - * @throws ReflectionException |
|
| 475 | - */ |
|
| 476 | - public function wp_user(): int |
|
| 477 | - { |
|
| 478 | - return $this->get('FIN_wpUser'); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * returns the id the wordpress user who created this question |
|
| 484 | - * |
|
| 485 | - * @param int $wp_user |
|
| 486 | - * @throws EE_Error |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - */ |
|
| 489 | - public function setWpUser(int $wp_user) |
|
| 490 | - { |
|
| 491 | - $this->set('FIN_wpUser', $wp_user); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @param array $set_cols_n_values |
|
| 497 | - * @return bool|int|string |
|
| 498 | - * @throws EE_Error |
|
| 499 | - * @throws ReflectionException |
|
| 500 | - */ |
|
| 501 | - public function save($set_cols_n_values = []) |
|
| 502 | - { |
|
| 503 | - // make sure internal versions for all composite objects are updated |
|
| 504 | - $this->set('FIN_attributes', $this->attributes()->toArray()); |
|
| 505 | - $this->set('FIN_helpText', $this->helpText()->toArray()); |
|
| 506 | - $this->set('FIN_label', $this->label()->toArray()); |
|
| 507 | - $this->set('FIN_options', $this->options()->toArray()); |
|
| 508 | - $this->set('FIN_required', $this->required()->toArray()); |
|
| 509 | - return parent::save($set_cols_n_values); |
|
| 510 | - } |
|
| 32 | + /** |
|
| 33 | + * @var Attributes |
|
| 34 | + */ |
|
| 35 | + private $attributes; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var FormLabel |
|
| 39 | + */ |
|
| 40 | + private $label; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var HelpText |
|
| 44 | + */ |
|
| 45 | + private $helpText; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var InputOptions |
|
| 49 | + */ |
|
| 50 | + private $options; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var Required |
|
| 54 | + */ |
|
| 55 | + private $required; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param array $props_n_values |
|
| 60 | + * @return EE_Form_Element |
|
| 61 | + * @throws EE_Error |
|
| 62 | + * @throws ReflectionException |
|
| 63 | + */ |
|
| 64 | + public static function new_instance(array $props_n_values = []): EE_Form_Element |
|
| 65 | + { |
|
| 66 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 67 | + return $has_object ?: new self($props_n_values); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param array $props_n_values |
|
| 73 | + * @return EE_Form_Element |
|
| 74 | + * @throws EE_Error |
|
| 75 | + * @throws ReflectionException |
|
| 76 | + */ |
|
| 77 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Element |
|
| 78 | + { |
|
| 79 | + return new self($props_n_values); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Form Element UUID (universally unique identifier) |
|
| 85 | + * |
|
| 86 | + * @return string |
|
| 87 | + * @throws EE_Error |
|
| 88 | + * @throws ReflectionException |
|
| 89 | + */ |
|
| 90 | + public function UUID(): string |
|
| 91 | + { |
|
| 92 | + return $this->get('FIN_UUID'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param string $UUID |
|
| 98 | + * @throws EE_Error |
|
| 99 | + * @throws ReflectionException |
|
| 100 | + */ |
|
| 101 | + public function setUUID(string $UUID) |
|
| 102 | + { |
|
| 103 | + $this->set('FIN_UUID', $UUID); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
| 109 | + * |
|
| 110 | + * @return bool |
|
| 111 | + * @throws EE_Error |
|
| 112 | + * @throws ReflectionException |
|
| 113 | + */ |
|
| 114 | + public function adminOnly(): ?bool |
|
| 115 | + { |
|
| 116 | + return $this->get('FIN_adminOnly'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param bool $admin_only |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws ReflectionException |
|
| 124 | + */ |
|
| 125 | + public function setAdminOnly(bool $admin_only) |
|
| 126 | + { |
|
| 127 | + $this->set('FIN_adminOnly', $admin_only); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * JSON string of HTML attributes such as class, max, min, placeholder, type, etc. |
|
| 133 | + * |
|
| 134 | + * @return Attributes |
|
| 135 | + * @throws EE_Error |
|
| 136 | + * @throws ReflectionException |
|
| 137 | + */ |
|
| 138 | + public function attributes(): ?Attributes |
|
| 139 | + { |
|
| 140 | + if (! $this->attributes instanceof Attributes) { |
|
| 141 | + $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
|
| 142 | + } |
|
| 143 | + return $this->attributes; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param string $attribute |
|
| 149 | + * @return bool|float|int|string |
|
| 150 | + * @throws EE_Error |
|
| 151 | + * @throws ReflectionException |
|
| 152 | + */ |
|
| 153 | + public function getAttribute(string $attribute) |
|
| 154 | + { |
|
| 155 | + return $this->attributes()->getAttribute($attribute); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param Attributes $attributes |
|
| 161 | + * @throws EE_Error |
|
| 162 | + * @throws ReflectionException |
|
| 163 | + */ |
|
| 164 | + public function setAttributes(Attributes $attributes) |
|
| 165 | + { |
|
| 166 | + // set local object |
|
| 167 | + $this->attributes = $attributes; |
|
| 168 | + // then pass to model as an array which will get converted to JSON by the model field |
|
| 169 | + $this->set('FIN_attributes', $attributes->toArray()); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * UUID of parent form section this form input belongs to. |
|
| 175 | + * |
|
| 176 | + * @return string |
|
| 177 | + * @throws EE_Error |
|
| 178 | + * @throws ReflectionException |
|
| 179 | + */ |
|
| 180 | + public function belongsTo(): string |
|
| 181 | + { |
|
| 182 | + return $this->get('FSC_UUID'); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param string $relation_UUID |
|
| 188 | + * @throws EE_Error |
|
| 189 | + * @throws ReflectionException |
|
| 190 | + */ |
|
| 191 | + public function setBelongsTo(string $relation_UUID) |
|
| 192 | + { |
|
| 193 | + $this->set('FSC_UUID', $relation_UUID); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * returns a HelpText object for managing input help text |
|
| 199 | + * |
|
| 200 | + * @return HelpText |
|
| 201 | + * @throws EE_Error |
|
| 202 | + * @throws ReflectionException |
|
| 203 | + */ |
|
| 204 | + public function helpText(): ?HelpText |
|
| 205 | + { |
|
| 206 | + if (! $this->helpText instanceof HelpText) { |
|
| 207 | + $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
|
| 208 | + } |
|
| 209 | + return $this->helpText; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @param HelpText $helpText |
|
| 215 | + * @throws EE_Error |
|
| 216 | + * @throws ReflectionException |
|
| 217 | + */ |
|
| 218 | + public function setHelpText(HelpText $helpText) |
|
| 219 | + { |
|
| 220 | + // set local object |
|
| 221 | + $this->helpText = $helpText; |
|
| 222 | + // then pass to model as an array which will get converted to JSON by the model field |
|
| 223 | + $this->set('FIN_helpText', $helpText->toArray()); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * returns a FormLabel object for managing input labels |
|
| 229 | + * |
|
| 230 | + * @return FormLabel |
|
| 231 | + * @throws EE_Error |
|
| 232 | + * @throws ReflectionException |
|
| 233 | + */ |
|
| 234 | + public function label(): ?FormLabel |
|
| 235 | + { |
|
| 236 | + if (! $this->label instanceof FormLabel) { |
|
| 237 | + $this->label = FormLabel::fromJson($this->get('FIN_label')); |
|
| 238 | + } |
|
| 239 | + return $this->label; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @param FormLabel $label |
|
| 245 | + * @throws EE_Error |
|
| 246 | + * @throws ReflectionException |
|
| 247 | + */ |
|
| 248 | + public function setLabel(FormLabel $label) |
|
| 249 | + { |
|
| 250 | + // set local object |
|
| 251 | + $this->label = $label; |
|
| 252 | + // then pass to model as an array which will get converted to JSON by the model field |
|
| 253 | + $this->set('FIN_label', $label->toArray()); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Model and Fields name that this input maps to; ex: Attendee.email |
|
| 259 | + * |
|
| 260 | + * @return string |
|
| 261 | + * @throws EE_Error |
|
| 262 | + * @throws ReflectionException |
|
| 263 | + */ |
|
| 264 | + public function mapsTo(): ?string |
|
| 265 | + { |
|
| 266 | + return $this->get('FIN_mapsTo'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @param string $model ex: Attendee |
|
| 272 | + * @param string $field ex: email |
|
| 273 | + * @throws EE_Error |
|
| 274 | + * @throws ReflectionException |
|
| 275 | + */ |
|
| 276 | + public function setMapsTo(string $model, string $field) |
|
| 277 | + { |
|
| 278 | + $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
|
| 279 | + if (! class_exists($model_name)) { |
|
| 280 | + throw new DomainException( |
|
| 281 | + sprintf( |
|
| 282 | + esc_html__( |
|
| 283 | + 'The %1$s model does not exist or can not be located. Please verify the spelling and whether it is loaded.', |
|
| 284 | + 'event_espresso' |
|
| 285 | + ), |
|
| 286 | + $model_name |
|
| 287 | + ) |
|
| 288 | + ); |
|
| 289 | + } |
|
| 290 | + $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
| 296 | + * |
|
| 297 | + * @return InputOptions |
|
| 298 | + * @throws EE_Error |
|
| 299 | + * @throws ReflectionException |
|
| 300 | + */ |
|
| 301 | + public function options(): ?InputOptions |
|
| 302 | + { |
|
| 303 | + if (! $this->options instanceof InputOptions) { |
|
| 304 | + $this->options = InputOptions::fromJson($this->get('FIN_options')); |
|
| 305 | + } |
|
| 306 | + return $this->options; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param InputOptions $options |
|
| 312 | + * @throws EE_Error |
|
| 313 | + * @throws ReflectionException |
|
| 314 | + */ |
|
| 315 | + public function setOptions(InputOptions $options) |
|
| 316 | + { |
|
| 317 | + // set local object |
|
| 318 | + $this->options = $options; |
|
| 319 | + // then pass to model as an array which will get converted to JSON by the model field |
|
| 320 | + $this->set('FIN_options', $options->toArray()); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Order in which form input appears in a form. |
|
| 327 | + * |
|
| 328 | + * @return int |
|
| 329 | + * @throws EE_Error |
|
| 330 | + * @throws ReflectionException |
|
| 331 | + */ |
|
| 332 | + public function order(): int |
|
| 333 | + { |
|
| 334 | + return $this->get('FIN_order'); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @param int $order |
|
| 340 | + * @throws EE_Error |
|
| 341 | + * @throws ReflectionException |
|
| 342 | + */ |
|
| 343 | + public function setOrder(int $order) |
|
| 344 | + { |
|
| 345 | + $this->set('FIN_order', $order); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Example text displayed within an input to assist users with completing the form. |
|
| 351 | + * |
|
| 352 | + * @return string |
|
| 353 | + * @throws EE_Error |
|
| 354 | + * @throws ReflectionException |
|
| 355 | + */ |
|
| 356 | + public function placeholder(): ?string |
|
| 357 | + { |
|
| 358 | + return $this->get('FIN_placeholder'); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @param string $placeholder |
|
| 364 | + * @throws EE_Error |
|
| 365 | + * @throws ReflectionException |
|
| 366 | + */ |
|
| 367 | + public function setPlaceholder(string $placeholder) |
|
| 368 | + { |
|
| 369 | + $this->set('FIN_placeholder', $placeholder); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Whether or not the input must be supplied with a value in order to complete the form. |
|
| 375 | + * |
|
| 376 | + * @return Required |
|
| 377 | + * @throws EE_Error |
|
| 378 | + * @throws ReflectionException |
|
| 379 | + */ |
|
| 380 | + public function required(): ?Required |
|
| 381 | + { |
|
| 382 | + if (! $this->required instanceof Required) { |
|
| 383 | + $this->required = Required::fromJson($this->get('FIN_required')); |
|
| 384 | + } |
|
| 385 | + return $this->required; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * @param Required $required |
|
| 391 | + * @throws EE_Error |
|
| 392 | + * @throws ReflectionException |
|
| 393 | + */ |
|
| 394 | + public function setRequired(Required $required) |
|
| 395 | + { |
|
| 396 | + // set local object |
|
| 397 | + $this->required = $required; |
|
| 398 | + // then pass to model as an array which will get converted to JSON by the model field |
|
| 399 | + $this->set('FIN_required', $required->toArray()); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * version of public label for use in identifiers |
|
| 405 | + * |
|
| 406 | + * @return string |
|
| 407 | + * @throws EE_Error |
|
| 408 | + * @throws ReflectionException |
|
| 409 | + */ |
|
| 410 | + public function slug(): ?string |
|
| 411 | + { |
|
| 412 | + return $this->label()->publicLabel(); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
| 418 | + * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
| 419 | + * |
|
| 420 | + * @return string |
|
| 421 | + * @throws EE_Error |
|
| 422 | + * @throws ReflectionException |
|
| 423 | + */ |
|
| 424 | + public function status(): string |
|
| 425 | + { |
|
| 426 | + return $this->get('FIN_status'); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
| 432 | + * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
| 433 | + * |
|
| 434 | + * @param string $status |
|
| 435 | + * @throws EE_Error |
|
| 436 | + * @throws ReflectionException |
|
| 437 | + */ |
|
| 438 | + public function setStatus(string $status) |
|
| 439 | + { |
|
| 440 | + $this->set('FIN_status', $status); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Form input type. |
|
| 446 | + * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
| 447 | + * |
|
| 448 | + * @return string |
|
| 449 | + * @throws EE_Error |
|
| 450 | + * @throws ReflectionException |
|
| 451 | + */ |
|
| 452 | + public function type(): ?string |
|
| 453 | + { |
|
| 454 | + return $this->get('FIN_type'); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @param string $type |
|
| 460 | + * @throws EE_Error |
|
| 461 | + * @throws ReflectionException |
|
| 462 | + */ |
|
| 463 | + public function setType(string $type) |
|
| 464 | + { |
|
| 465 | + $this->set('FIN_type', $type); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * ID of the WP User that created this form input. |
|
| 471 | + * |
|
| 472 | + * @return int |
|
| 473 | + * @throws EE_Error |
|
| 474 | + * @throws ReflectionException |
|
| 475 | + */ |
|
| 476 | + public function wp_user(): int |
|
| 477 | + { |
|
| 478 | + return $this->get('FIN_wpUser'); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * returns the id the wordpress user who created this question |
|
| 484 | + * |
|
| 485 | + * @param int $wp_user |
|
| 486 | + * @throws EE_Error |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + */ |
|
| 489 | + public function setWpUser(int $wp_user) |
|
| 490 | + { |
|
| 491 | + $this->set('FIN_wpUser', $wp_user); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @param array $set_cols_n_values |
|
| 497 | + * @return bool|int|string |
|
| 498 | + * @throws EE_Error |
|
| 499 | + * @throws ReflectionException |
|
| 500 | + */ |
|
| 501 | + public function save($set_cols_n_values = []) |
|
| 502 | + { |
|
| 503 | + // make sure internal versions for all composite objects are updated |
|
| 504 | + $this->set('FIN_attributes', $this->attributes()->toArray()); |
|
| 505 | + $this->set('FIN_helpText', $this->helpText()->toArray()); |
|
| 506 | + $this->set('FIN_label', $this->label()->toArray()); |
|
| 507 | + $this->set('FIN_options', $this->options()->toArray()); |
|
| 508 | + $this->set('FIN_required', $this->required()->toArray()); |
|
| 509 | + return parent::save($set_cols_n_values); |
|
| 510 | + } |
|
| 511 | 511 | } |
@@ -13,735 +13,735 @@ discard block |
||
| 13 | 13 | class EEH_Debug_Tools |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * instance of the EEH_Autoloader object |
|
| 18 | - * |
|
| 19 | - * @var $_instance |
|
| 20 | - * @access private |
|
| 21 | - */ |
|
| 22 | - private static $_instance; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $_memory_usage_points = array(); |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @singleton method used to instantiate class object |
|
| 33 | - * @access public |
|
| 34 | - * @return EEH_Debug_Tools |
|
| 35 | - */ |
|
| 36 | - public static function instance() |
|
| 37 | - { |
|
| 38 | - // check if class object is instantiated, and instantiated properly |
|
| 39 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 40 | - self::$_instance = new self(); |
|
| 41 | - } |
|
| 42 | - return self::$_instance; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * private class constructor |
|
| 49 | - */ |
|
| 50 | - private function __construct() |
|
| 51 | - { |
|
| 52 | - // load Kint PHP debugging library |
|
| 53 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
| 54 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 55 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 56 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 57 | - // so we've moved it to our test folder so that it is not included with production releases |
|
| 58 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 59 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
| 60 | - } |
|
| 61 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 62 | - // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 63 | - // } |
|
| 64 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 65 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 66 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 67 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * show_db_name |
|
| 74 | - * |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - public static function show_db_name() |
|
| 78 | - { |
|
| 79 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 80 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 81 | - . DB_NAME |
|
| 82 | - . '</p>'; |
|
| 83 | - } |
|
| 84 | - if (EE_DEBUG) { |
|
| 85 | - Benchmark::displayResults(); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * dump EE_Session object at bottom of page after everything else has happened |
|
| 93 | - * |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function espresso_session_footer_dump() |
|
| 97 | - { |
|
| 98 | - if ( |
|
| 99 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
| 100 | - && ! defined('DOING_AJAX') |
|
| 101 | - && class_exists('Kint') |
|
| 102 | - && function_exists('wp_get_current_user') |
|
| 103 | - && current_user_can('update_core') |
|
| 104 | - && class_exists('EE_Registry') |
|
| 105 | - ) { |
|
| 106 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 107 | - Kint::dump(EE_Registry::instance()->SSN); |
|
| 108 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 109 | - $this->espresso_list_hooked_functions(); |
|
| 110 | - Benchmark::displayResults(); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * List All Hooked Functions |
|
| 118 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 119 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 120 | - * |
|
| 121 | - * @param string $tag |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public function espresso_list_hooked_functions($tag = '') |
|
| 125 | - { |
|
| 126 | - global $wp_filter; |
|
| 127 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 128 | - if ($tag) { |
|
| 129 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
| 130 | - if (! is_array($hook[ $tag ])) { |
|
| 131 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 135 | - } else { |
|
| 136 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 137 | - ksort($hook); |
|
| 138 | - } |
|
| 139 | - foreach ($hook as $tag_name => $priorities) { |
|
| 140 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 141 | - ksort($priorities); |
|
| 142 | - foreach ($priorities as $priority => $function) { |
|
| 143 | - echo $priority; |
|
| 144 | - foreach ($function as $name => $properties) { |
|
| 145 | - echo "\t$name<br />"; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * registered_filter_callbacks |
|
| 155 | - * |
|
| 156 | - * @param string $hook_name |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - public static function registered_filter_callbacks($hook_name = '') |
|
| 160 | - { |
|
| 161 | - $filters = array(); |
|
| 162 | - global $wp_filter; |
|
| 163 | - if (isset($wp_filter[ $hook_name ])) { |
|
| 164 | - $filters[ $hook_name ] = array(); |
|
| 165 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
| 166 | - $filters[ $hook_name ][ $priority ] = array(); |
|
| 167 | - foreach ($callbacks as $callback) { |
|
| 168 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - return $filters; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * captures plugin activation errors for debugging |
|
| 179 | - * |
|
| 180 | - * @return void |
|
| 181 | - * @throws EE_Error |
|
| 182 | - */ |
|
| 183 | - public static function ee_plugin_activation_errors() |
|
| 184 | - { |
|
| 185 | - if (WP_DEBUG) { |
|
| 186 | - $activation_errors = ob_get_contents(); |
|
| 187 | - if (empty($activation_errors)) { |
|
| 188 | - return; |
|
| 189 | - } |
|
| 190 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 191 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 192 | - if (class_exists('EEH_File')) { |
|
| 193 | - try { |
|
| 194 | - EEH_File::ensure_file_exists_and_is_writable( |
|
| 195 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
| 196 | - ); |
|
| 197 | - EEH_File::write_to_file( |
|
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 199 | - $activation_errors |
|
| 200 | - ); |
|
| 201 | - } catch (EE_Error $e) { |
|
| 202 | - EE_Error::add_error( |
|
| 203 | - sprintf( |
|
| 204 | - __( |
|
| 205 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ), |
|
| 208 | - $e->getMessage() |
|
| 209 | - ), |
|
| 210 | - __FILE__, |
|
| 211 | - __FUNCTION__, |
|
| 212 | - __LINE__ |
|
| 213 | - ); |
|
| 214 | - } |
|
| 215 | - } else { |
|
| 216 | - // old school attempt |
|
| 217 | - file_put_contents( |
|
| 218 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 219 | - $activation_errors |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 223 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 231 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 232 | - * or we want to make sure they use something the right way. |
|
| 233 | - * |
|
| 234 | - * @access public |
|
| 235 | - * @param string $function The function that was called |
|
| 236 | - * @param string $message A message explaining what has been done incorrectly |
|
| 237 | - * @param string $version The version of Event Espresso where the error was added |
|
| 238 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 239 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 240 | - * but not have any notices appear until a later version. This allows developers |
|
| 241 | - * extra time to update their code before notices appear. |
|
| 242 | - * @param int $error_type |
|
| 243 | - * @uses trigger_error() |
|
| 244 | - */ |
|
| 245 | - public function doing_it_wrong( |
|
| 246 | - $function, |
|
| 247 | - $message, |
|
| 248 | - $version, |
|
| 249 | - $applies_when = '', |
|
| 250 | - $error_type = null |
|
| 251 | - ) { |
|
| 252 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 253 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 254 | - // because we swapped the parameter order around for the last two params, |
|
| 255 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
| 256 | - if (is_int($applies_when)) { |
|
| 257 | - $error_type = $applies_when; |
|
| 258 | - $applies_when = espresso_version(); |
|
| 259 | - } |
|
| 260 | - // if not displaying notices yet, then just leave |
|
| 261 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 265 | - $version = $version === null |
|
| 266 | - ? '' |
|
| 267 | - : sprintf( |
|
| 268 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 269 | - $version |
|
| 270 | - ); |
|
| 271 | - $error_message = sprintf( |
|
| 272 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 273 | - $function, |
|
| 274 | - '<strong>', |
|
| 275 | - '</strong>', |
|
| 276 | - $message, |
|
| 277 | - $version |
|
| 278 | - ); |
|
| 279 | - // don't trigger error if doing ajax, |
|
| 280 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 281 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 282 | - $error_message .= ' ' . esc_html__( |
|
| 283 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 284 | - 'event_espresso' |
|
| 285 | - ); |
|
| 286 | - $error_message .= '<ul><li>'; |
|
| 287 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 288 | - $error_message .= '</ul>'; |
|
| 289 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 290 | - // now we set this on the transient so it shows up on the next request. |
|
| 291 | - EE_Error::get_notices(false, true); |
|
| 292 | - } else { |
|
| 293 | - trigger_error($error_message, $error_type); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Logger helpers |
|
| 302 | - */ |
|
| 303 | - /** |
|
| 304 | - * debug |
|
| 305 | - * |
|
| 306 | - * @param string $class |
|
| 307 | - * @param string $func |
|
| 308 | - * @param string $line |
|
| 309 | - * @param array $info |
|
| 310 | - * @param bool $display_request |
|
| 311 | - * @param string $debug_index |
|
| 312 | - * @param string $debug_key |
|
| 313 | - * @throws EE_Error |
|
| 314 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 315 | - */ |
|
| 316 | - public static function log( |
|
| 317 | - $class = '', |
|
| 318 | - $func = '', |
|
| 319 | - $line = '', |
|
| 320 | - $info = array(), |
|
| 321 | - $display_request = false, |
|
| 322 | - $debug_index = '', |
|
| 323 | - $debug_key = 'EE_DEBUG_SPCO' |
|
| 324 | - ) { |
|
| 325 | - if (WP_DEBUG) { |
|
| 326 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 327 | - $debug_data = get_option($debug_key, array()); |
|
| 328 | - $default_data = array( |
|
| 329 | - $class => $func . '() : ' . $line, |
|
| 330 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
| 331 | - ); |
|
| 332 | - // don't serialize objects |
|
| 333 | - $info = self::strip_objects($info); |
|
| 334 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 335 | - if (! isset($debug_data[ $index ])) { |
|
| 336 | - $debug_data[ $index ] = array(); |
|
| 337 | - } |
|
| 338 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
| 339 | - update_option($debug_key, $debug_data); |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * strip_objects |
|
| 347 | - * |
|
| 348 | - * @param array $info |
|
| 349 | - * @return array |
|
| 350 | - */ |
|
| 351 | - public static function strip_objects($info = array()) |
|
| 352 | - { |
|
| 353 | - foreach ($info as $key => $value) { |
|
| 354 | - if (is_array($value)) { |
|
| 355 | - $info[ $key ] = self::strip_objects($value); |
|
| 356 | - } elseif (is_object($value)) { |
|
| 357 | - $object_class = get_class($value); |
|
| 358 | - $info[ $object_class ] = array(); |
|
| 359 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 360 | - if (method_exists($value, 'ID')) { |
|
| 361 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
| 362 | - } |
|
| 363 | - if (method_exists($value, 'status')) { |
|
| 364 | - $info[ $object_class ]['status'] = $value->status(); |
|
| 365 | - } elseif (method_exists($value, 'status_ID')) { |
|
| 366 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
| 367 | - } |
|
| 368 | - unset($info[ $key ]); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - return (array) $info; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * @param mixed $var |
|
| 378 | - * @param string $var_name |
|
| 379 | - * @param string $file |
|
| 380 | - * @param int|string $line |
|
| 381 | - * @param int|string $heading_tag |
|
| 382 | - * @param bool $die |
|
| 383 | - * @param string $margin |
|
| 384 | - */ |
|
| 385 | - public static function printv( |
|
| 386 | - $var, |
|
| 387 | - $var_name = '', |
|
| 388 | - $file = '', |
|
| 389 | - $line = '', |
|
| 390 | - $heading_tag = 5, |
|
| 391 | - $die = false, |
|
| 392 | - $margin = '' |
|
| 393 | - ) { |
|
| 394 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
| 395 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 396 | - $is_method = method_exists($var_name, $var); |
|
| 397 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 398 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 399 | - // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 400 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 401 | - $result .= $is_method |
|
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 405 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | - if ($die) { |
|
| 407 | - die($result); |
|
| 408 | - } |
|
| 409 | - echo $result; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - protected static function headingTag($heading_tag) |
|
| 414 | - { |
|
| 415 | - $heading_tag = absint($heading_tag); |
|
| 416 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - // protected static function headingSpacer($heading_tag) |
|
| 421 | - // { |
|
| 422 | - // return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
| 423 | - // ? EEH_Debug_Tools::lineBreak() |
|
| 424 | - // : ''; |
|
| 425 | - // } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - protected static function plainOutput() |
|
| 429 | - { |
|
| 430 | - return defined('EE_TESTS_DIR') |
|
| 431 | - || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output'])) |
|
| 432 | - || ( |
|
| 433 | - isset($_SERVER['REQUEST_URI']) |
|
| 434 | - && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
| 435 | - ); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param string $var_name |
|
| 441 | - * @param string $heading_tag |
|
| 442 | - * @param string $margin |
|
| 443 | - * @param int $line |
|
| 444 | - * @return string |
|
| 445 | - */ |
|
| 446 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
| 447 | - { |
|
| 448 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 449 | - switch ($heading_tag) { |
|
| 450 | - case 'h1': |
|
| 451 | - $line_breaks = EEH_Debug_Tools::lineBreak(3); |
|
| 452 | - break; |
|
| 453 | - case 'h2': |
|
| 454 | - $line_breaks = EEH_Debug_Tools::lineBreak(2); |
|
| 455 | - break; |
|
| 456 | - default: |
|
| 457 | - $line_breaks = EEH_Debug_Tools::lineBreak(); |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - return "{$line_breaks}{$line}) {$var_name}"; |
|
| 461 | - } |
|
| 462 | - $margin = "25px 0 0 {$margin}"; |
|
| 463 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @param string $heading_tag |
|
| 470 | - * @return string |
|
| 471 | - */ |
|
| 472 | - protected static function headingX($heading_tag = 'h5') |
|
| 473 | - { |
|
| 474 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 475 | - return ''; |
|
| 476 | - } |
|
| 477 | - return '</' . $heading_tag . '>'; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @param string $content |
|
| 484 | - * @return string |
|
| 485 | - */ |
|
| 486 | - protected static function grey_span($content = '') |
|
| 487 | - { |
|
| 488 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 489 | - return $content; |
|
| 490 | - } |
|
| 491 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * @param string $file |
|
| 498 | - * @param int $line |
|
| 499 | - * @return string |
|
| 500 | - */ |
|
| 501 | - protected static function file_and_line($file, $line, $heading_tag) |
|
| 502 | - { |
|
| 503 | - if ($file === '' || $line === '') { |
|
| 504 | - return ''; |
|
| 505 | - } |
|
| 506 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
| 507 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 508 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
| 509 | - return " ({$file})"; |
|
| 510 | - } |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - return EEH_Debug_Tools::lineBreak() |
|
| 514 | - . '<span style="display:block; font-size:9px; font-weight:normal; color:#666; line-height:12px;">' |
|
| 515 | - . $file |
|
| 516 | - . EEH_Debug_Tools::lineBreak() |
|
| 517 | - . 'line no: ' |
|
| 518 | - . $line |
|
| 519 | - . '</span>'; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * @param string $content |
|
| 526 | - * @return string |
|
| 527 | - */ |
|
| 528 | - protected static function orange_span($content = '') |
|
| 529 | - { |
|
| 530 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 531 | - return $content; |
|
| 532 | - } |
|
| 533 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @param mixed $var |
|
| 540 | - * @return string |
|
| 541 | - */ |
|
| 542 | - protected static function pre_span($var) |
|
| 543 | - { |
|
| 544 | - ob_start(); |
|
| 545 | - if(is_array($var)) { |
|
| 546 | - self::arrayDisplay($var); |
|
| 547 | - } else { |
|
| 548 | - var_dump($var); |
|
| 549 | - } |
|
| 550 | - $var = ob_get_clean(); |
|
| 551 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 552 | - return $var; |
|
| 553 | - } |
|
| 554 | - return EEH_Debug_Tools::lineBreak() |
|
| 555 | - . '<pre style="color: #9C3; display: inline-block; padding:.5em; margin: .25rem 0; background: #334">' |
|
| 556 | - . $var |
|
| 557 | - . '</pre>'; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * @param mixed $var |
|
| 564 | - * @param string $var_name |
|
| 565 | - * @param string $file |
|
| 566 | - * @param int|string $line |
|
| 567 | - * @param int|string $heading_tag |
|
| 568 | - * @param bool $die |
|
| 569 | - */ |
|
| 570 | - public static function printr( |
|
| 571 | - $var, |
|
| 572 | - $var_name = '', |
|
| 573 | - $file = '', |
|
| 574 | - $line = '', |
|
| 575 | - $heading_tag = 5, |
|
| 576 | - $die = false |
|
| 577 | - ) { |
|
| 578 | - // return; |
|
| 579 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 580 | - if (empty($var) && empty($var_name)) { |
|
| 581 | - $var = $file; |
|
| 582 | - $var_name = "line $line"; |
|
| 583 | - $file = ''; |
|
| 584 | - $line = ''; |
|
| 585 | - } |
|
| 586 | - $margin = is_admin() ? ' 180px' : '0'; |
|
| 587 | - // $print_r = false; |
|
| 588 | - if (is_string($var)) { |
|
| 589 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 590 | - return; |
|
| 591 | - } |
|
| 592 | - if (is_object($var)) { |
|
| 593 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
| 594 | - // $print_r = true; |
|
| 595 | - } elseif (is_array($var)) { |
|
| 596 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
| 597 | - // $print_r = true; |
|
| 598 | - } elseif (is_numeric($var)) { |
|
| 599 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 600 | - } elseif ($var === null) { |
|
| 601 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
| 602 | - } |
|
| 603 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 604 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 605 | - // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 606 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 607 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 608 | - EEH_Debug_Tools::pre_span($var) |
|
| 609 | - ); |
|
| 610 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 611 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 612 | - if ($die) { |
|
| 613 | - die($result); |
|
| 614 | - } |
|
| 615 | - echo $result; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - private static function lineBreak($lines = 1): string |
|
| 620 | - { |
|
| 621 | - $linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL; |
|
| 622 | - return str_repeat($linebreak, $lines); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - public static function shortClassName(string $fqcn): string |
|
| 627 | - { |
|
| 628 | - return substr(strrchr($fqcn, '\\'), 1); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * @return void |
|
| 634 | - */ |
|
| 635 | - public static function arrayDisplay(array $data, $depth = 0) |
|
| 636 | - { |
|
| 637 | - $depth++; |
|
| 638 | - $spacer = self::plainOutput() ? ' . . ' : "\t"; |
|
| 639 | - $indent = str_repeat($spacer, $depth); |
|
| 640 | - if ($depth === 1) { |
|
| 641 | - echo self::lineBreak() . '{'; |
|
| 642 | - } |
|
| 643 | - foreach ($data as $key => $child) { |
|
| 644 | - echo self::lineBreak() . $indent . $key; |
|
| 645 | - // $child = is_object($child) ? (array) $child : $child; |
|
| 646 | - if (is_array($child)) { |
|
| 647 | - echo " [ "; |
|
| 648 | - self::arrayDisplay($child, $depth); |
|
| 649 | - echo self::lineBreak() . $indent . ']'; |
|
| 650 | - } else if (is_scalar($child)) { |
|
| 651 | - echo ' => ' . $child; |
|
| 652 | - } else { |
|
| 653 | - var_export($child); |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - if ($depth === 1) { |
|
| 657 | - echo self::lineBreak() . '}'; |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - /******************** deprecated ********************/ |
|
| 663 | - |
|
| 664 | - |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * @deprecated 4.9.39.rc.034 |
|
| 668 | - */ |
|
| 669 | - public function reset_times() |
|
| 670 | - { |
|
| 671 | - Benchmark::resetTimes(); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * @deprecated 4.9.39.rc.034 |
|
| 678 | - * @param null $timer_name |
|
| 679 | - */ |
|
| 680 | - public function start_timer($timer_name = null) |
|
| 681 | - { |
|
| 682 | - Benchmark::startTimer($timer_name); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * @deprecated 4.9.39.rc.034 |
|
| 689 | - * @param string $timer_name |
|
| 690 | - */ |
|
| 691 | - public function stop_timer($timer_name = '') |
|
| 692 | - { |
|
| 693 | - Benchmark::stopTimer($timer_name); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * @deprecated 4.9.39.rc.034 |
|
| 700 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 701 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 702 | - * @return void |
|
| 703 | - */ |
|
| 704 | - public function measure_memory($label, $output_now = false) |
|
| 705 | - { |
|
| 706 | - Benchmark::measureMemory($label, $output_now); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * @deprecated 4.9.39.rc.034 |
|
| 713 | - * @param int $size |
|
| 714 | - * @return string |
|
| 715 | - */ |
|
| 716 | - public function convert($size) |
|
| 717 | - { |
|
| 718 | - return Benchmark::convert($size); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * @deprecated 4.9.39.rc.034 |
|
| 725 | - * @param bool $output_now |
|
| 726 | - * @return string |
|
| 727 | - */ |
|
| 728 | - public function show_times($output_now = true) |
|
| 729 | - { |
|
| 730 | - return Benchmark::displayResults($output_now); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * @deprecated 4.9.39.rc.034 |
|
| 737 | - * @param string $timer_name |
|
| 738 | - * @param float $total_time |
|
| 739 | - * @return string |
|
| 740 | - */ |
|
| 741 | - public function format_time($timer_name, $total_time) |
|
| 742 | - { |
|
| 743 | - return Benchmark::formatTime($timer_name, $total_time); |
|
| 744 | - } |
|
| 16 | + /** |
|
| 17 | + * instance of the EEH_Autoloader object |
|
| 18 | + * |
|
| 19 | + * @var $_instance |
|
| 20 | + * @access private |
|
| 21 | + */ |
|
| 22 | + private static $_instance; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $_memory_usage_points = array(); |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @singleton method used to instantiate class object |
|
| 33 | + * @access public |
|
| 34 | + * @return EEH_Debug_Tools |
|
| 35 | + */ |
|
| 36 | + public static function instance() |
|
| 37 | + { |
|
| 38 | + // check if class object is instantiated, and instantiated properly |
|
| 39 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 40 | + self::$_instance = new self(); |
|
| 41 | + } |
|
| 42 | + return self::$_instance; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * private class constructor |
|
| 49 | + */ |
|
| 50 | + private function __construct() |
|
| 51 | + { |
|
| 52 | + // load Kint PHP debugging library |
|
| 53 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
| 54 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 55 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 56 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 57 | + // so we've moved it to our test folder so that it is not included with production releases |
|
| 58 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 59 | + require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
| 60 | + } |
|
| 61 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 62 | + // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 63 | + // } |
|
| 64 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 65 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 66 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 67 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * show_db_name |
|
| 74 | + * |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + public static function show_db_name() |
|
| 78 | + { |
|
| 79 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 80 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 81 | + . DB_NAME |
|
| 82 | + . '</p>'; |
|
| 83 | + } |
|
| 84 | + if (EE_DEBUG) { |
|
| 85 | + Benchmark::displayResults(); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * dump EE_Session object at bottom of page after everything else has happened |
|
| 93 | + * |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function espresso_session_footer_dump() |
|
| 97 | + { |
|
| 98 | + if ( |
|
| 99 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
| 100 | + && ! defined('DOING_AJAX') |
|
| 101 | + && class_exists('Kint') |
|
| 102 | + && function_exists('wp_get_current_user') |
|
| 103 | + && current_user_can('update_core') |
|
| 104 | + && class_exists('EE_Registry') |
|
| 105 | + ) { |
|
| 106 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 107 | + Kint::dump(EE_Registry::instance()->SSN); |
|
| 108 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 109 | + $this->espresso_list_hooked_functions(); |
|
| 110 | + Benchmark::displayResults(); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * List All Hooked Functions |
|
| 118 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 119 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 120 | + * |
|
| 121 | + * @param string $tag |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public function espresso_list_hooked_functions($tag = '') |
|
| 125 | + { |
|
| 126 | + global $wp_filter; |
|
| 127 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 128 | + if ($tag) { |
|
| 129 | + $hook[ $tag ] = $wp_filter[ $tag ]; |
|
| 130 | + if (! is_array($hook[ $tag ])) { |
|
| 131 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 135 | + } else { |
|
| 136 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 137 | + ksort($hook); |
|
| 138 | + } |
|
| 139 | + foreach ($hook as $tag_name => $priorities) { |
|
| 140 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 141 | + ksort($priorities); |
|
| 142 | + foreach ($priorities as $priority => $function) { |
|
| 143 | + echo $priority; |
|
| 144 | + foreach ($function as $name => $properties) { |
|
| 145 | + echo "\t$name<br />"; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * registered_filter_callbacks |
|
| 155 | + * |
|
| 156 | + * @param string $hook_name |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + public static function registered_filter_callbacks($hook_name = '') |
|
| 160 | + { |
|
| 161 | + $filters = array(); |
|
| 162 | + global $wp_filter; |
|
| 163 | + if (isset($wp_filter[ $hook_name ])) { |
|
| 164 | + $filters[ $hook_name ] = array(); |
|
| 165 | + foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
| 166 | + $filters[ $hook_name ][ $priority ] = array(); |
|
| 167 | + foreach ($callbacks as $callback) { |
|
| 168 | + $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + return $filters; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * captures plugin activation errors for debugging |
|
| 179 | + * |
|
| 180 | + * @return void |
|
| 181 | + * @throws EE_Error |
|
| 182 | + */ |
|
| 183 | + public static function ee_plugin_activation_errors() |
|
| 184 | + { |
|
| 185 | + if (WP_DEBUG) { |
|
| 186 | + $activation_errors = ob_get_contents(); |
|
| 187 | + if (empty($activation_errors)) { |
|
| 188 | + return; |
|
| 189 | + } |
|
| 190 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 191 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 192 | + if (class_exists('EEH_File')) { |
|
| 193 | + try { |
|
| 194 | + EEH_File::ensure_file_exists_and_is_writable( |
|
| 195 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
| 196 | + ); |
|
| 197 | + EEH_File::write_to_file( |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 199 | + $activation_errors |
|
| 200 | + ); |
|
| 201 | + } catch (EE_Error $e) { |
|
| 202 | + EE_Error::add_error( |
|
| 203 | + sprintf( |
|
| 204 | + __( |
|
| 205 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ), |
|
| 208 | + $e->getMessage() |
|
| 209 | + ), |
|
| 210 | + __FILE__, |
|
| 211 | + __FUNCTION__, |
|
| 212 | + __LINE__ |
|
| 213 | + ); |
|
| 214 | + } |
|
| 215 | + } else { |
|
| 216 | + // old school attempt |
|
| 217 | + file_put_contents( |
|
| 218 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 219 | + $activation_errors |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 223 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 231 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 232 | + * or we want to make sure they use something the right way. |
|
| 233 | + * |
|
| 234 | + * @access public |
|
| 235 | + * @param string $function The function that was called |
|
| 236 | + * @param string $message A message explaining what has been done incorrectly |
|
| 237 | + * @param string $version The version of Event Espresso where the error was added |
|
| 238 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 239 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 240 | + * but not have any notices appear until a later version. This allows developers |
|
| 241 | + * extra time to update their code before notices appear. |
|
| 242 | + * @param int $error_type |
|
| 243 | + * @uses trigger_error() |
|
| 244 | + */ |
|
| 245 | + public function doing_it_wrong( |
|
| 246 | + $function, |
|
| 247 | + $message, |
|
| 248 | + $version, |
|
| 249 | + $applies_when = '', |
|
| 250 | + $error_type = null |
|
| 251 | + ) { |
|
| 252 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 253 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 254 | + // because we swapped the parameter order around for the last two params, |
|
| 255 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
| 256 | + if (is_int($applies_when)) { |
|
| 257 | + $error_type = $applies_when; |
|
| 258 | + $applies_when = espresso_version(); |
|
| 259 | + } |
|
| 260 | + // if not displaying notices yet, then just leave |
|
| 261 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 265 | + $version = $version === null |
|
| 266 | + ? '' |
|
| 267 | + : sprintf( |
|
| 268 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 269 | + $version |
|
| 270 | + ); |
|
| 271 | + $error_message = sprintf( |
|
| 272 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 273 | + $function, |
|
| 274 | + '<strong>', |
|
| 275 | + '</strong>', |
|
| 276 | + $message, |
|
| 277 | + $version |
|
| 278 | + ); |
|
| 279 | + // don't trigger error if doing ajax, |
|
| 280 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 281 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 282 | + $error_message .= ' ' . esc_html__( |
|
| 283 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 284 | + 'event_espresso' |
|
| 285 | + ); |
|
| 286 | + $error_message .= '<ul><li>'; |
|
| 287 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 288 | + $error_message .= '</ul>'; |
|
| 289 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 290 | + // now we set this on the transient so it shows up on the next request. |
|
| 291 | + EE_Error::get_notices(false, true); |
|
| 292 | + } else { |
|
| 293 | + trigger_error($error_message, $error_type); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Logger helpers |
|
| 302 | + */ |
|
| 303 | + /** |
|
| 304 | + * debug |
|
| 305 | + * |
|
| 306 | + * @param string $class |
|
| 307 | + * @param string $func |
|
| 308 | + * @param string $line |
|
| 309 | + * @param array $info |
|
| 310 | + * @param bool $display_request |
|
| 311 | + * @param string $debug_index |
|
| 312 | + * @param string $debug_key |
|
| 313 | + * @throws EE_Error |
|
| 314 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 315 | + */ |
|
| 316 | + public static function log( |
|
| 317 | + $class = '', |
|
| 318 | + $func = '', |
|
| 319 | + $line = '', |
|
| 320 | + $info = array(), |
|
| 321 | + $display_request = false, |
|
| 322 | + $debug_index = '', |
|
| 323 | + $debug_key = 'EE_DEBUG_SPCO' |
|
| 324 | + ) { |
|
| 325 | + if (WP_DEBUG) { |
|
| 326 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 327 | + $debug_data = get_option($debug_key, array()); |
|
| 328 | + $default_data = array( |
|
| 329 | + $class => $func . '() : ' . $line, |
|
| 330 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
| 331 | + ); |
|
| 332 | + // don't serialize objects |
|
| 333 | + $info = self::strip_objects($info); |
|
| 334 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 335 | + if (! isset($debug_data[ $index ])) { |
|
| 336 | + $debug_data[ $index ] = array(); |
|
| 337 | + } |
|
| 338 | + $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
| 339 | + update_option($debug_key, $debug_data); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * strip_objects |
|
| 347 | + * |
|
| 348 | + * @param array $info |
|
| 349 | + * @return array |
|
| 350 | + */ |
|
| 351 | + public static function strip_objects($info = array()) |
|
| 352 | + { |
|
| 353 | + foreach ($info as $key => $value) { |
|
| 354 | + if (is_array($value)) { |
|
| 355 | + $info[ $key ] = self::strip_objects($value); |
|
| 356 | + } elseif (is_object($value)) { |
|
| 357 | + $object_class = get_class($value); |
|
| 358 | + $info[ $object_class ] = array(); |
|
| 359 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 360 | + if (method_exists($value, 'ID')) { |
|
| 361 | + $info[ $object_class ]['ID'] = $value->ID(); |
|
| 362 | + } |
|
| 363 | + if (method_exists($value, 'status')) { |
|
| 364 | + $info[ $object_class ]['status'] = $value->status(); |
|
| 365 | + } elseif (method_exists($value, 'status_ID')) { |
|
| 366 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
| 367 | + } |
|
| 368 | + unset($info[ $key ]); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + return (array) $info; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * @param mixed $var |
|
| 378 | + * @param string $var_name |
|
| 379 | + * @param string $file |
|
| 380 | + * @param int|string $line |
|
| 381 | + * @param int|string $heading_tag |
|
| 382 | + * @param bool $die |
|
| 383 | + * @param string $margin |
|
| 384 | + */ |
|
| 385 | + public static function printv( |
|
| 386 | + $var, |
|
| 387 | + $var_name = '', |
|
| 388 | + $file = '', |
|
| 389 | + $line = '', |
|
| 390 | + $heading_tag = 5, |
|
| 391 | + $die = false, |
|
| 392 | + $margin = '' |
|
| 393 | + ) { |
|
| 394 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
| 395 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 396 | + $is_method = method_exists($var_name, $var); |
|
| 397 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 398 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 399 | + // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 400 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 401 | + $result .= $is_method |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 405 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | + if ($die) { |
|
| 407 | + die($result); |
|
| 408 | + } |
|
| 409 | + echo $result; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + protected static function headingTag($heading_tag) |
|
| 414 | + { |
|
| 415 | + $heading_tag = absint($heading_tag); |
|
| 416 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + // protected static function headingSpacer($heading_tag) |
|
| 421 | + // { |
|
| 422 | + // return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
| 423 | + // ? EEH_Debug_Tools::lineBreak() |
|
| 424 | + // : ''; |
|
| 425 | + // } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + protected static function plainOutput() |
|
| 429 | + { |
|
| 430 | + return defined('EE_TESTS_DIR') |
|
| 431 | + || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output'])) |
|
| 432 | + || ( |
|
| 433 | + isset($_SERVER['REQUEST_URI']) |
|
| 434 | + && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
| 435 | + ); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param string $var_name |
|
| 441 | + * @param string $heading_tag |
|
| 442 | + * @param string $margin |
|
| 443 | + * @param int $line |
|
| 444 | + * @return string |
|
| 445 | + */ |
|
| 446 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
| 447 | + { |
|
| 448 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 449 | + switch ($heading_tag) { |
|
| 450 | + case 'h1': |
|
| 451 | + $line_breaks = EEH_Debug_Tools::lineBreak(3); |
|
| 452 | + break; |
|
| 453 | + case 'h2': |
|
| 454 | + $line_breaks = EEH_Debug_Tools::lineBreak(2); |
|
| 455 | + break; |
|
| 456 | + default: |
|
| 457 | + $line_breaks = EEH_Debug_Tools::lineBreak(); |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + return "{$line_breaks}{$line}) {$var_name}"; |
|
| 461 | + } |
|
| 462 | + $margin = "25px 0 0 {$margin}"; |
|
| 463 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @param string $heading_tag |
|
| 470 | + * @return string |
|
| 471 | + */ |
|
| 472 | + protected static function headingX($heading_tag = 'h5') |
|
| 473 | + { |
|
| 474 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 475 | + return ''; |
|
| 476 | + } |
|
| 477 | + return '</' . $heading_tag . '>'; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @param string $content |
|
| 484 | + * @return string |
|
| 485 | + */ |
|
| 486 | + protected static function grey_span($content = '') |
|
| 487 | + { |
|
| 488 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 489 | + return $content; |
|
| 490 | + } |
|
| 491 | + return '<span style="color:#999">' . $content . '</span>'; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * @param string $file |
|
| 498 | + * @param int $line |
|
| 499 | + * @return string |
|
| 500 | + */ |
|
| 501 | + protected static function file_and_line($file, $line, $heading_tag) |
|
| 502 | + { |
|
| 503 | + if ($file === '' || $line === '') { |
|
| 504 | + return ''; |
|
| 505 | + } |
|
| 506 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
| 507 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 508 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
| 509 | + return " ({$file})"; |
|
| 510 | + } |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + return EEH_Debug_Tools::lineBreak() |
|
| 514 | + . '<span style="display:block; font-size:9px; font-weight:normal; color:#666; line-height:12px;">' |
|
| 515 | + . $file |
|
| 516 | + . EEH_Debug_Tools::lineBreak() |
|
| 517 | + . 'line no: ' |
|
| 518 | + . $line |
|
| 519 | + . '</span>'; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * @param string $content |
|
| 526 | + * @return string |
|
| 527 | + */ |
|
| 528 | + protected static function orange_span($content = '') |
|
| 529 | + { |
|
| 530 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 531 | + return $content; |
|
| 532 | + } |
|
| 533 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @param mixed $var |
|
| 540 | + * @return string |
|
| 541 | + */ |
|
| 542 | + protected static function pre_span($var) |
|
| 543 | + { |
|
| 544 | + ob_start(); |
|
| 545 | + if(is_array($var)) { |
|
| 546 | + self::arrayDisplay($var); |
|
| 547 | + } else { |
|
| 548 | + var_dump($var); |
|
| 549 | + } |
|
| 550 | + $var = ob_get_clean(); |
|
| 551 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 552 | + return $var; |
|
| 553 | + } |
|
| 554 | + return EEH_Debug_Tools::lineBreak() |
|
| 555 | + . '<pre style="color: #9C3; display: inline-block; padding:.5em; margin: .25rem 0; background: #334">' |
|
| 556 | + . $var |
|
| 557 | + . '</pre>'; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * @param mixed $var |
|
| 564 | + * @param string $var_name |
|
| 565 | + * @param string $file |
|
| 566 | + * @param int|string $line |
|
| 567 | + * @param int|string $heading_tag |
|
| 568 | + * @param bool $die |
|
| 569 | + */ |
|
| 570 | + public static function printr( |
|
| 571 | + $var, |
|
| 572 | + $var_name = '', |
|
| 573 | + $file = '', |
|
| 574 | + $line = '', |
|
| 575 | + $heading_tag = 5, |
|
| 576 | + $die = false |
|
| 577 | + ) { |
|
| 578 | + // return; |
|
| 579 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 580 | + if (empty($var) && empty($var_name)) { |
|
| 581 | + $var = $file; |
|
| 582 | + $var_name = "line $line"; |
|
| 583 | + $file = ''; |
|
| 584 | + $line = ''; |
|
| 585 | + } |
|
| 586 | + $margin = is_admin() ? ' 180px' : '0'; |
|
| 587 | + // $print_r = false; |
|
| 588 | + if (is_string($var)) { |
|
| 589 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 590 | + return; |
|
| 591 | + } |
|
| 592 | + if (is_object($var)) { |
|
| 593 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
| 594 | + // $print_r = true; |
|
| 595 | + } elseif (is_array($var)) { |
|
| 596 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
| 597 | + // $print_r = true; |
|
| 598 | + } elseif (is_numeric($var)) { |
|
| 599 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 600 | + } elseif ($var === null) { |
|
| 601 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
| 602 | + } |
|
| 603 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 604 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 605 | + // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 606 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 607 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 608 | + EEH_Debug_Tools::pre_span($var) |
|
| 609 | + ); |
|
| 610 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 611 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 612 | + if ($die) { |
|
| 613 | + die($result); |
|
| 614 | + } |
|
| 615 | + echo $result; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + private static function lineBreak($lines = 1): string |
|
| 620 | + { |
|
| 621 | + $linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL; |
|
| 622 | + return str_repeat($linebreak, $lines); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + public static function shortClassName(string $fqcn): string |
|
| 627 | + { |
|
| 628 | + return substr(strrchr($fqcn, '\\'), 1); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * @return void |
|
| 634 | + */ |
|
| 635 | + public static function arrayDisplay(array $data, $depth = 0) |
|
| 636 | + { |
|
| 637 | + $depth++; |
|
| 638 | + $spacer = self::plainOutput() ? ' . . ' : "\t"; |
|
| 639 | + $indent = str_repeat($spacer, $depth); |
|
| 640 | + if ($depth === 1) { |
|
| 641 | + echo self::lineBreak() . '{'; |
|
| 642 | + } |
|
| 643 | + foreach ($data as $key => $child) { |
|
| 644 | + echo self::lineBreak() . $indent . $key; |
|
| 645 | + // $child = is_object($child) ? (array) $child : $child; |
|
| 646 | + if (is_array($child)) { |
|
| 647 | + echo " [ "; |
|
| 648 | + self::arrayDisplay($child, $depth); |
|
| 649 | + echo self::lineBreak() . $indent . ']'; |
|
| 650 | + } else if (is_scalar($child)) { |
|
| 651 | + echo ' => ' . $child; |
|
| 652 | + } else { |
|
| 653 | + var_export($child); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + if ($depth === 1) { |
|
| 657 | + echo self::lineBreak() . '}'; |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + /******************** deprecated ********************/ |
|
| 663 | + |
|
| 664 | + |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * @deprecated 4.9.39.rc.034 |
|
| 668 | + */ |
|
| 669 | + public function reset_times() |
|
| 670 | + { |
|
| 671 | + Benchmark::resetTimes(); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * @deprecated 4.9.39.rc.034 |
|
| 678 | + * @param null $timer_name |
|
| 679 | + */ |
|
| 680 | + public function start_timer($timer_name = null) |
|
| 681 | + { |
|
| 682 | + Benchmark::startTimer($timer_name); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * @deprecated 4.9.39.rc.034 |
|
| 689 | + * @param string $timer_name |
|
| 690 | + */ |
|
| 691 | + public function stop_timer($timer_name = '') |
|
| 692 | + { |
|
| 693 | + Benchmark::stopTimer($timer_name); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * @deprecated 4.9.39.rc.034 |
|
| 700 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 701 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 702 | + * @return void |
|
| 703 | + */ |
|
| 704 | + public function measure_memory($label, $output_now = false) |
|
| 705 | + { |
|
| 706 | + Benchmark::measureMemory($label, $output_now); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * @deprecated 4.9.39.rc.034 |
|
| 713 | + * @param int $size |
|
| 714 | + * @return string |
|
| 715 | + */ |
|
| 716 | + public function convert($size) |
|
| 717 | + { |
|
| 718 | + return Benchmark::convert($size); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * @deprecated 4.9.39.rc.034 |
|
| 725 | + * @param bool $output_now |
|
| 726 | + * @return string |
|
| 727 | + */ |
|
| 728 | + public function show_times($output_now = true) |
|
| 729 | + { |
|
| 730 | + return Benchmark::displayResults($output_now); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * @deprecated 4.9.39.rc.034 |
|
| 737 | + * @param string $timer_name |
|
| 738 | + * @param float $total_time |
|
| 739 | + * @return string |
|
| 740 | + */ |
|
| 741 | + public function format_time($timer_name, $total_time) |
|
| 742 | + { |
|
| 743 | + return Benchmark::formatTime($timer_name, $total_time); |
|
| 744 | + } |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | |
@@ -751,31 +751,31 @@ discard block |
||
| 751 | 751 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 752 | 752 | */ |
| 753 | 753 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
| 754 | - function dump_wp_query() |
|
| 755 | - { |
|
| 756 | - global $wp_query; |
|
| 757 | - d($wp_query); |
|
| 758 | - } |
|
| 754 | + function dump_wp_query() |
|
| 755 | + { |
|
| 756 | + global $wp_query; |
|
| 757 | + d($wp_query); |
|
| 758 | + } |
|
| 759 | 759 | } |
| 760 | 760 | /** |
| 761 | 761 | * borrowed from Kint Debugger |
| 762 | 762 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 763 | 763 | */ |
| 764 | 764 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
| 765 | - function dump_wp() |
|
| 766 | - { |
|
| 767 | - global $wp; |
|
| 768 | - d($wp); |
|
| 769 | - } |
|
| 765 | + function dump_wp() |
|
| 766 | + { |
|
| 767 | + global $wp; |
|
| 768 | + d($wp); |
|
| 769 | + } |
|
| 770 | 770 | } |
| 771 | 771 | /** |
| 772 | 772 | * borrowed from Kint Debugger |
| 773 | 773 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 774 | 774 | */ |
| 775 | 775 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
| 776 | - function dump_post() |
|
| 777 | - { |
|
| 778 | - global $post; |
|
| 779 | - d($post); |
|
| 780 | - } |
|
| 776 | + function dump_post() |
|
| 777 | + { |
|
| 778 | + global $post; |
|
| 779 | + d($post); |
|
| 780 | + } |
|
| 781 | 781 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | public static function instance() |
| 37 | 37 | { |
| 38 | 38 | // check if class object is instantiated, and instantiated properly |
| 39 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 39 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 40 | 40 | self::$_instance = new self(); |
| 41 | 41 | } |
| 42 | 42 | return self::$_instance; |
@@ -50,13 +50,13 @@ discard block |
||
| 50 | 50 | private function __construct() |
| 51 | 51 | { |
| 52 | 52 | // load Kint PHP debugging library |
| 53 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
| 53 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php')) { |
|
| 54 | 54 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
| 55 | 55 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
| 56 | 56 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
| 57 | 57 | // so we've moved it to our test folder so that it is not included with production releases |
| 58 | 58 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
| 59 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
| 59 | + require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php'); |
|
| 60 | 60 | } |
| 61 | 61 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
| 62 | 62 | // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public static function show_db_name() |
| 78 | 78 | { |
| 79 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 79 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 80 | 80 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
| 81 | 81 | . DB_NAME |
| 82 | 82 | . '</p>'; |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | global $wp_filter; |
| 127 | 127 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
| 128 | 128 | if ($tag) { |
| 129 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
| 130 | - if (! is_array($hook[ $tag ])) { |
|
| 129 | + $hook[$tag] = $wp_filter[$tag]; |
|
| 130 | + if ( ! is_array($hook[$tag])) { |
|
| 131 | 131 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
| 132 | 132 | return; |
| 133 | 133 | } |
| 134 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 134 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
| 135 | 135 | } else { |
| 136 | 136 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
| 137 | 137 | ksort($hook); |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | { |
| 161 | 161 | $filters = array(); |
| 162 | 162 | global $wp_filter; |
| 163 | - if (isset($wp_filter[ $hook_name ])) { |
|
| 164 | - $filters[ $hook_name ] = array(); |
|
| 165 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
| 166 | - $filters[ $hook_name ][ $priority ] = array(); |
|
| 163 | + if (isset($wp_filter[$hook_name])) { |
|
| 164 | + $filters[$hook_name] = array(); |
|
| 165 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 166 | + $filters[$hook_name][$priority] = array(); |
|
| 167 | 167 | foreach ($callbacks as $callback) { |
| 168 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
| 168 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | if (empty($activation_errors)) { |
| 188 | 188 | return; |
| 189 | 189 | } |
| 190 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 191 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 190 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
| 191 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
| 192 | 192 | if (class_exists('EEH_File')) { |
| 193 | 193 | try { |
| 194 | 194 | EEH_File::ensure_file_exists_and_is_writable( |
| 195 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
| 195 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html' |
|
| 196 | 196 | ); |
| 197 | 197 | EEH_File::write_to_file( |
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
| 199 | 199 | $activation_errors |
| 200 | 200 | ); |
| 201 | 201 | } catch (EE_Error $e) { |
@@ -215,11 +215,11 @@ discard block |
||
| 215 | 215 | } else { |
| 216 | 216 | // old school attempt |
| 217 | 217 | file_put_contents( |
| 218 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 218 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
| 219 | 219 | $activation_errors |
| 220 | 220 | ); |
| 221 | 221 | } |
| 222 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 222 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
| 223 | 223 | update_option('ee_plugin_activation_errors', $activation_errors); |
| 224 | 224 | } |
| 225 | 225 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | // don't trigger error if doing ajax, |
| 280 | 280 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
| 281 | 281 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 282 | - $error_message .= ' ' . esc_html__( |
|
| 282 | + $error_message .= ' '.esc_html__( |
|
| 283 | 283 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
| 284 | 284 | 'event_espresso' |
| 285 | 285 | ); |
@@ -323,19 +323,19 @@ discard block |
||
| 323 | 323 | $debug_key = 'EE_DEBUG_SPCO' |
| 324 | 324 | ) { |
| 325 | 325 | if (WP_DEBUG) { |
| 326 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 326 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
| 327 | 327 | $debug_data = get_option($debug_key, array()); |
| 328 | 328 | $default_data = array( |
| 329 | - $class => $func . '() : ' . $line, |
|
| 329 | + $class => $func.'() : '.$line, |
|
| 330 | 330 | 'REQ' => $display_request ? $_REQUEST : '', |
| 331 | 331 | ); |
| 332 | 332 | // don't serialize objects |
| 333 | 333 | $info = self::strip_objects($info); |
| 334 | 334 | $index = ! empty($debug_index) ? $debug_index : 0; |
| 335 | - if (! isset($debug_data[ $index ])) { |
|
| 336 | - $debug_data[ $index ] = array(); |
|
| 335 | + if ( ! isset($debug_data[$index])) { |
|
| 336 | + $debug_data[$index] = array(); |
|
| 337 | 337 | } |
| 338 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
| 338 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 339 | 339 | update_option($debug_key, $debug_data); |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -352,20 +352,20 @@ discard block |
||
| 352 | 352 | { |
| 353 | 353 | foreach ($info as $key => $value) { |
| 354 | 354 | if (is_array($value)) { |
| 355 | - $info[ $key ] = self::strip_objects($value); |
|
| 355 | + $info[$key] = self::strip_objects($value); |
|
| 356 | 356 | } elseif (is_object($value)) { |
| 357 | 357 | $object_class = get_class($value); |
| 358 | - $info[ $object_class ] = array(); |
|
| 359 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 358 | + $info[$object_class] = array(); |
|
| 359 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 360 | 360 | if (method_exists($value, 'ID')) { |
| 361 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
| 361 | + $info[$object_class]['ID'] = $value->ID(); |
|
| 362 | 362 | } |
| 363 | 363 | if (method_exists($value, 'status')) { |
| 364 | - $info[ $object_class ]['status'] = $value->status(); |
|
| 364 | + $info[$object_class]['status'] = $value->status(); |
|
| 365 | 365 | } elseif (method_exists($value, 'status_ID')) { |
| 366 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
| 366 | + $info[$object_class]['status'] = $value->status_ID(); |
|
| 367 | 367 | } |
| 368 | - unset($info[ $key ]); |
|
| 368 | + unset($info[$key]); |
|
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | return (array) $info; |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
| 400 | 400 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
| 401 | 401 | $result .= $is_method |
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
| 404 | 404 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
| 405 | 405 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
| 406 | 406 | if ($die) { |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | return "{$line_breaks}{$line}) {$var_name}"; |
| 461 | 461 | } |
| 462 | 462 | $margin = "25px 0 0 {$margin}"; |
| 463 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 463 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | if (EEH_Debug_Tools::plainOutput()) { |
| 475 | 475 | return ''; |
| 476 | 476 | } |
| 477 | - return '</' . $heading_tag . '>'; |
|
| 477 | + return '</'.$heading_tag.'>'; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | if (EEH_Debug_Tools::plainOutput()) { |
| 489 | 489 | return $content; |
| 490 | 490 | } |
| 491 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 491 | + return '<span style="color:#999">'.$content.'</span>'; |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | if (EEH_Debug_Tools::plainOutput()) { |
| 531 | 531 | return $content; |
| 532 | 532 | } |
| 533 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 533 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | protected static function pre_span($var) |
| 543 | 543 | { |
| 544 | 544 | ob_start(); |
| 545 | - if(is_array($var)) { |
|
| 545 | + if (is_array($var)) { |
|
| 546 | 546 | self::arrayDisplay($var); |
| 547 | 547 | } else { |
| 548 | 548 | var_dump($var); |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
| 605 | 605 | // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
| 606 | 606 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
| 607 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 607 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
| 608 | 608 | EEH_Debug_Tools::pre_span($var) |
| 609 | 609 | ); |
| 610 | 610 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -638,23 +638,23 @@ discard block |
||
| 638 | 638 | $spacer = self::plainOutput() ? ' . . ' : "\t"; |
| 639 | 639 | $indent = str_repeat($spacer, $depth); |
| 640 | 640 | if ($depth === 1) { |
| 641 | - echo self::lineBreak() . '{'; |
|
| 641 | + echo self::lineBreak().'{'; |
|
| 642 | 642 | } |
| 643 | 643 | foreach ($data as $key => $child) { |
| 644 | - echo self::lineBreak() . $indent . $key; |
|
| 644 | + echo self::lineBreak().$indent.$key; |
|
| 645 | 645 | // $child = is_object($child) ? (array) $child : $child; |
| 646 | 646 | if (is_array($child)) { |
| 647 | 647 | echo " [ "; |
| 648 | 648 | self::arrayDisplay($child, $depth); |
| 649 | - echo self::lineBreak() . $indent . ']'; |
|
| 649 | + echo self::lineBreak().$indent.']'; |
|
| 650 | 650 | } else if (is_scalar($child)) { |
| 651 | - echo ' => ' . $child; |
|
| 651 | + echo ' => '.$child; |
|
| 652 | 652 | } else { |
| 653 | 653 | var_export($child); |
| 654 | 654 | } |
| 655 | 655 | } |
| 656 | 656 | if ($depth === 1) { |
| 657 | - echo self::lineBreak() . '}'; |
|
| 657 | + echo self::lineBreak().'}'; |
|
| 658 | 658 | } |
| 659 | 659 | } |
| 660 | 660 | |
@@ -22,1070 +22,1070 @@ |
||
| 22 | 22 | class EE_Dependency_Map |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This means that the requested class dependency is not present in the dependency map |
|
| 27 | - */ |
|
| 28 | - const not_registered = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | - */ |
|
| 33 | - const load_new_object = 1; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | - */ |
|
| 39 | - const load_from_cache = 2; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * When registering a dependency, |
|
| 43 | - * this indicates to keep any existing dependencies that already exist, |
|
| 44 | - * and simply discard any new dependencies declared in the incoming data |
|
| 45 | - */ |
|
| 46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * When registering a dependency, |
|
| 50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | - */ |
|
| 52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @type EE_Dependency_Map $_instance |
|
| 56 | - */ |
|
| 57 | - protected static $_instance; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var ClassInterfaceCache $class_cache |
|
| 61 | - */ |
|
| 62 | - private $class_cache; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type RequestInterface $request |
|
| 66 | - */ |
|
| 67 | - protected $request; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @type LegacyRequestInterface $legacy_request |
|
| 71 | - */ |
|
| 72 | - protected $legacy_request; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type ResponseInterface $response |
|
| 76 | - */ |
|
| 77 | - protected $response; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @type LoaderInterface $loader |
|
| 81 | - */ |
|
| 82 | - protected $loader; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type array $_dependency_map |
|
| 86 | - */ |
|
| 87 | - protected $_dependency_map = []; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @type array $_class_loaders |
|
| 91 | - */ |
|
| 92 | - protected $_class_loaders = []; |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * EE_Dependency_Map constructor. |
|
| 97 | - * |
|
| 98 | - * @param ClassInterfaceCache $class_cache |
|
| 99 | - */ |
|
| 100 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
| 101 | - { |
|
| 102 | - $this->class_cache = $class_cache; |
|
| 103 | - do_action('EE_Dependency_Map____construct', $this); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return void |
|
| 109 | - * @throws InvalidAliasException |
|
| 110 | - */ |
|
| 111 | - public function initialize() |
|
| 112 | - { |
|
| 113 | - $this->_register_core_dependencies(); |
|
| 114 | - $this->_register_core_class_loaders(); |
|
| 115 | - $this->_register_core_aliases(); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @singleton method used to instantiate class object |
|
| 121 | - * @param ClassInterfaceCache|null $class_cache |
|
| 122 | - * @return EE_Dependency_Map |
|
| 123 | - */ |
|
| 124 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 125 | - { |
|
| 126 | - // check if class object is instantiated, and instantiated properly |
|
| 127 | - if ( |
|
| 128 | - ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
| 129 | - && $class_cache instanceof ClassInterfaceCache |
|
| 130 | - ) { |
|
| 131 | - EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
| 132 | - } |
|
| 133 | - return EE_Dependency_Map::$_instance; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param RequestInterface $request |
|
| 139 | - */ |
|
| 140 | - public function setRequest(RequestInterface $request) |
|
| 141 | - { |
|
| 142 | - $this->request = $request; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param LegacyRequestInterface $legacy_request |
|
| 148 | - */ |
|
| 149 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 150 | - { |
|
| 151 | - $this->legacy_request = $legacy_request; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param ResponseInterface $response |
|
| 157 | - */ |
|
| 158 | - public function setResponse(ResponseInterface $response) |
|
| 159 | - { |
|
| 160 | - $this->response = $response; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param LoaderInterface $loader |
|
| 166 | - */ |
|
| 167 | - public function setLoader(LoaderInterface $loader) |
|
| 168 | - { |
|
| 169 | - $this->loader = $loader; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param string $class |
|
| 175 | - * @param array $dependencies |
|
| 176 | - * @param int $overwrite |
|
| 177 | - * @return bool |
|
| 178 | - */ |
|
| 179 | - public static function register_dependencies( |
|
| 180 | - $class, |
|
| 181 | - array $dependencies, |
|
| 182 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 183 | - ) { |
|
| 184 | - return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 190 | - * to the class specified by the first parameter. |
|
| 191 | - * IMPORTANT !!! |
|
| 192 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 193 | - * the order of the constructor parameters for the class in question. |
|
| 194 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 195 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 196 | - * |
|
| 197 | - * @param string $class |
|
| 198 | - * @param array $dependencies |
|
| 199 | - * @param int $overwrite |
|
| 200 | - * @return bool |
|
| 201 | - */ |
|
| 202 | - public function registerDependencies( |
|
| 203 | - $class, |
|
| 204 | - array $dependencies, |
|
| 205 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 206 | - ) { |
|
| 207 | - $class = trim($class, '\\'); |
|
| 208 | - $registered = false; |
|
| 209 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
| 210 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
| 211 | - } |
|
| 212 | - // we need to make sure that any aliases used when registering a dependency |
|
| 213 | - // get resolved to the correct class name |
|
| 214 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 215 | - $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
| 216 | - if ( |
|
| 217 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 218 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 219 | - ) { |
|
| 220 | - unset($dependencies[ $dependency ]); |
|
| 221 | - $dependencies[ $alias ] = $load_source; |
|
| 222 | - $registered = true; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - // now add our two lists of dependencies together. |
|
| 226 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 227 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 228 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 229 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 230 | - // especially with numerically indexed arrays |
|
| 231 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
| 232 | - // now we need to ensure that the resulting dependencies |
|
| 233 | - // array only has the entries that are required for the class |
|
| 234 | - // so first count how many dependencies were originally registered for the class |
|
| 235 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
| 236 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 237 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 238 | - // then truncate the final array to match that count |
|
| 239 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 240 | - // otherwise just take the incoming array because nothing previously existed |
|
| 241 | - : $dependencies; |
|
| 242 | - return $registered; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param string $class_name |
|
| 248 | - * @param string $loader |
|
| 249 | - * @return bool |
|
| 250 | - * @throws DomainException |
|
| 251 | - */ |
|
| 252 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 253 | - { |
|
| 254 | - return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * @param string $class_name |
|
| 260 | - * @param string $loader |
|
| 261 | - * @return bool |
|
| 262 | - * @throws DomainException |
|
| 263 | - */ |
|
| 264 | - public function registerClassLoader($class_name, $loader = 'load_core') |
|
| 265 | - { |
|
| 266 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 267 | - throw new DomainException( |
|
| 268 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 272 | - if ( |
|
| 273 | - ! is_callable($loader) |
|
| 274 | - && ( |
|
| 275 | - strpos($loader, 'load_') !== 0 |
|
| 276 | - || ! method_exists('EE_Registry', $loader) |
|
| 277 | - ) |
|
| 278 | - ) { |
|
| 279 | - throw new DomainException( |
|
| 280 | - sprintf( |
|
| 281 | - esc_html__( |
|
| 282 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 283 | - 'event_espresso' |
|
| 284 | - ), |
|
| 285 | - $loader |
|
| 286 | - ) |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
| 290 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
| 291 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 292 | - return true; |
|
| 293 | - } |
|
| 294 | - return false; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return array |
|
| 300 | - */ |
|
| 301 | - public function dependency_map() |
|
| 302 | - { |
|
| 303 | - return $this->_dependency_map; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 309 | - * |
|
| 310 | - * @param string $class_name |
|
| 311 | - * @return boolean |
|
| 312 | - */ |
|
| 313 | - public function has($class_name = '') |
|
| 314 | - { |
|
| 315 | - // all legacy models have the same dependencies |
|
| 316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 317 | - $class_name = 'LEGACY_MODELS'; |
|
| 318 | - } |
|
| 319 | - return isset($this->_dependency_map[ $class_name ]); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 325 | - * |
|
| 326 | - * @param string $class_name |
|
| 327 | - * @param string $dependency |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 331 | - { |
|
| 332 | - // all legacy models have the same dependencies |
|
| 333 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 334 | - $class_name = 'LEGACY_MODELS'; |
|
| 335 | - } |
|
| 336 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 337 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | - * |
|
| 344 | - * @param string $class_name |
|
| 345 | - * @param string $dependency |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | - { |
|
| 350 | - // all legacy models have the same dependencies |
|
| 351 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | - $class_name = 'LEGACY_MODELS'; |
|
| 353 | - } |
|
| 354 | - $dependency = $this->getFqnForAlias($dependency); |
|
| 355 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 357 | - : EE_Dependency_Map::not_registered; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * @param string $class_name |
|
| 363 | - * @return string | Closure |
|
| 364 | - */ |
|
| 365 | - public function class_loader($class_name) |
|
| 366 | - { |
|
| 367 | - // all legacy models use load_model() |
|
| 368 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 369 | - return 'load_model'; |
|
| 370 | - } |
|
| 371 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 372 | - // perform strpos() first to avoid loading regex every time we load a class |
|
| 373 | - if ( |
|
| 374 | - strpos($class_name, 'EE_CPT_') === 0 |
|
| 375 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 376 | - ) { |
|
| 377 | - return 'load_core'; |
|
| 378 | - } |
|
| 379 | - $class_name = $this->getFqnForAlias($class_name); |
|
| 380 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @return array |
|
| 386 | - */ |
|
| 387 | - public function class_loaders() |
|
| 388 | - { |
|
| 389 | - return $this->_class_loaders; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * adds an alias for a classname |
|
| 395 | - * |
|
| 396 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 397 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 398 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 399 | - * @throws InvalidAliasException |
|
| 400 | - */ |
|
| 401 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
| 402 | - { |
|
| 403 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
| 409 | - * WHY? |
|
| 410 | - * Because if a class is type hinting for a concretion, |
|
| 411 | - * then why would we need to find another class to supply it? |
|
| 412 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 413 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 414 | - * Don't go looking for some substitute. |
|
| 415 | - * Whereas if a class is type hinting for an interface... |
|
| 416 | - * then we need to find an actual class to use. |
|
| 417 | - * So the interface IS the alias for some other FQN, |
|
| 418 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 419 | - * represents some other class. |
|
| 420 | - * |
|
| 421 | - * @param string $fqn |
|
| 422 | - * @param string $for_class |
|
| 423 | - * @return bool |
|
| 424 | - */ |
|
| 425 | - public function isAlias($fqn = '', $for_class = '') |
|
| 426 | - { |
|
| 427 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 433 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 434 | - * for example: |
|
| 435 | - * if the following two entries were added to the _aliases array: |
|
| 436 | - * array( |
|
| 437 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 438 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 439 | - * ) |
|
| 440 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 441 | - * to load an instance of 'some\namespace\classname' |
|
| 442 | - * |
|
| 443 | - * @param string $alias |
|
| 444 | - * @param string $for_class |
|
| 445 | - * @return string |
|
| 446 | - */ |
|
| 447 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
| 448 | - { |
|
| 449 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 455 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 456 | - * This is done by using the following class constants: |
|
| 457 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 458 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 459 | - */ |
|
| 460 | - protected function _register_core_dependencies() |
|
| 461 | - { |
|
| 462 | - $this->_dependency_map = [ |
|
| 463 | - 'EE_Request_Handler' => [ |
|
| 464 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 465 | - ], |
|
| 466 | - 'EE_System' => [ |
|
| 467 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 469 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - ], |
|
| 473 | - 'EE_Admin' => [ |
|
| 474 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - ], |
|
| 477 | - 'EE_Cart' => [ |
|
| 478 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - ], |
|
| 480 | - 'EE_Messenger_Collection_Loader' => [ |
|
| 481 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | - ], |
|
| 483 | - 'EE_Message_Type_Collection_Loader' => [ |
|
| 484 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 485 | - ], |
|
| 486 | - 'EE_Message_Resource_Manager' => [ |
|
| 487 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 488 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 489 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 490 | - ], |
|
| 491 | - 'EE_Message_Factory' => [ |
|
| 492 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 493 | - ], |
|
| 494 | - 'EE_messages' => [ |
|
| 495 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - ], |
|
| 497 | - 'EE_Messages_Generator' => [ |
|
| 498 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 499 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 500 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 501 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 502 | - ], |
|
| 503 | - 'EE_Messages_Processor' => [ |
|
| 504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 505 | - ], |
|
| 506 | - 'EE_Messages_Queue' => [ |
|
| 507 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 508 | - ], |
|
| 509 | - 'EE_Messages_Template_Defaults' => [ |
|
| 510 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 512 | - ], |
|
| 513 | - 'EE_Message_To_Generate_From_Request' => [ |
|
| 514 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 516 | - ], |
|
| 517 | - 'EventEspresso\core\services\commands\CommandBus' => [ |
|
| 518 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 519 | - ], |
|
| 520 | - 'EventEspresso\services\commands\CommandHandler' => [ |
|
| 521 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 522 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ], |
|
| 524 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
| 525 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ], |
|
| 527 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
| 528 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 530 | - ], |
|
| 531 | - 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
| 532 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 533 | - ], |
|
| 534 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
| 535 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 536 | - ], |
|
| 537 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
| 538 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 539 | - ], |
|
| 540 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
| 541 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 542 | - ], |
|
| 543 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
| 544 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 545 | - ], |
|
| 546 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
| 547 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 548 | - ], |
|
| 549 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
| 550 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 551 | - ], |
|
| 552 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
| 553 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 554 | - ], |
|
| 555 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
| 556 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 557 | - ], |
|
| 558 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
| 559 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 560 | - ], |
|
| 561 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
| 562 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 563 | - ], |
|
| 564 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
| 565 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 566 | - ], |
|
| 567 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
| 568 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 569 | - ], |
|
| 570 | - 'EventEspresso\core\services\database\TableManager' => [ |
|
| 571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | - ], |
|
| 573 | - 'EE_Data_Migration_Class_Base' => [ |
|
| 574 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 575 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 576 | - ], |
|
| 577 | - 'EE_DMS_Core_4_1_0' => [ |
|
| 578 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 579 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 580 | - ], |
|
| 581 | - 'EE_DMS_Core_4_2_0' => [ |
|
| 582 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 584 | - ], |
|
| 585 | - 'EE_DMS_Core_4_3_0' => [ |
|
| 586 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 587 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - ], |
|
| 589 | - 'EE_DMS_Core_4_4_0' => [ |
|
| 590 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 592 | - ], |
|
| 593 | - 'EE_DMS_Core_4_5_0' => [ |
|
| 594 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 595 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 596 | - ], |
|
| 597 | - 'EE_DMS_Core_4_6_0' => [ |
|
| 598 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 599 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ], |
|
| 601 | - 'EE_DMS_Core_4_7_0' => [ |
|
| 602 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 604 | - ], |
|
| 605 | - 'EE_DMS_Core_4_8_0' => [ |
|
| 606 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | - ], |
|
| 609 | - 'EE_DMS_Core_4_9_0' => [ |
|
| 610 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | - ], |
|
| 613 | - 'EE_DMS_Core_4_10_0' => [ |
|
| 614 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 616 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 617 | - ], |
|
| 618 | - 'EE_DMS_Core_4_11_0' => [ |
|
| 619 | - 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
| 620 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 621 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 622 | - ], |
|
| 623 | - 'EE_DMS_Core_4_12_0' => [ |
|
| 624 | - 'EE_DMS_Core_4_11_0' => EE_Dependency_Map::load_from_cache, |
|
| 625 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 626 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 627 | - ], |
|
| 628 | - 'EventEspresso\core\services\assets\Registry' => [ |
|
| 629 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
| 630 | - 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
| 631 | - ], |
|
| 632 | - 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
| 633 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 634 | - ], |
|
| 635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
| 636 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 637 | - ], |
|
| 638 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
| 639 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 640 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 641 | - ], |
|
| 642 | - 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
| 643 | - null, |
|
| 644 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 645 | - ], |
|
| 646 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
| 647 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 648 | - ], |
|
| 649 | - 'LEGACY_MODELS' => [ |
|
| 650 | - null, |
|
| 651 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 652 | - ], |
|
| 653 | - 'EE_Module_Request_Router' => [ |
|
| 654 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 655 | - ], |
|
| 656 | - 'EE_Registration_Processor' => [ |
|
| 657 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 658 | - ], |
|
| 659 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
| 660 | - null, |
|
| 661 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 662 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 663 | - ], |
|
| 664 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
| 665 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 666 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 667 | - ], |
|
| 668 | - 'EventEspresso\modules\ticket_selector\DisplayTicketSelector' => [ |
|
| 669 | - 'EventEspresso\core\domain\entities\users\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
| 670 | - ], |
|
| 671 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
| 672 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 673 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 674 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 675 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 676 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 677 | - ], |
|
| 678 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
| 679 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 680 | - ], |
|
| 681 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
| 682 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 683 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 684 | - ], |
|
| 685 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
| 686 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 687 | - ], |
|
| 688 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
| 689 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 690 | - ], |
|
| 691 | - 'EE_CPT_Strategy' => [ |
|
| 692 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 693 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 694 | - ], |
|
| 695 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
| 696 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 697 | - ], |
|
| 698 | - 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
| 699 | - null, |
|
| 700 | - null, |
|
| 701 | - null, |
|
| 702 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 703 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 704 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 705 | - ], |
|
| 706 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
| 707 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 708 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 709 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 710 | - ], |
|
| 711 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
| 712 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 713 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 714 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 715 | - ], |
|
| 716 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
| 717 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 718 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 719 | - ], |
|
| 720 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
| 721 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 722 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 723 | - ], |
|
| 724 | - 'EE_URL_Validation_Strategy' => [ |
|
| 725 | - null, |
|
| 726 | - null, |
|
| 727 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
| 728 | - ], |
|
| 729 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
| 730 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 731 | - ], |
|
| 732 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 733 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 734 | - ], |
|
| 735 | - 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
| 736 | - 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
| 737 | - 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
| 738 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
| 739 | - null, |
|
| 740 | - ], |
|
| 741 | - 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
| 742 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
| 743 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 744 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 745 | - 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
| 746 | - ], |
|
| 747 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
| 748 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
| 749 | - ], |
|
| 750 | - 'EventEspresso\core\services\routing\Router' => [ |
|
| 751 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 752 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 753 | - 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
| 754 | - ], |
|
| 755 | - 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
| 756 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 757 | - ], |
|
| 758 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
| 759 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 760 | - ], |
|
| 761 | - 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
| 762 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
| 763 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 764 | - ], |
|
| 765 | - 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
| 766 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 767 | - ], |
|
| 768 | - 'EventEspresso\core\services\addon\AddonManager' => [ |
|
| 769 | - 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
| 770 | - 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
| 771 | - 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
| 772 | - 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
| 773 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
| 774 | - ], |
|
| 775 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
| 776 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 777 | - ], |
|
| 778 | - 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
| 779 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 780 | - ], |
|
| 781 | - 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
| 782 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 783 | - ], |
|
| 784 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
| 785 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 786 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 787 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 788 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 789 | - ], |
|
| 790 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
| 791 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 792 | - ], |
|
| 793 | - 'EventEspresso\core\domain\entities\users\CurrentUser' => [ |
|
| 794 | - 'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache, |
|
| 795 | - ], |
|
| 796 | - 'EventEspresso\core\services\form\meta\InputTypes' => [ |
|
| 797 | - 'EventEspresso\core\services\form\meta\inputs\Block' => EE_Dependency_Map::load_from_cache, |
|
| 798 | - 'EventEspresso\core\services\form\meta\inputs\Button' => EE_Dependency_Map::load_from_cache, |
|
| 799 | - 'EventEspresso\core\services\form\meta\inputs\DateTime' => EE_Dependency_Map::load_from_cache, |
|
| 800 | - 'EventEspresso\core\services\form\meta\inputs\Input' => EE_Dependency_Map::load_from_cache, |
|
| 801 | - 'EventEspresso\core\services\form\meta\inputs\Number' => EE_Dependency_Map::load_from_cache, |
|
| 802 | - 'EventEspresso\core\services\form\meta\inputs\Phone' => EE_Dependency_Map::load_from_cache, |
|
| 803 | - 'EventEspresso\core\services\form\meta\inputs\Select' => EE_Dependency_Map::load_from_cache, |
|
| 804 | - 'EventEspresso\core\services\form\meta\inputs\Text' => EE_Dependency_Map::load_from_cache, |
|
| 805 | - ], |
|
| 806 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormDependencyHandler' => [ |
|
| 807 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 808 | - ], |
|
| 809 | - 'EventEspresso\core\domain\services\registration\form\v2\RegFormDependencyHandler' => [ |
|
| 810 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 811 | - ], |
|
| 812 | - 'EventEspresso\core\services\calculators\LineItemCalculator' => [ |
|
| 813 | - 'EventEspresso\core\services\helpers\DecimalValues' => EE_Dependency_Map::load_from_cache, |
|
| 814 | - ], |
|
| 815 | - 'EventEspresso\core\services\helpers\DecimalValues' => [ |
|
| 816 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 817 | - ], |
|
| 818 | - ]; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Registers how core classes are loaded. |
|
| 824 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 825 | - * 'EE_Request_Handler' => 'load_core' |
|
| 826 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 827 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 828 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 829 | - * 'Some_Class' => function () { |
|
| 830 | - * return new Some_Class(); |
|
| 831 | - * }, |
|
| 832 | - * This is required for instantiating dependencies |
|
| 833 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 834 | - * 'Required_Interface' => function () { |
|
| 835 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 836 | - * }, |
|
| 837 | - */ |
|
| 838 | - protected function _register_core_class_loaders() |
|
| 839 | - { |
|
| 840 | - $this->_class_loaders = [ |
|
| 841 | - // load_core |
|
| 842 | - 'EE_Dependency_Map' => function () { |
|
| 843 | - return $this; |
|
| 844 | - }, |
|
| 845 | - 'EE_Capabilities' => 'load_core', |
|
| 846 | - 'EE_Encryption' => 'load_core', |
|
| 847 | - 'EE_Front_Controller' => 'load_core', |
|
| 848 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 849 | - 'EE_Registry' => 'load_core', |
|
| 850 | - 'EE_Request' => function () { |
|
| 851 | - return $this->legacy_request; |
|
| 852 | - }, |
|
| 853 | - 'EventEspresso\core\services\request\Request' => function () { |
|
| 854 | - return $this->request; |
|
| 855 | - }, |
|
| 856 | - 'EventEspresso\core\services\request\Response' => function () { |
|
| 857 | - return $this->response; |
|
| 858 | - }, |
|
| 859 | - 'EE_Base' => 'load_core', |
|
| 860 | - 'EE_Request_Handler' => 'load_core', |
|
| 861 | - 'EE_Session' => 'load_core', |
|
| 862 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 863 | - 'EE_System' => 'load_core', |
|
| 864 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 865 | - 'EE_Register_CPTs' => 'load_core', |
|
| 866 | - 'EE_Admin' => 'load_core', |
|
| 867 | - 'EE_CPT_Strategy' => 'load_core', |
|
| 868 | - // load_class |
|
| 869 | - 'EE_Registration_Processor' => 'load_class', |
|
| 870 | - // load_lib |
|
| 871 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 872 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 873 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 874 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 875 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 876 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 877 | - 'EE_Message_Repository' => 'load_lib', |
|
| 878 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 879 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 880 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 881 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 882 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 883 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 884 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 885 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 886 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 887 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 888 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 889 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 890 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 891 | - 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
| 892 | - 'EE_DMS_Core_4_12_0' => 'load_dms', |
|
| 893 | - 'EE_Messages_Generator' => static function () { |
|
| 894 | - return EE_Registry::instance()->load_lib( |
|
| 895 | - 'Messages_Generator', |
|
| 896 | - [], |
|
| 897 | - false, |
|
| 898 | - false |
|
| 899 | - ); |
|
| 900 | - }, |
|
| 901 | - 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
| 902 | - return EE_Registry::instance()->load_lib( |
|
| 903 | - 'Messages_Template_Defaults', |
|
| 904 | - $arguments, |
|
| 905 | - false, |
|
| 906 | - false |
|
| 907 | - ); |
|
| 908 | - }, |
|
| 909 | - // load_helper |
|
| 910 | - 'EEH_Parse_Shortcodes' => static function () { |
|
| 911 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 912 | - return new EEH_Parse_Shortcodes(); |
|
| 913 | - } |
|
| 914 | - return null; |
|
| 915 | - }, |
|
| 916 | - 'EE_Template_Config' => static function () { |
|
| 917 | - return EE_Config::instance()->template_settings; |
|
| 918 | - }, |
|
| 919 | - 'EE_Currency_Config' => static function () { |
|
| 920 | - return EE_Config::instance()->currency; |
|
| 921 | - }, |
|
| 922 | - 'EE_Registration_Config' => static function () { |
|
| 923 | - return EE_Config::instance()->registration; |
|
| 924 | - }, |
|
| 925 | - 'EE_Core_Config' => static function () { |
|
| 926 | - return EE_Config::instance()->core; |
|
| 927 | - }, |
|
| 928 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
| 929 | - return LoaderFactory::getLoader(); |
|
| 930 | - }, |
|
| 931 | - 'EE_Network_Config' => static function () { |
|
| 932 | - return EE_Network_Config::instance(); |
|
| 933 | - }, |
|
| 934 | - 'EE_Config' => static function () { |
|
| 935 | - return EE_Config::instance(); |
|
| 936 | - }, |
|
| 937 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
| 938 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
| 939 | - }, |
|
| 940 | - 'EE_Admin_Config' => static function () { |
|
| 941 | - return EE_Config::instance()->admin; |
|
| 942 | - }, |
|
| 943 | - 'EE_Organization_Config' => static function () { |
|
| 944 | - return EE_Config::instance()->organization; |
|
| 945 | - }, |
|
| 946 | - 'EE_Network_Core_Config' => static function () { |
|
| 947 | - return EE_Network_Config::instance()->core; |
|
| 948 | - }, |
|
| 949 | - 'EE_Environment_Config' => static function () { |
|
| 950 | - return EE_Config::instance()->environment; |
|
| 951 | - }, |
|
| 952 | - 'EED_Core_Rest_Api' => static function () { |
|
| 953 | - return EED_Core_Rest_Api::instance(); |
|
| 954 | - }, |
|
| 955 | - 'WP_REST_Server' => static function () { |
|
| 956 | - return rest_get_server(); |
|
| 957 | - }, |
|
| 958 | - 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
| 959 | - return EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 960 | - }, |
|
| 961 | - ]; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * can be used for supplying alternate names for classes, |
|
| 967 | - * or for connecting interface names to instantiable classes |
|
| 968 | - * |
|
| 969 | - * @throws InvalidAliasException |
|
| 970 | - */ |
|
| 971 | - protected function _register_core_aliases() |
|
| 972 | - { |
|
| 973 | - $aliases = [ |
|
| 974 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 975 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 976 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 977 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 978 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 979 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 980 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 981 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 982 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 983 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 984 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 985 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 986 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 987 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 988 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 989 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 990 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 991 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 992 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 993 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 994 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 995 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 996 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 997 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 998 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 999 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 1000 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 1001 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 1002 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 1003 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 1004 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 1005 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 1006 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 1007 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 1008 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 1009 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 1010 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 1011 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 1012 | - 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
| 1013 | - ]; |
|
| 1014 | - foreach ($aliases as $alias => $fqn) { |
|
| 1015 | - if (is_array($fqn)) { |
|
| 1016 | - foreach ($fqn as $class => $for_class) { |
|
| 1017 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 1018 | - } |
|
| 1019 | - continue; |
|
| 1020 | - } |
|
| 1021 | - $this->class_cache->addAlias($fqn, $alias); |
|
| 1022 | - } |
|
| 1023 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1024 | - $this->class_cache->addAlias( |
|
| 1025 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 1026 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 1027 | - ); |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 1034 | - * request Primarily used by unit tests. |
|
| 1035 | - */ |
|
| 1036 | - public function reset() |
|
| 1037 | - { |
|
| 1038 | - $this->_register_core_class_loaders(); |
|
| 1039 | - $this->_register_core_dependencies(); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
| 1045 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 1046 | - * WHY? |
|
| 1047 | - * Because if a class is type hinting for a concretion, |
|
| 1048 | - * then why would we need to find another class to supply it? |
|
| 1049 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1050 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1051 | - * Don't go looking for some substitute. |
|
| 1052 | - * Whereas if a class is type hinting for an interface... |
|
| 1053 | - * then we need to find an actual class to use. |
|
| 1054 | - * So the interface IS the alias for some other FQN, |
|
| 1055 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1056 | - * represents some other class. |
|
| 1057 | - * |
|
| 1058 | - * @param string $fqn |
|
| 1059 | - * @param string $for_class |
|
| 1060 | - * @return bool |
|
| 1061 | - * @deprecated 4.9.62.p |
|
| 1062 | - */ |
|
| 1063 | - public function has_alias($fqn = '', $for_class = '') |
|
| 1064 | - { |
|
| 1065 | - return $this->isAlias($fqn, $for_class); |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1071 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1072 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1073 | - * for example: |
|
| 1074 | - * if the following two entries were added to the _aliases array: |
|
| 1075 | - * array( |
|
| 1076 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 1077 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1078 | - * ) |
|
| 1079 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1080 | - * to load an instance of 'some\namespace\classname' |
|
| 1081 | - * |
|
| 1082 | - * @param string $alias |
|
| 1083 | - * @param string $for_class |
|
| 1084 | - * @return string |
|
| 1085 | - * @deprecated 4.9.62.p |
|
| 1086 | - */ |
|
| 1087 | - public function get_alias($alias = '', $for_class = '') |
|
| 1088 | - { |
|
| 1089 | - return $this->getFqnForAlias($alias, $for_class); |
|
| 1090 | - } |
|
| 25 | + /** |
|
| 26 | + * This means that the requested class dependency is not present in the dependency map |
|
| 27 | + */ |
|
| 28 | + const not_registered = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | + */ |
|
| 33 | + const load_new_object = 1; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | + */ |
|
| 39 | + const load_from_cache = 2; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * When registering a dependency, |
|
| 43 | + * this indicates to keep any existing dependencies that already exist, |
|
| 44 | + * and simply discard any new dependencies declared in the incoming data |
|
| 45 | + */ |
|
| 46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * When registering a dependency, |
|
| 50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | + */ |
|
| 52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @type EE_Dependency_Map $_instance |
|
| 56 | + */ |
|
| 57 | + protected static $_instance; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var ClassInterfaceCache $class_cache |
|
| 61 | + */ |
|
| 62 | + private $class_cache; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type RequestInterface $request |
|
| 66 | + */ |
|
| 67 | + protected $request; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @type LegacyRequestInterface $legacy_request |
|
| 71 | + */ |
|
| 72 | + protected $legacy_request; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type ResponseInterface $response |
|
| 76 | + */ |
|
| 77 | + protected $response; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @type LoaderInterface $loader |
|
| 81 | + */ |
|
| 82 | + protected $loader; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type array $_dependency_map |
|
| 86 | + */ |
|
| 87 | + protected $_dependency_map = []; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @type array $_class_loaders |
|
| 91 | + */ |
|
| 92 | + protected $_class_loaders = []; |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * EE_Dependency_Map constructor. |
|
| 97 | + * |
|
| 98 | + * @param ClassInterfaceCache $class_cache |
|
| 99 | + */ |
|
| 100 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
| 101 | + { |
|
| 102 | + $this->class_cache = $class_cache; |
|
| 103 | + do_action('EE_Dependency_Map____construct', $this); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return void |
|
| 109 | + * @throws InvalidAliasException |
|
| 110 | + */ |
|
| 111 | + public function initialize() |
|
| 112 | + { |
|
| 113 | + $this->_register_core_dependencies(); |
|
| 114 | + $this->_register_core_class_loaders(); |
|
| 115 | + $this->_register_core_aliases(); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @singleton method used to instantiate class object |
|
| 121 | + * @param ClassInterfaceCache|null $class_cache |
|
| 122 | + * @return EE_Dependency_Map |
|
| 123 | + */ |
|
| 124 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 125 | + { |
|
| 126 | + // check if class object is instantiated, and instantiated properly |
|
| 127 | + if ( |
|
| 128 | + ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
| 129 | + && $class_cache instanceof ClassInterfaceCache |
|
| 130 | + ) { |
|
| 131 | + EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
| 132 | + } |
|
| 133 | + return EE_Dependency_Map::$_instance; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param RequestInterface $request |
|
| 139 | + */ |
|
| 140 | + public function setRequest(RequestInterface $request) |
|
| 141 | + { |
|
| 142 | + $this->request = $request; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param LegacyRequestInterface $legacy_request |
|
| 148 | + */ |
|
| 149 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 150 | + { |
|
| 151 | + $this->legacy_request = $legacy_request; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param ResponseInterface $response |
|
| 157 | + */ |
|
| 158 | + public function setResponse(ResponseInterface $response) |
|
| 159 | + { |
|
| 160 | + $this->response = $response; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param LoaderInterface $loader |
|
| 166 | + */ |
|
| 167 | + public function setLoader(LoaderInterface $loader) |
|
| 168 | + { |
|
| 169 | + $this->loader = $loader; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param string $class |
|
| 175 | + * @param array $dependencies |
|
| 176 | + * @param int $overwrite |
|
| 177 | + * @return bool |
|
| 178 | + */ |
|
| 179 | + public static function register_dependencies( |
|
| 180 | + $class, |
|
| 181 | + array $dependencies, |
|
| 182 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 183 | + ) { |
|
| 184 | + return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 190 | + * to the class specified by the first parameter. |
|
| 191 | + * IMPORTANT !!! |
|
| 192 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 193 | + * the order of the constructor parameters for the class in question. |
|
| 194 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 195 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 196 | + * |
|
| 197 | + * @param string $class |
|
| 198 | + * @param array $dependencies |
|
| 199 | + * @param int $overwrite |
|
| 200 | + * @return bool |
|
| 201 | + */ |
|
| 202 | + public function registerDependencies( |
|
| 203 | + $class, |
|
| 204 | + array $dependencies, |
|
| 205 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 206 | + ) { |
|
| 207 | + $class = trim($class, '\\'); |
|
| 208 | + $registered = false; |
|
| 209 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
| 210 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
| 211 | + } |
|
| 212 | + // we need to make sure that any aliases used when registering a dependency |
|
| 213 | + // get resolved to the correct class name |
|
| 214 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 215 | + $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
| 216 | + if ( |
|
| 217 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 218 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 219 | + ) { |
|
| 220 | + unset($dependencies[ $dependency ]); |
|
| 221 | + $dependencies[ $alias ] = $load_source; |
|
| 222 | + $registered = true; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + // now add our two lists of dependencies together. |
|
| 226 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 227 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 228 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 229 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 230 | + // especially with numerically indexed arrays |
|
| 231 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
| 232 | + // now we need to ensure that the resulting dependencies |
|
| 233 | + // array only has the entries that are required for the class |
|
| 234 | + // so first count how many dependencies were originally registered for the class |
|
| 235 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
| 236 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 237 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 238 | + // then truncate the final array to match that count |
|
| 239 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 240 | + // otherwise just take the incoming array because nothing previously existed |
|
| 241 | + : $dependencies; |
|
| 242 | + return $registered; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param string $class_name |
|
| 248 | + * @param string $loader |
|
| 249 | + * @return bool |
|
| 250 | + * @throws DomainException |
|
| 251 | + */ |
|
| 252 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 253 | + { |
|
| 254 | + return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * @param string $class_name |
|
| 260 | + * @param string $loader |
|
| 261 | + * @return bool |
|
| 262 | + * @throws DomainException |
|
| 263 | + */ |
|
| 264 | + public function registerClassLoader($class_name, $loader = 'load_core') |
|
| 265 | + { |
|
| 266 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 267 | + throw new DomainException( |
|
| 268 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 272 | + if ( |
|
| 273 | + ! is_callable($loader) |
|
| 274 | + && ( |
|
| 275 | + strpos($loader, 'load_') !== 0 |
|
| 276 | + || ! method_exists('EE_Registry', $loader) |
|
| 277 | + ) |
|
| 278 | + ) { |
|
| 279 | + throw new DomainException( |
|
| 280 | + sprintf( |
|
| 281 | + esc_html__( |
|
| 282 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 283 | + 'event_espresso' |
|
| 284 | + ), |
|
| 285 | + $loader |
|
| 286 | + ) |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
| 290 | + if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
| 291 | + EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 292 | + return true; |
|
| 293 | + } |
|
| 294 | + return false; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return array |
|
| 300 | + */ |
|
| 301 | + public function dependency_map() |
|
| 302 | + { |
|
| 303 | + return $this->_dependency_map; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 309 | + * |
|
| 310 | + * @param string $class_name |
|
| 311 | + * @return boolean |
|
| 312 | + */ |
|
| 313 | + public function has($class_name = '') |
|
| 314 | + { |
|
| 315 | + // all legacy models have the same dependencies |
|
| 316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 317 | + $class_name = 'LEGACY_MODELS'; |
|
| 318 | + } |
|
| 319 | + return isset($this->_dependency_map[ $class_name ]); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 325 | + * |
|
| 326 | + * @param string $class_name |
|
| 327 | + * @param string $dependency |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 331 | + { |
|
| 332 | + // all legacy models have the same dependencies |
|
| 333 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 334 | + $class_name = 'LEGACY_MODELS'; |
|
| 335 | + } |
|
| 336 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 337 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | + * |
|
| 344 | + * @param string $class_name |
|
| 345 | + * @param string $dependency |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | + { |
|
| 350 | + // all legacy models have the same dependencies |
|
| 351 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | + $class_name = 'LEGACY_MODELS'; |
|
| 353 | + } |
|
| 354 | + $dependency = $this->getFqnForAlias($dependency); |
|
| 355 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 357 | + : EE_Dependency_Map::not_registered; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * @param string $class_name |
|
| 363 | + * @return string | Closure |
|
| 364 | + */ |
|
| 365 | + public function class_loader($class_name) |
|
| 366 | + { |
|
| 367 | + // all legacy models use load_model() |
|
| 368 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 369 | + return 'load_model'; |
|
| 370 | + } |
|
| 371 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 372 | + // perform strpos() first to avoid loading regex every time we load a class |
|
| 373 | + if ( |
|
| 374 | + strpos($class_name, 'EE_CPT_') === 0 |
|
| 375 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 376 | + ) { |
|
| 377 | + return 'load_core'; |
|
| 378 | + } |
|
| 379 | + $class_name = $this->getFqnForAlias($class_name); |
|
| 380 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @return array |
|
| 386 | + */ |
|
| 387 | + public function class_loaders() |
|
| 388 | + { |
|
| 389 | + return $this->_class_loaders; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * adds an alias for a classname |
|
| 395 | + * |
|
| 396 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 397 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 398 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 399 | + * @throws InvalidAliasException |
|
| 400 | + */ |
|
| 401 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
| 402 | + { |
|
| 403 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
| 409 | + * WHY? |
|
| 410 | + * Because if a class is type hinting for a concretion, |
|
| 411 | + * then why would we need to find another class to supply it? |
|
| 412 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 413 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 414 | + * Don't go looking for some substitute. |
|
| 415 | + * Whereas if a class is type hinting for an interface... |
|
| 416 | + * then we need to find an actual class to use. |
|
| 417 | + * So the interface IS the alias for some other FQN, |
|
| 418 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 419 | + * represents some other class. |
|
| 420 | + * |
|
| 421 | + * @param string $fqn |
|
| 422 | + * @param string $for_class |
|
| 423 | + * @return bool |
|
| 424 | + */ |
|
| 425 | + public function isAlias($fqn = '', $for_class = '') |
|
| 426 | + { |
|
| 427 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 433 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 434 | + * for example: |
|
| 435 | + * if the following two entries were added to the _aliases array: |
|
| 436 | + * array( |
|
| 437 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 438 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 439 | + * ) |
|
| 440 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 441 | + * to load an instance of 'some\namespace\classname' |
|
| 442 | + * |
|
| 443 | + * @param string $alias |
|
| 444 | + * @param string $for_class |
|
| 445 | + * @return string |
|
| 446 | + */ |
|
| 447 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
| 448 | + { |
|
| 449 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 455 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 456 | + * This is done by using the following class constants: |
|
| 457 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 458 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 459 | + */ |
|
| 460 | + protected function _register_core_dependencies() |
|
| 461 | + { |
|
| 462 | + $this->_dependency_map = [ |
|
| 463 | + 'EE_Request_Handler' => [ |
|
| 464 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 465 | + ], |
|
| 466 | + 'EE_System' => [ |
|
| 467 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 469 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + ], |
|
| 473 | + 'EE_Admin' => [ |
|
| 474 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + ], |
|
| 477 | + 'EE_Cart' => [ |
|
| 478 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + ], |
|
| 480 | + 'EE_Messenger_Collection_Loader' => [ |
|
| 481 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | + ], |
|
| 483 | + 'EE_Message_Type_Collection_Loader' => [ |
|
| 484 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 485 | + ], |
|
| 486 | + 'EE_Message_Resource_Manager' => [ |
|
| 487 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 488 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 489 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 490 | + ], |
|
| 491 | + 'EE_Message_Factory' => [ |
|
| 492 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 493 | + ], |
|
| 494 | + 'EE_messages' => [ |
|
| 495 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + ], |
|
| 497 | + 'EE_Messages_Generator' => [ |
|
| 498 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 499 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 500 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 501 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 502 | + ], |
|
| 503 | + 'EE_Messages_Processor' => [ |
|
| 504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 505 | + ], |
|
| 506 | + 'EE_Messages_Queue' => [ |
|
| 507 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 508 | + ], |
|
| 509 | + 'EE_Messages_Template_Defaults' => [ |
|
| 510 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 512 | + ], |
|
| 513 | + 'EE_Message_To_Generate_From_Request' => [ |
|
| 514 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 516 | + ], |
|
| 517 | + 'EventEspresso\core\services\commands\CommandBus' => [ |
|
| 518 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 519 | + ], |
|
| 520 | + 'EventEspresso\services\commands\CommandHandler' => [ |
|
| 521 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 522 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ], |
|
| 524 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
| 525 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ], |
|
| 527 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
| 528 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 530 | + ], |
|
| 531 | + 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
| 532 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 533 | + ], |
|
| 534 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
| 535 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 536 | + ], |
|
| 537 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
| 538 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 539 | + ], |
|
| 540 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
| 541 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 542 | + ], |
|
| 543 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
| 544 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 545 | + ], |
|
| 546 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
| 547 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 548 | + ], |
|
| 549 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
| 550 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 551 | + ], |
|
| 552 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
| 553 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 554 | + ], |
|
| 555 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
| 556 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 557 | + ], |
|
| 558 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
| 559 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 560 | + ], |
|
| 561 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
| 562 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 563 | + ], |
|
| 564 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
| 565 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 566 | + ], |
|
| 567 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
| 568 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 569 | + ], |
|
| 570 | + 'EventEspresso\core\services\database\TableManager' => [ |
|
| 571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | + ], |
|
| 573 | + 'EE_Data_Migration_Class_Base' => [ |
|
| 574 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 575 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 576 | + ], |
|
| 577 | + 'EE_DMS_Core_4_1_0' => [ |
|
| 578 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 579 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 580 | + ], |
|
| 581 | + 'EE_DMS_Core_4_2_0' => [ |
|
| 582 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 584 | + ], |
|
| 585 | + 'EE_DMS_Core_4_3_0' => [ |
|
| 586 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 587 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + ], |
|
| 589 | + 'EE_DMS_Core_4_4_0' => [ |
|
| 590 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 592 | + ], |
|
| 593 | + 'EE_DMS_Core_4_5_0' => [ |
|
| 594 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 595 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 596 | + ], |
|
| 597 | + 'EE_DMS_Core_4_6_0' => [ |
|
| 598 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 599 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ], |
|
| 601 | + 'EE_DMS_Core_4_7_0' => [ |
|
| 602 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 604 | + ], |
|
| 605 | + 'EE_DMS_Core_4_8_0' => [ |
|
| 606 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | + ], |
|
| 609 | + 'EE_DMS_Core_4_9_0' => [ |
|
| 610 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | + ], |
|
| 613 | + 'EE_DMS_Core_4_10_0' => [ |
|
| 614 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 616 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 617 | + ], |
|
| 618 | + 'EE_DMS_Core_4_11_0' => [ |
|
| 619 | + 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
| 620 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 621 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 622 | + ], |
|
| 623 | + 'EE_DMS_Core_4_12_0' => [ |
|
| 624 | + 'EE_DMS_Core_4_11_0' => EE_Dependency_Map::load_from_cache, |
|
| 625 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 626 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 627 | + ], |
|
| 628 | + 'EventEspresso\core\services\assets\Registry' => [ |
|
| 629 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
| 630 | + 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
| 631 | + ], |
|
| 632 | + 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
| 633 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 634 | + ], |
|
| 635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
| 636 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 637 | + ], |
|
| 638 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
| 639 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 640 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 641 | + ], |
|
| 642 | + 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
| 643 | + null, |
|
| 644 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 645 | + ], |
|
| 646 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
| 647 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 648 | + ], |
|
| 649 | + 'LEGACY_MODELS' => [ |
|
| 650 | + null, |
|
| 651 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 652 | + ], |
|
| 653 | + 'EE_Module_Request_Router' => [ |
|
| 654 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 655 | + ], |
|
| 656 | + 'EE_Registration_Processor' => [ |
|
| 657 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 658 | + ], |
|
| 659 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
| 660 | + null, |
|
| 661 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 662 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 663 | + ], |
|
| 664 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
| 665 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 666 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 667 | + ], |
|
| 668 | + 'EventEspresso\modules\ticket_selector\DisplayTicketSelector' => [ |
|
| 669 | + 'EventEspresso\core\domain\entities\users\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
| 670 | + ], |
|
| 671 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
| 672 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 673 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 674 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 675 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 676 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 677 | + ], |
|
| 678 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
| 679 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 680 | + ], |
|
| 681 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
| 682 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 683 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 684 | + ], |
|
| 685 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
| 686 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 687 | + ], |
|
| 688 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
| 689 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 690 | + ], |
|
| 691 | + 'EE_CPT_Strategy' => [ |
|
| 692 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 693 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 694 | + ], |
|
| 695 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
| 696 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 697 | + ], |
|
| 698 | + 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
| 699 | + null, |
|
| 700 | + null, |
|
| 701 | + null, |
|
| 702 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 703 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 704 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 705 | + ], |
|
| 706 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
| 707 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 708 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 709 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 710 | + ], |
|
| 711 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
| 712 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 713 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 714 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 715 | + ], |
|
| 716 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
| 717 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 718 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 719 | + ], |
|
| 720 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
| 721 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 722 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 723 | + ], |
|
| 724 | + 'EE_URL_Validation_Strategy' => [ |
|
| 725 | + null, |
|
| 726 | + null, |
|
| 727 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
| 728 | + ], |
|
| 729 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
| 730 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 731 | + ], |
|
| 732 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 733 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 734 | + ], |
|
| 735 | + 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
| 736 | + 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
| 737 | + 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
| 738 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
| 739 | + null, |
|
| 740 | + ], |
|
| 741 | + 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
| 742 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
| 743 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 744 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 745 | + 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
| 746 | + ], |
|
| 747 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
| 748 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
| 749 | + ], |
|
| 750 | + 'EventEspresso\core\services\routing\Router' => [ |
|
| 751 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 752 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 753 | + 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
| 754 | + ], |
|
| 755 | + 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
| 756 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 757 | + ], |
|
| 758 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
| 759 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 760 | + ], |
|
| 761 | + 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
| 762 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
| 763 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 764 | + ], |
|
| 765 | + 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
| 766 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 767 | + ], |
|
| 768 | + 'EventEspresso\core\services\addon\AddonManager' => [ |
|
| 769 | + 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
| 770 | + 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
| 771 | + 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
| 772 | + 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
| 773 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
| 774 | + ], |
|
| 775 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
| 776 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 777 | + ], |
|
| 778 | + 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
| 779 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 780 | + ], |
|
| 781 | + 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
| 782 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 783 | + ], |
|
| 784 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
| 785 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 786 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 787 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 788 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 789 | + ], |
|
| 790 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
| 791 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 792 | + ], |
|
| 793 | + 'EventEspresso\core\domain\entities\users\CurrentUser' => [ |
|
| 794 | + 'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache, |
|
| 795 | + ], |
|
| 796 | + 'EventEspresso\core\services\form\meta\InputTypes' => [ |
|
| 797 | + 'EventEspresso\core\services\form\meta\inputs\Block' => EE_Dependency_Map::load_from_cache, |
|
| 798 | + 'EventEspresso\core\services\form\meta\inputs\Button' => EE_Dependency_Map::load_from_cache, |
|
| 799 | + 'EventEspresso\core\services\form\meta\inputs\DateTime' => EE_Dependency_Map::load_from_cache, |
|
| 800 | + 'EventEspresso\core\services\form\meta\inputs\Input' => EE_Dependency_Map::load_from_cache, |
|
| 801 | + 'EventEspresso\core\services\form\meta\inputs\Number' => EE_Dependency_Map::load_from_cache, |
|
| 802 | + 'EventEspresso\core\services\form\meta\inputs\Phone' => EE_Dependency_Map::load_from_cache, |
|
| 803 | + 'EventEspresso\core\services\form\meta\inputs\Select' => EE_Dependency_Map::load_from_cache, |
|
| 804 | + 'EventEspresso\core\services\form\meta\inputs\Text' => EE_Dependency_Map::load_from_cache, |
|
| 805 | + ], |
|
| 806 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormDependencyHandler' => [ |
|
| 807 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 808 | + ], |
|
| 809 | + 'EventEspresso\core\domain\services\registration\form\v2\RegFormDependencyHandler' => [ |
|
| 810 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 811 | + ], |
|
| 812 | + 'EventEspresso\core\services\calculators\LineItemCalculator' => [ |
|
| 813 | + 'EventEspresso\core\services\helpers\DecimalValues' => EE_Dependency_Map::load_from_cache, |
|
| 814 | + ], |
|
| 815 | + 'EventEspresso\core\services\helpers\DecimalValues' => [ |
|
| 816 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 817 | + ], |
|
| 818 | + ]; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Registers how core classes are loaded. |
|
| 824 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 825 | + * 'EE_Request_Handler' => 'load_core' |
|
| 826 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 827 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 828 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 829 | + * 'Some_Class' => function () { |
|
| 830 | + * return new Some_Class(); |
|
| 831 | + * }, |
|
| 832 | + * This is required for instantiating dependencies |
|
| 833 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 834 | + * 'Required_Interface' => function () { |
|
| 835 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 836 | + * }, |
|
| 837 | + */ |
|
| 838 | + protected function _register_core_class_loaders() |
|
| 839 | + { |
|
| 840 | + $this->_class_loaders = [ |
|
| 841 | + // load_core |
|
| 842 | + 'EE_Dependency_Map' => function () { |
|
| 843 | + return $this; |
|
| 844 | + }, |
|
| 845 | + 'EE_Capabilities' => 'load_core', |
|
| 846 | + 'EE_Encryption' => 'load_core', |
|
| 847 | + 'EE_Front_Controller' => 'load_core', |
|
| 848 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 849 | + 'EE_Registry' => 'load_core', |
|
| 850 | + 'EE_Request' => function () { |
|
| 851 | + return $this->legacy_request; |
|
| 852 | + }, |
|
| 853 | + 'EventEspresso\core\services\request\Request' => function () { |
|
| 854 | + return $this->request; |
|
| 855 | + }, |
|
| 856 | + 'EventEspresso\core\services\request\Response' => function () { |
|
| 857 | + return $this->response; |
|
| 858 | + }, |
|
| 859 | + 'EE_Base' => 'load_core', |
|
| 860 | + 'EE_Request_Handler' => 'load_core', |
|
| 861 | + 'EE_Session' => 'load_core', |
|
| 862 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 863 | + 'EE_System' => 'load_core', |
|
| 864 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 865 | + 'EE_Register_CPTs' => 'load_core', |
|
| 866 | + 'EE_Admin' => 'load_core', |
|
| 867 | + 'EE_CPT_Strategy' => 'load_core', |
|
| 868 | + // load_class |
|
| 869 | + 'EE_Registration_Processor' => 'load_class', |
|
| 870 | + // load_lib |
|
| 871 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 872 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 873 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 874 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 875 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 876 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 877 | + 'EE_Message_Repository' => 'load_lib', |
|
| 878 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 879 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 880 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 881 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 882 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 883 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 884 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 885 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 886 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 887 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 888 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 889 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 890 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 891 | + 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
| 892 | + 'EE_DMS_Core_4_12_0' => 'load_dms', |
|
| 893 | + 'EE_Messages_Generator' => static function () { |
|
| 894 | + return EE_Registry::instance()->load_lib( |
|
| 895 | + 'Messages_Generator', |
|
| 896 | + [], |
|
| 897 | + false, |
|
| 898 | + false |
|
| 899 | + ); |
|
| 900 | + }, |
|
| 901 | + 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
| 902 | + return EE_Registry::instance()->load_lib( |
|
| 903 | + 'Messages_Template_Defaults', |
|
| 904 | + $arguments, |
|
| 905 | + false, |
|
| 906 | + false |
|
| 907 | + ); |
|
| 908 | + }, |
|
| 909 | + // load_helper |
|
| 910 | + 'EEH_Parse_Shortcodes' => static function () { |
|
| 911 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 912 | + return new EEH_Parse_Shortcodes(); |
|
| 913 | + } |
|
| 914 | + return null; |
|
| 915 | + }, |
|
| 916 | + 'EE_Template_Config' => static function () { |
|
| 917 | + return EE_Config::instance()->template_settings; |
|
| 918 | + }, |
|
| 919 | + 'EE_Currency_Config' => static function () { |
|
| 920 | + return EE_Config::instance()->currency; |
|
| 921 | + }, |
|
| 922 | + 'EE_Registration_Config' => static function () { |
|
| 923 | + return EE_Config::instance()->registration; |
|
| 924 | + }, |
|
| 925 | + 'EE_Core_Config' => static function () { |
|
| 926 | + return EE_Config::instance()->core; |
|
| 927 | + }, |
|
| 928 | + 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
| 929 | + return LoaderFactory::getLoader(); |
|
| 930 | + }, |
|
| 931 | + 'EE_Network_Config' => static function () { |
|
| 932 | + return EE_Network_Config::instance(); |
|
| 933 | + }, |
|
| 934 | + 'EE_Config' => static function () { |
|
| 935 | + return EE_Config::instance(); |
|
| 936 | + }, |
|
| 937 | + 'EventEspresso\core\domain\Domain' => static function () { |
|
| 938 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
| 939 | + }, |
|
| 940 | + 'EE_Admin_Config' => static function () { |
|
| 941 | + return EE_Config::instance()->admin; |
|
| 942 | + }, |
|
| 943 | + 'EE_Organization_Config' => static function () { |
|
| 944 | + return EE_Config::instance()->organization; |
|
| 945 | + }, |
|
| 946 | + 'EE_Network_Core_Config' => static function () { |
|
| 947 | + return EE_Network_Config::instance()->core; |
|
| 948 | + }, |
|
| 949 | + 'EE_Environment_Config' => static function () { |
|
| 950 | + return EE_Config::instance()->environment; |
|
| 951 | + }, |
|
| 952 | + 'EED_Core_Rest_Api' => static function () { |
|
| 953 | + return EED_Core_Rest_Api::instance(); |
|
| 954 | + }, |
|
| 955 | + 'WP_REST_Server' => static function () { |
|
| 956 | + return rest_get_server(); |
|
| 957 | + }, |
|
| 958 | + 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
| 959 | + return EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 960 | + }, |
|
| 961 | + ]; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * can be used for supplying alternate names for classes, |
|
| 967 | + * or for connecting interface names to instantiable classes |
|
| 968 | + * |
|
| 969 | + * @throws InvalidAliasException |
|
| 970 | + */ |
|
| 971 | + protected function _register_core_aliases() |
|
| 972 | + { |
|
| 973 | + $aliases = [ |
|
| 974 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 975 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 976 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 977 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 978 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 979 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 980 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 981 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 982 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 983 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 984 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 985 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 986 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 987 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 988 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 989 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 990 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 991 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 992 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 993 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 994 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 995 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 996 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 997 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 998 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 999 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 1000 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 1001 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 1002 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 1003 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 1004 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 1005 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 1006 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 1007 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 1008 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 1009 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 1010 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 1011 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 1012 | + 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
| 1013 | + ]; |
|
| 1014 | + foreach ($aliases as $alias => $fqn) { |
|
| 1015 | + if (is_array($fqn)) { |
|
| 1016 | + foreach ($fqn as $class => $for_class) { |
|
| 1017 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 1018 | + } |
|
| 1019 | + continue; |
|
| 1020 | + } |
|
| 1021 | + $this->class_cache->addAlias($fqn, $alias); |
|
| 1022 | + } |
|
| 1023 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1024 | + $this->class_cache->addAlias( |
|
| 1025 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 1026 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 1027 | + ); |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 1034 | + * request Primarily used by unit tests. |
|
| 1035 | + */ |
|
| 1036 | + public function reset() |
|
| 1037 | + { |
|
| 1038 | + $this->_register_core_class_loaders(); |
|
| 1039 | + $this->_register_core_dependencies(); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
| 1045 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 1046 | + * WHY? |
|
| 1047 | + * Because if a class is type hinting for a concretion, |
|
| 1048 | + * then why would we need to find another class to supply it? |
|
| 1049 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1050 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1051 | + * Don't go looking for some substitute. |
|
| 1052 | + * Whereas if a class is type hinting for an interface... |
|
| 1053 | + * then we need to find an actual class to use. |
|
| 1054 | + * So the interface IS the alias for some other FQN, |
|
| 1055 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1056 | + * represents some other class. |
|
| 1057 | + * |
|
| 1058 | + * @param string $fqn |
|
| 1059 | + * @param string $for_class |
|
| 1060 | + * @return bool |
|
| 1061 | + * @deprecated 4.9.62.p |
|
| 1062 | + */ |
|
| 1063 | + public function has_alias($fqn = '', $for_class = '') |
|
| 1064 | + { |
|
| 1065 | + return $this->isAlias($fqn, $for_class); |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1071 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1072 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1073 | + * for example: |
|
| 1074 | + * if the following two entries were added to the _aliases array: |
|
| 1075 | + * array( |
|
| 1076 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 1077 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1078 | + * ) |
|
| 1079 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1080 | + * to load an instance of 'some\namespace\classname' |
|
| 1081 | + * |
|
| 1082 | + * @param string $alias |
|
| 1083 | + * @param string $for_class |
|
| 1084 | + * @return string |
|
| 1085 | + * @deprecated 4.9.62.p |
|
| 1086 | + */ |
|
| 1087 | + public function get_alias($alias = '', $for_class = '') |
|
| 1088 | + { |
|
| 1089 | + return $this->getFqnForAlias($alias, $for_class); |
|
| 1090 | + } |
|
| 1091 | 1091 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface RegistrantFormInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return bool |
|
| 9 | - */ |
|
| 10 | - public function hasQuestions(): bool; |
|
| 7 | + /** |
|
| 8 | + * @return bool |
|
| 9 | + */ |
|
| 10 | + public function hasQuestions(): bool; |
|
| 11 | 11 | } |