@@ -14,27 +14,27 @@ discard block |
||
14 | 14 | class EE_Invisible_Recaptcha_Display_Strategy extends EE_Display_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @return EE_Form_Input_Base|EE_Invisible_Recaptcha_Input |
|
19 | - */ |
|
20 | - public function input() |
|
21 | - { |
|
22 | - return $this->_input; |
|
23 | - } |
|
17 | + /** |
|
18 | + * @return EE_Form_Input_Base|EE_Invisible_Recaptcha_Input |
|
19 | + */ |
|
20 | + public function input() |
|
21 | + { |
|
22 | + return $this->_input; |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * returns HTML and javascript related to the displaying of this input |
|
28 | - * |
|
29 | - * @return string |
|
30 | - * @throws InvalidInterfaceException |
|
31 | - * @throws InvalidDataTypeException |
|
32 | - * @throws InvalidArgumentException |
|
33 | - */ |
|
34 | - public function display() |
|
35 | - { |
|
36 | - wp_enqueue_script(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA); |
|
37 | - return <<<EOD |
|
26 | + /** |
|
27 | + * returns HTML and javascript related to the displaying of this input |
|
28 | + * |
|
29 | + * @return string |
|
30 | + * @throws InvalidInterfaceException |
|
31 | + * @throws InvalidDataTypeException |
|
32 | + * @throws InvalidArgumentException |
|
33 | + */ |
|
34 | + public function display() |
|
35 | + { |
|
36 | + wp_enqueue_script(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA); |
|
37 | + return <<<EOD |
|
38 | 38 | <div id="g-recaptcha-{$this->input()->recaptchaId()}" |
39 | 39 | class="g-recaptcha" |
40 | 40 | data-sitekey="{$this->input()->siteKey()}" |
@@ -45,5 +45,5 @@ discard block |
||
45 | 45 | > |
46 | 46 | </div> |
47 | 47 | EOD; |
48 | - } |
|
48 | + } |
|
49 | 49 | } |
@@ -16,57 +16,57 @@ |
||
16 | 16 | abstract class EE_Compound_Input_Display_Strategy extends EE_Display_Strategy_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Gets the html ID for the sub-input for the specified option html value (not display text) |
|
21 | - * |
|
22 | - * @param string $option_value |
|
23 | - * @param bool $add_pound_sign |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function get_sub_input_id($option_value, $add_pound_sign = false) |
|
27 | - { |
|
28 | - return $this->_append_chars($this->_input->html_id($add_pound_sign), '-') . sanitize_key($option_value); |
|
29 | - } |
|
19 | + /** |
|
20 | + * Gets the html ID for the sub-input for the specified option html value (not display text) |
|
21 | + * |
|
22 | + * @param string $option_value |
|
23 | + * @param bool $add_pound_sign |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function get_sub_input_id($option_value, $add_pound_sign = false) |
|
27 | + { |
|
28 | + return $this->_append_chars($this->_input->html_id($add_pound_sign), '-') . sanitize_key($option_value); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * Gets the HTML IDs of all the inputs |
|
35 | - * |
|
36 | - * @param boolean $add_pound_sign |
|
37 | - * @return array |
|
38 | - * @throws \EE_Error |
|
39 | - */ |
|
40 | - public function get_html_input_ids($add_pound_sign = false) |
|
41 | - { |
|
42 | - $html_input_ids = array(); |
|
43 | - foreach ($this->get_input()->options() as $value => $display) { |
|
44 | - $html_input_ids[] = $this->get_sub_input_id($value, $add_pound_sign); |
|
45 | - } |
|
46 | - return $html_input_ids; |
|
47 | - } |
|
33 | + /** |
|
34 | + * Gets the HTML IDs of all the inputs |
|
35 | + * |
|
36 | + * @param boolean $add_pound_sign |
|
37 | + * @return array |
|
38 | + * @throws \EE_Error |
|
39 | + */ |
|
40 | + public function get_html_input_ids($add_pound_sign = false) |
|
41 | + { |
|
42 | + $html_input_ids = array(); |
|
43 | + foreach ($this->get_input()->options() as $value => $display) { |
|
44 | + $html_input_ids[] = $this->get_sub_input_id($value, $add_pound_sign); |
|
45 | + } |
|
46 | + return $html_input_ids; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * Overrides parent to make sure this display strategy is only used with the |
|
53 | - * appropriate input type |
|
54 | - * |
|
55 | - * @return \EE_Form_Input_With_Options_Base |
|
56 | - * @throws \EE_Error |
|
57 | - */ |
|
58 | - public function get_input() |
|
59 | - { |
|
60 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
61 | - throw new EE_Error( |
|
62 | - sprintf( |
|
63 | - __( |
|
64 | - 'Can not use a Compound Input Display Strategy (eg checkbox or radio) with an input that doesn\'t have options', |
|
65 | - 'event_espresso' |
|
66 | - ) |
|
67 | - ) |
|
68 | - ); |
|
69 | - } |
|
70 | - return parent::get_input(); |
|
71 | - } |
|
51 | + /** |
|
52 | + * Overrides parent to make sure this display strategy is only used with the |
|
53 | + * appropriate input type |
|
54 | + * |
|
55 | + * @return \EE_Form_Input_With_Options_Base |
|
56 | + * @throws \EE_Error |
|
57 | + */ |
|
58 | + public function get_input() |
|
59 | + { |
|
60 | + if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
61 | + throw new EE_Error( |
|
62 | + sprintf( |
|
63 | + __( |
|
64 | + 'Can not use a Compound Input Display Strategy (eg checkbox or radio) with an input that doesn\'t have options', |
|
65 | + 'event_espresso' |
|
66 | + ) |
|
67 | + ) |
|
68 | + ); |
|
69 | + } |
|
70 | + return parent::get_input(); |
|
71 | + } |
|
72 | 72 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function get_sub_input_id($option_value, $add_pound_sign = false) |
27 | 27 | { |
28 | - return $this->_append_chars($this->_input->html_id($add_pound_sign), '-') . sanitize_key($option_value); |
|
28 | + return $this->_append_chars($this->_input->html_id($add_pound_sign), '-').sanitize_key($option_value); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function get_input() |
59 | 59 | { |
60 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
60 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
61 | 61 | throw new EE_Error( |
62 | 62 | sprintf( |
63 | 63 | __( |
@@ -10,84 +10,84 @@ |
||
10 | 10 | class EE_Float_Normalization extends EE_Normalization_Strategy_Base |
11 | 11 | { |
12 | 12 | |
13 | - /* |
|
13 | + /* |
|
14 | 14 | * regex pattern that matches for the following: |
15 | 15 | * * optional negative sign |
16 | 16 | * * one or more digits or decimals |
17 | 17 | */ |
18 | - const REGEX = '/^(-?)([\d.]+)$/'; |
|
18 | + const REGEX = '/^(-?)([\d.]+)$/'; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $value_to_normalize |
|
24 | - * @return float |
|
25 | - * @throws \EE_Validation_Error |
|
26 | - */ |
|
27 | - public function normalize($value_to_normalize) |
|
28 | - { |
|
29 | - if ($value_to_normalize === null) { |
|
30 | - return null; |
|
31 | - } |
|
32 | - if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
33 | - return (float) $value_to_normalize; |
|
34 | - } |
|
35 | - if (! is_string($value_to_normalize)) { |
|
36 | - throw new EE_Validation_Error( |
|
37 | - sprintf( |
|
38 | - __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | - print_r($value_to_normalize, true), |
|
40 | - gettype($value_to_normalize) |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - $normalized_value = filter_var( |
|
45 | - $value_to_normalize, |
|
46 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | - FILTER_FLAG_ALLOW_FRACTION |
|
48 | - ); |
|
49 | - if ($normalized_value === '') { |
|
50 | - return null; |
|
51 | - } |
|
52 | - if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
53 | - if (count($matches) === 3) { |
|
54 | - // if first match is the negative sign, |
|
55 | - // then the number needs to be multiplied by -1 to remain negative |
|
56 | - return $matches[1] === '-' |
|
57 | - ? (float) $matches[2] * -1 |
|
58 | - : (float) $matches[2]; |
|
59 | - } |
|
60 | - } |
|
61 | - // find if this input has a float validation strategy |
|
62 | - // in which case, use its message |
|
63 | - $validation_error_message = null; |
|
64 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
65 | - if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
66 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
67 | - } |
|
68 | - } |
|
69 | - // this really shouldn't ever happen because fields with a float normalization strategy |
|
70 | - // should also have a float validation strategy, but in case it doesn't use the default |
|
71 | - if (! $validation_error_message) { |
|
72 | - $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
73 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
74 | - } |
|
75 | - throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
76 | - } |
|
22 | + /** |
|
23 | + * @param string $value_to_normalize |
|
24 | + * @return float |
|
25 | + * @throws \EE_Validation_Error |
|
26 | + */ |
|
27 | + public function normalize($value_to_normalize) |
|
28 | + { |
|
29 | + if ($value_to_normalize === null) { |
|
30 | + return null; |
|
31 | + } |
|
32 | + if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
33 | + return (float) $value_to_normalize; |
|
34 | + } |
|
35 | + if (! is_string($value_to_normalize)) { |
|
36 | + throw new EE_Validation_Error( |
|
37 | + sprintf( |
|
38 | + __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | + print_r($value_to_normalize, true), |
|
40 | + gettype($value_to_normalize) |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + $normalized_value = filter_var( |
|
45 | + $value_to_normalize, |
|
46 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | + FILTER_FLAG_ALLOW_FRACTION |
|
48 | + ); |
|
49 | + if ($normalized_value === '') { |
|
50 | + return null; |
|
51 | + } |
|
52 | + if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
53 | + if (count($matches) === 3) { |
|
54 | + // if first match is the negative sign, |
|
55 | + // then the number needs to be multiplied by -1 to remain negative |
|
56 | + return $matches[1] === '-' |
|
57 | + ? (float) $matches[2] * -1 |
|
58 | + : (float) $matches[2]; |
|
59 | + } |
|
60 | + } |
|
61 | + // find if this input has a float validation strategy |
|
62 | + // in which case, use its message |
|
63 | + $validation_error_message = null; |
|
64 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
65 | + if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
66 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
67 | + } |
|
68 | + } |
|
69 | + // this really shouldn't ever happen because fields with a float normalization strategy |
|
70 | + // should also have a float validation strategy, but in case it doesn't use the default |
|
71 | + if (! $validation_error_message) { |
|
72 | + $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
73 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
74 | + } |
|
75 | + throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * Converts a float into a string |
|
82 | - * |
|
83 | - * @param float $normalized_value |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function unnormalize($normalized_value) |
|
87 | - { |
|
88 | - if (empty($normalized_value)) { |
|
89 | - return '0.00'; |
|
90 | - } |
|
91 | - return "{$normalized_value}"; |
|
92 | - } |
|
80 | + /** |
|
81 | + * Converts a float into a string |
|
82 | + * |
|
83 | + * @param float $normalized_value |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function unnormalize($normalized_value) |
|
87 | + { |
|
88 | + if (empty($normalized_value)) { |
|
89 | + return '0.00'; |
|
90 | + } |
|
91 | + return "{$normalized_value}"; |
|
92 | + } |
|
93 | 93 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
33 | 33 | return (float) $value_to_normalize; |
34 | 34 | } |
35 | - if (! is_string($value_to_normalize)) { |
|
35 | + if ( ! is_string($value_to_normalize)) { |
|
36 | 36 | throw new EE_Validation_Error( |
37 | 37 | sprintf( |
38 | 38 | __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | // this really shouldn't ever happen because fields with a float normalization strategy |
70 | 70 | // should also have a float validation strategy, but in case it doesn't use the default |
71 | - if (! $validation_error_message) { |
|
71 | + if ( ! $validation_error_message) { |
|
72 | 72 | $default_validation_strategy = new EE_Float_Validation_Strategy(); |
73 | 73 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
74 | 74 | } |
@@ -10,88 +10,88 @@ |
||
10 | 10 | class EE_Int_Normalization extends EE_Normalization_Strategy_Base |
11 | 11 | { |
12 | 12 | |
13 | - /* |
|
13 | + /* |
|
14 | 14 | * regex pattern that matches for the following: |
15 | 15 | * * optional negative sign |
16 | 16 | * * one or more digits |
17 | 17 | */ |
18 | - const REGEX = '/^(-?)(\d+)(?:\.0+)?$/'; |
|
18 | + const REGEX = '/^(-?)(\d+)(?:\.0+)?$/'; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $value_to_normalize |
|
24 | - * @return int|mixed|string |
|
25 | - * @throws \EE_Validation_Error |
|
26 | - */ |
|
27 | - public function normalize($value_to_normalize) |
|
28 | - { |
|
29 | - if ($value_to_normalize === null) { |
|
30 | - return null; |
|
31 | - } |
|
32 | - if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
33 | - return (int) $value_to_normalize; |
|
34 | - } |
|
35 | - if (! is_string($value_to_normalize)) { |
|
36 | - throw new EE_Validation_Error( |
|
37 | - sprintf( |
|
38 | - __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | - print_r($value_to_normalize, true), |
|
40 | - gettype($value_to_normalize) |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - $value_to_normalize = filter_var( |
|
45 | - $value_to_normalize, |
|
46 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | - FILTER_FLAG_ALLOW_FRACTION |
|
48 | - ); |
|
49 | - if ($value_to_normalize === '') { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $matches = array(); |
|
53 | - if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) { |
|
54 | - if (count($matches) === 3) { |
|
55 | - // if first match is the negative sign, |
|
56 | - // then the number needs to be multiplied by -1 to remain negative |
|
57 | - return $matches[1] === '-' |
|
58 | - ? (int) $matches[2] * -1 |
|
59 | - : (int) $matches[2]; |
|
60 | - } |
|
61 | - } |
|
62 | - // find if this input has a int validation strategy |
|
63 | - // in which case, use its message |
|
64 | - $validation_error_message = null; |
|
65 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
66 | - if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
67 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
68 | - } |
|
69 | - } |
|
70 | - // this really shouldn't ever happen because fields with a int normalization strategy |
|
71 | - // should also have a int validation strategy, but in case it doesn't use the default |
|
72 | - if (! $validation_error_message) { |
|
73 | - $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
74 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
75 | - } |
|
76 | - throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
77 | - } |
|
22 | + /** |
|
23 | + * @param string $value_to_normalize |
|
24 | + * @return int|mixed|string |
|
25 | + * @throws \EE_Validation_Error |
|
26 | + */ |
|
27 | + public function normalize($value_to_normalize) |
|
28 | + { |
|
29 | + if ($value_to_normalize === null) { |
|
30 | + return null; |
|
31 | + } |
|
32 | + if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
33 | + return (int) $value_to_normalize; |
|
34 | + } |
|
35 | + if (! is_string($value_to_normalize)) { |
|
36 | + throw new EE_Validation_Error( |
|
37 | + sprintf( |
|
38 | + __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | + print_r($value_to_normalize, true), |
|
40 | + gettype($value_to_normalize) |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + $value_to_normalize = filter_var( |
|
45 | + $value_to_normalize, |
|
46 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | + FILTER_FLAG_ALLOW_FRACTION |
|
48 | + ); |
|
49 | + if ($value_to_normalize === '') { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $matches = array(); |
|
53 | + if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) { |
|
54 | + if (count($matches) === 3) { |
|
55 | + // if first match is the negative sign, |
|
56 | + // then the number needs to be multiplied by -1 to remain negative |
|
57 | + return $matches[1] === '-' |
|
58 | + ? (int) $matches[2] * -1 |
|
59 | + : (int) $matches[2]; |
|
60 | + } |
|
61 | + } |
|
62 | + // find if this input has a int validation strategy |
|
63 | + // in which case, use its message |
|
64 | + $validation_error_message = null; |
|
65 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
66 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
67 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
68 | + } |
|
69 | + } |
|
70 | + // this really shouldn't ever happen because fields with a int normalization strategy |
|
71 | + // should also have a int validation strategy, but in case it doesn't use the default |
|
72 | + if (! $validation_error_message) { |
|
73 | + $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
74 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
75 | + } |
|
76 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Converts the int into a string for use in teh html form |
|
83 | - * |
|
84 | - * @param int $normalized_value |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function unnormalize($normalized_value) |
|
88 | - { |
|
89 | - if ($normalized_value === null || $normalized_value === '') { |
|
90 | - return ''; |
|
91 | - } |
|
92 | - if (empty($normalized_value)) { |
|
93 | - return '0'; |
|
94 | - } |
|
95 | - return "$normalized_value"; |
|
96 | - } |
|
81 | + /** |
|
82 | + * Converts the int into a string for use in teh html form |
|
83 | + * |
|
84 | + * @param int $normalized_value |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function unnormalize($normalized_value) |
|
88 | + { |
|
89 | + if ($normalized_value === null || $normalized_value === '') { |
|
90 | + return ''; |
|
91 | + } |
|
92 | + if (empty($normalized_value)) { |
|
93 | + return '0'; |
|
94 | + } |
|
95 | + return "$normalized_value"; |
|
96 | + } |
|
97 | 97 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
33 | 33 | return (int) $value_to_normalize; |
34 | 34 | } |
35 | - if (! is_string($value_to_normalize)) { |
|
35 | + if ( ! is_string($value_to_normalize)) { |
|
36 | 36 | throw new EE_Validation_Error( |
37 | 37 | sprintf( |
38 | 38 | __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | // this really shouldn't ever happen because fields with a int normalization strategy |
71 | 71 | // should also have a int validation strategy, but in case it doesn't use the default |
72 | - if (! $validation_error_message) { |
|
72 | + if ( ! $validation_error_message) { |
|
73 | 73 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
74 | 74 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
75 | 75 | } |
@@ -10,25 +10,25 @@ |
||
10 | 10 | class EE_Null_Normalization extends EE_Normalization_Strategy_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param string $value_to_normalize |
|
15 | - * @return null |
|
16 | - */ |
|
17 | - public function normalize($value_to_normalize) |
|
18 | - { |
|
19 | - return null; |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param string $value_to_normalize |
|
15 | + * @return null |
|
16 | + */ |
|
17 | + public function normalize($value_to_normalize) |
|
18 | + { |
|
19 | + return null; |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * In the form input we need some string, so use a blank one. |
|
26 | - * |
|
27 | - * @param string $normalized_value |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function unnormalize($normalized_value) |
|
31 | - { |
|
32 | - return ''; |
|
33 | - } |
|
24 | + /** |
|
25 | + * In the form input we need some string, so use a blank one. |
|
26 | + * |
|
27 | + * @param string $normalized_value |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function unnormalize($normalized_value) |
|
31 | + { |
|
32 | + return ''; |
|
33 | + } |
|
34 | 34 | } |
@@ -11,26 +11,26 @@ |
||
11 | 11 | class EE_All_Caps_Normalization extends EE_Normalization_Strategy_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param string $value_to_normalize |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function normalize($value_to_normalize) |
|
19 | - { |
|
20 | - return strtoupper($value_to_normalize); |
|
21 | - } |
|
14 | + /** |
|
15 | + * @param string $value_to_normalize |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function normalize($value_to_normalize) |
|
19 | + { |
|
20 | + return strtoupper($value_to_normalize); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * It's kinda hard to unnormalize this- we can't determine which parts used to be lowercase |
|
27 | - * so just return it as-is. |
|
28 | - * |
|
29 | - * @param string $normalized_value |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function unnormalize($normalized_value) |
|
33 | - { |
|
34 | - return $normalized_value; |
|
35 | - } |
|
25 | + /** |
|
26 | + * It's kinda hard to unnormalize this- we can't determine which parts used to be lowercase |
|
27 | + * so just return it as-is. |
|
28 | + * |
|
29 | + * @param string $normalized_value |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function unnormalize($normalized_value) |
|
33 | + { |
|
34 | + return $normalized_value; |
|
35 | + } |
|
36 | 36 | } |
@@ -9,59 +9,59 @@ |
||
9 | 9 | abstract class EE_Normalization_Strategy_Base extends EE_Form_Input_Strategy_Base |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * Takes the sanitized value for the input and casts it into the correct PHP type. |
|
14 | - * Eg, turns it into an int, float, string, boolean, datetime, etc. The validation |
|
15 | - * strategy should be able to depend on the normalized value being of the correct type. |
|
16 | - * If the normalized value passes validation, the normalized value is what other code |
|
17 | - * will operate on. If the sanitized value cannot be normalized, this method should either |
|
18 | - * add a validation error onto the input, or wrangle the input into a format that can be normalized |
|
19 | - * (eg, for a date input, if the user enters "2014/100/100", you can either add an error stating |
|
20 | - * "hey! 2014/100/100 is not a valid date!", or simply convert it into a valid date like "2014/12/31". |
|
21 | - * For this case, I'd prefer the former. But there may be cases where you'd just rather correct it for them) |
|
22 | - * |
|
23 | - * @param string $value_to_normalize it should always be a string. If the input receives an array, then the |
|
24 | - * validation strategy should be called on array elements, not on the entire array |
|
25 | - * @return mixed the normalized value |
|
26 | - */ |
|
27 | - abstract public function normalize($value_to_normalize); |
|
12 | + /** |
|
13 | + * Takes the sanitized value for the input and casts it into the correct PHP type. |
|
14 | + * Eg, turns it into an int, float, string, boolean, datetime, etc. The validation |
|
15 | + * strategy should be able to depend on the normalized value being of the correct type. |
|
16 | + * If the normalized value passes validation, the normalized value is what other code |
|
17 | + * will operate on. If the sanitized value cannot be normalized, this method should either |
|
18 | + * add a validation error onto the input, or wrangle the input into a format that can be normalized |
|
19 | + * (eg, for a date input, if the user enters "2014/100/100", you can either add an error stating |
|
20 | + * "hey! 2014/100/100 is not a valid date!", or simply convert it into a valid date like "2014/12/31". |
|
21 | + * For this case, I'd prefer the former. But there may be cases where you'd just rather correct it for them) |
|
22 | + * |
|
23 | + * @param string $value_to_normalize it should always be a string. If the input receives an array, then the |
|
24 | + * validation strategy should be called on array elements, not on the entire array |
|
25 | + * @return mixed the normalized value |
|
26 | + */ |
|
27 | + abstract public function normalize($value_to_normalize); |
|
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * Identical to normalize, except normalize_one() CANNOT be passed an array and |
|
33 | - * never returns an array. Useful if the normalization strategy converts between arrays |
|
34 | - * |
|
35 | - * @param string $individual_item_to_normalize |
|
36 | - * @return mixed |
|
37 | - */ |
|
38 | - public function normalize_one($individual_item_to_normalize) |
|
39 | - { |
|
40 | - return $this->normalize($individual_item_to_normalize); |
|
41 | - } |
|
31 | + /** |
|
32 | + * Identical to normalize, except normalize_one() CANNOT be passed an array and |
|
33 | + * never returns an array. Useful if the normalization strategy converts between arrays |
|
34 | + * |
|
35 | + * @param string $individual_item_to_normalize |
|
36 | + * @return mixed |
|
37 | + */ |
|
38 | + public function normalize_one($individual_item_to_normalize) |
|
39 | + { |
|
40 | + return $this->normalize($individual_item_to_normalize); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Takes the normalized value (for an Yes_No_Input this could be TRUE or FALSE), and converts it into |
|
47 | - * the value you would use in the html form (for a Yes_No_Input this could be '1' or '0'). |
|
48 | - * |
|
49 | - * @param $normalized_value |
|
50 | - * @return array|string the 'raw' value as used in the form, usually a string or array of strings. |
|
51 | - */ |
|
52 | - abstract public function unnormalize($normalized_value); |
|
45 | + /** |
|
46 | + * Takes the normalized value (for an Yes_No_Input this could be TRUE or FALSE), and converts it into |
|
47 | + * the value you would use in the html form (for a Yes_No_Input this could be '1' or '0'). |
|
48 | + * |
|
49 | + * @param $normalized_value |
|
50 | + * @return array|string the 'raw' value as used in the form, usually a string or array of strings. |
|
51 | + */ |
|
52 | + abstract public function unnormalize($normalized_value); |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Normally the same as unnormalize, except it CANNOT be passed an array and |
|
58 | - * ALWAYS returns a string |
|
59 | - * |
|
60 | - * @param mixed $individual_item_to_unnormalize NOT an array |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function unnormalize_one($individual_item_to_unnormalize) |
|
64 | - { |
|
65 | - return $this->unnormalize($individual_item_to_unnormalize); |
|
66 | - } |
|
56 | + /** |
|
57 | + * Normally the same as unnormalize, except it CANNOT be passed an array and |
|
58 | + * ALWAYS returns a string |
|
59 | + * |
|
60 | + * @param mixed $individual_item_to_unnormalize NOT an array |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function unnormalize_one($individual_item_to_unnormalize) |
|
64 | + { |
|
65 | + return $this->unnormalize($individual_item_to_unnormalize); |
|
66 | + } |
|
67 | 67 | } |
@@ -13,27 +13,27 @@ |
||
13 | 13 | class EE_Boolean_Normalization extends EE_Normalization_Strategy_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param string | int | bool $value_to_normalize |
|
18 | - * @return boolean |
|
19 | - */ |
|
20 | - public function normalize($value_to_normalize) |
|
21 | - { |
|
22 | - return filter_var($value_to_normalize, FILTER_VALIDATE_BOOLEAN); |
|
23 | - } |
|
16 | + /** |
|
17 | + * @param string | int | bool $value_to_normalize |
|
18 | + * @return boolean |
|
19 | + */ |
|
20 | + public function normalize($value_to_normalize) |
|
21 | + { |
|
22 | + return filter_var($value_to_normalize, FILTER_VALIDATE_BOOLEAN); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param boolean $normalized_value |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function unnormalize($normalized_value) |
|
32 | - { |
|
33 | - if ($normalized_value) { |
|
34 | - return '1'; |
|
35 | - } else { |
|
36 | - return '0'; |
|
37 | - } |
|
38 | - } |
|
27 | + /** |
|
28 | + * @param boolean $normalized_value |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function unnormalize($normalized_value) |
|
32 | + { |
|
33 | + if ($normalized_value) { |
|
34 | + return '1'; |
|
35 | + } else { |
|
36 | + return '0'; |
|
37 | + } |
|
38 | + } |
|
39 | 39 | } |
@@ -10,90 +10,90 @@ |
||
10 | 10 | class EE_Many_Valued_Normalization extends EE_Normalization_Strategy_Base |
11 | 11 | { |
12 | 12 | |
13 | - protected $_individual_item_normalization_strategy = array(); |
|
14 | - |
|
15 | - |
|
16 | - |
|
17 | - /** |
|
18 | - * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
19 | - */ |
|
20 | - public function __construct($individual_item_normalization_strategy) |
|
21 | - { |
|
22 | - $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
23 | - parent::__construct(); |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Normalizes the input into an array, and normalizes each item according to its |
|
30 | - * individual item normalization strategy |
|
31 | - * |
|
32 | - * @param array | string $value_to_normalize |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - public function normalize($value_to_normalize) |
|
36 | - { |
|
37 | - if (is_array($value_to_normalize)) { |
|
38 | - $items_to_normalize = $value_to_normalize; |
|
39 | - } elseif ($value_to_normalize !== null) { |
|
40 | - $items_to_normalize = array($value_to_normalize); |
|
41 | - } else { |
|
42 | - $items_to_normalize = array(); |
|
43 | - } |
|
44 | - $normalized_array_value = array(); |
|
45 | - foreach ($items_to_normalize as $key => $individual_item) { |
|
46 | - $normalized_array_value[ $key ] = $this->normalize_one($individual_item); |
|
47 | - } |
|
48 | - return $normalized_array_value; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
55 | - * |
|
56 | - * @param string $individual_value_to_normalize but definitely NOT an array |
|
57 | - * @return mixed |
|
58 | - */ |
|
59 | - public function normalize_one($individual_value_to_normalize) |
|
60 | - { |
|
61 | - return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Converts the array of normalized things to an array of raw html values. |
|
68 | - * |
|
69 | - * @param array $normalized_values |
|
70 | - * @return string[] |
|
71 | - */ |
|
72 | - public function unnormalize($normalized_values) |
|
73 | - { |
|
74 | - if ($normalized_values === null) { |
|
75 | - $normalized_values = array(); |
|
76 | - } |
|
77 | - if (! is_array($normalized_values)) { |
|
78 | - $normalized_values = array($normalized_values); |
|
79 | - } |
|
80 | - $non_normal_values = array(); |
|
81 | - foreach ($normalized_values as $key => $value) { |
|
82 | - $non_normal_values[ $key ] = $this->unnormalize_one($value); |
|
83 | - } |
|
84 | - return $non_normal_values; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Unnormalizes an individual item in the array of values |
|
91 | - * |
|
92 | - * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function unnormalize_one($individual_value_to_unnormalize) |
|
96 | - { |
|
97 | - return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
98 | - } |
|
13 | + protected $_individual_item_normalization_strategy = array(); |
|
14 | + |
|
15 | + |
|
16 | + |
|
17 | + /** |
|
18 | + * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
19 | + */ |
|
20 | + public function __construct($individual_item_normalization_strategy) |
|
21 | + { |
|
22 | + $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
23 | + parent::__construct(); |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Normalizes the input into an array, and normalizes each item according to its |
|
30 | + * individual item normalization strategy |
|
31 | + * |
|
32 | + * @param array | string $value_to_normalize |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + public function normalize($value_to_normalize) |
|
36 | + { |
|
37 | + if (is_array($value_to_normalize)) { |
|
38 | + $items_to_normalize = $value_to_normalize; |
|
39 | + } elseif ($value_to_normalize !== null) { |
|
40 | + $items_to_normalize = array($value_to_normalize); |
|
41 | + } else { |
|
42 | + $items_to_normalize = array(); |
|
43 | + } |
|
44 | + $normalized_array_value = array(); |
|
45 | + foreach ($items_to_normalize as $key => $individual_item) { |
|
46 | + $normalized_array_value[ $key ] = $this->normalize_one($individual_item); |
|
47 | + } |
|
48 | + return $normalized_array_value; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
55 | + * |
|
56 | + * @param string $individual_value_to_normalize but definitely NOT an array |
|
57 | + * @return mixed |
|
58 | + */ |
|
59 | + public function normalize_one($individual_value_to_normalize) |
|
60 | + { |
|
61 | + return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Converts the array of normalized things to an array of raw html values. |
|
68 | + * |
|
69 | + * @param array $normalized_values |
|
70 | + * @return string[] |
|
71 | + */ |
|
72 | + public function unnormalize($normalized_values) |
|
73 | + { |
|
74 | + if ($normalized_values === null) { |
|
75 | + $normalized_values = array(); |
|
76 | + } |
|
77 | + if (! is_array($normalized_values)) { |
|
78 | + $normalized_values = array($normalized_values); |
|
79 | + } |
|
80 | + $non_normal_values = array(); |
|
81 | + foreach ($normalized_values as $key => $value) { |
|
82 | + $non_normal_values[ $key ] = $this->unnormalize_one($value); |
|
83 | + } |
|
84 | + return $non_normal_values; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Unnormalizes an individual item in the array of values |
|
91 | + * |
|
92 | + * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function unnormalize_one($individual_value_to_unnormalize) |
|
96 | + { |
|
97 | + return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
98 | + } |
|
99 | 99 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | } |
44 | 44 | $normalized_array_value = array(); |
45 | 45 | foreach ($items_to_normalize as $key => $individual_item) { |
46 | - $normalized_array_value[ $key ] = $this->normalize_one($individual_item); |
|
46 | + $normalized_array_value[$key] = $this->normalize_one($individual_item); |
|
47 | 47 | } |
48 | 48 | return $normalized_array_value; |
49 | 49 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | if ($normalized_values === null) { |
75 | 75 | $normalized_values = array(); |
76 | 76 | } |
77 | - if (! is_array($normalized_values)) { |
|
77 | + if ( ! is_array($normalized_values)) { |
|
78 | 78 | $normalized_values = array($normalized_values); |
79 | 79 | } |
80 | 80 | $non_normal_values = array(); |
81 | 81 | foreach ($normalized_values as $key => $value) { |
82 | - $non_normal_values[ $key ] = $this->unnormalize_one($value); |
|
82 | + $non_normal_values[$key] = $this->unnormalize_one($value); |
|
83 | 83 | } |
84 | 84 | return $non_normal_values; |
85 | 85 | } |