@@ -4,7 +4,6 @@ |
||
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Composable; |
| 6 | 6 | use WFV\Artisan\FormArtisan; |
| 7 | -use WFV\Contract\ValidateInterface; |
|
| 8 | 7 | use WFV\Factory\ValidatorFactory; |
| 9 | 8 | |
| 10 | 9 | /** |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Composable; |
| 6 | 6 | use WFV\Artisan\FormArtisan; |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * @param ArtisanInterface $builder |
| 32 | 32 | * @param string $action |
| 33 | 33 | */ |
| 34 | - public function __construct( FormArtisan $builder, $action ) { |
|
| 34 | + public function __construct(FormArtisan $builder, $action) { |
|
| 35 | 35 | $this->alias = $action; |
| 36 | - $this->install( $builder->collection ); |
|
| 36 | + $this->install($builder->collection); |
|
| 37 | 37 | $this->validator = $builder->validator; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * @param string $value Value to compare against. |
| 47 | 47 | * @return string|null |
| 48 | 48 | */ |
| 49 | - public function checked_if( $field = null, $value = null ) { |
|
| 50 | - return $this->string_or_null( 'checked', $field, $value ); |
|
| 49 | + public function checked_if($field = null, $value = null) { |
|
| 50 | + return $this->string_or_null('checked', $field, $value); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @param callable (optional) $callback |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - public function display( $field = null, callable $callback = null ) { |
|
| 65 | - echo $input = $this->utilize('input')->escape( $field ); |
|
| 64 | + public function display($field = null, callable $callback = null) { |
|
| 65 | + echo $input = $this->utilize('input')->escape($field); |
|
| 66 | 66 | return $input; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function is_valid() { |
| 102 | 102 | $is_valid = $this->validator->is_valid(); |
| 103 | - if( false === $is_valid ) { |
|
| 104 | - $this->utilize('errors')->set_errors( $this->validator->errors() ); |
|
| 103 | + if (false === $is_valid) { |
|
| 104 | + $this->utilize('errors')->set_errors($this->validator->errors()); |
|
| 105 | 105 | } |
| 106 | - $this->trigger_post_validate_action( $is_valid ); |
|
| 106 | + $this->trigger_post_validate_action($is_valid); |
|
| 107 | 107 | return $is_valid; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | * @param string $value Value to compare against. |
| 139 | 139 | * @return string|null |
| 140 | 140 | */ |
| 141 | - public function selected_if( $field = null, $value = null ) { |
|
| 142 | - return $this->string_or_null( 'selected', $field, $value ); |
|
| 141 | + public function selected_if($field = null, $value = null) { |
|
| 142 | + return $this->string_or_null('selected', $field, $value); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function token_fields() { |
| 153 | 153 | // TODO - Move markup into something - perhaps a renderable interface? |
| 154 | - $token_name = $this->alias . '_token'; |
|
| 155 | - echo $nonce_field = wp_nonce_field( $this->alias, $token_name, false, false ); |
|
| 156 | - echo $action_field = '<input type="hidden" name="action" value="'. $this->alias .'">'; |
|
| 154 | + $token_name = $this->alias.'_token'; |
|
| 155 | + echo $nonce_field = wp_nonce_field($this->alias, $token_name, false, false); |
|
| 156 | + echo $action_field = '<input type="hidden" name="action" value="'.$this->alias.'">'; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -164,15 +164,15 @@ discard block |
||
| 164 | 164 | * @param ValidatorFactory $factory |
| 165 | 165 | * @return self |
| 166 | 166 | */ |
| 167 | - public function validate( ValidatorFactory $factory ) { |
|
| 167 | + public function validate(ValidatorFactory $factory) { |
|
| 168 | 168 | $rule_collection = $this->utilize('rules'); |
| 169 | - $rules = $rule_collection->get_array( true ); |
|
| 170 | - foreach( $rules as $field => $ruleset ) { |
|
| 171 | - $input = $this->field_value( $field ); |
|
| 172 | - $optional = $rule_collection->is_optional( $field ); |
|
| 173 | - foreach( $ruleset as $index => $rule ) { |
|
| 174 | - $params = $rule_collection->get_params( $field, $index ); |
|
| 175 | - $this->validator->validate( $factory->get( $rule ), $field, $input, $optional, $params ); |
|
| 169 | + $rules = $rule_collection->get_array(true); |
|
| 170 | + foreach ($rules as $field => $ruleset) { |
|
| 171 | + $input = $this->field_value($field); |
|
| 172 | + $optional = $rule_collection->is_optional($field); |
|
| 173 | + foreach ($ruleset as $index => $rule) { |
|
| 174 | + $params = $rule_collection->get_params($field, $index); |
|
| 175 | + $this->validator->validate($factory->get($rule), $field, $input, $optional, $params); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | return $this; |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @param string $field |
| 189 | 189 | */ |
| 190 | - protected function field_value( $field ) { |
|
| 190 | + protected function field_value($field) { |
|
| 191 | 191 | $input = $this->utilize('input'); |
| 192 | - if( $input->has( $field ) ) { |
|
| 193 | - $input = $input->get_array( false ); |
|
| 194 | - return $input[ $field ]; |
|
| 192 | + if ($input->has($field)) { |
|
| 193 | + $input = $input->get_array(false); |
|
| 194 | + return $input[$field]; |
|
| 195 | 195 | } |
| 196 | 196 | return null; |
| 197 | 197 | } |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | * @param string (optional) $value |
| 208 | 208 | * @return string|null |
| 209 | 209 | */ |
| 210 | - protected function string_or_null( $response, $field = null, $value = null ) { |
|
| 211 | - return ( $this->input( $field )->contains( $field, $value ) ) ? $response : null; |
|
| 210 | + protected function string_or_null($response, $field = null, $value = null) { |
|
| 211 | + return ($this->input($field)->contains($field, $value)) ? $response : null; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @param bool $is_valid |
| 221 | 221 | */ |
| 222 | - protected function trigger_post_validate_action( $is_valid = false ) { |
|
| 223 | - $action = ( true === $is_valid ) ? $this->alias : $this->alias .'_fail'; |
|
| 224 | - do_action( $action, $this ); |
|
| 222 | + protected function trigger_post_validate_action($is_valid = false) { |
|
| 223 | + $action = (true === $is_valid) ? $this->alias : $this->alias.'_fail'; |
|
| 224 | + do_action($action, $this); |
|
| 225 | 225 | } |
| 226 | 226 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Contract\ValidateInterface; |
| 6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @return bool |
| 41 | 41 | */ |
| 42 | 42 | public function is_valid() { |
| 43 | - return empty( $this->errors ); |
|
| 43 | + return empty($this->errors); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | * @param bool $optional |
| 55 | 55 | * @param array (optional) $params |
| 56 | 56 | */ |
| 57 | - public function validate( ValidateInterface $rule, $field, $value, $optional, $params = false ) { |
|
| 58 | - $params[] = ( $params ) ? $field : false; |
|
| 59 | - $valid = $rule->validate( $value, $optional, $params ); |
|
| 60 | - if( !$valid ){ |
|
| 61 | - $this->add_error( $field, $rule->template() ); |
|
| 57 | + public function validate(ValidateInterface $rule, $field, $value, $optional, $params = false) { |
|
| 58 | + $params[] = ($params) ? $field : false; |
|
| 59 | + $valid = $rule->validate($value, $optional, $params); |
|
| 60 | + if (!$valid) { |
|
| 61 | + $this->add_error($field, $rule->template()); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @param string $field |
| 72 | 72 | * @param array $template |
| 73 | 73 | */ |
| 74 | - protected function add_error( $field, array $template ) { |
|
| 75 | - $this->errors[ $field ][ $template['name'] ] = $template['message']; |
|
| 74 | + protected function add_error($field, array $template) { |
|
| 75 | + $this->errors[$field][$template['name']] = $template['message']; |
|
| 76 | 76 | } |
| 77 | 77 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Contract; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -14,5 +14,5 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * @return bool |
| 16 | 16 | */ |
| 17 | - public function validate( $input = null, $optional = false ); |
|
| 17 | + public function validate($input = null, $optional = false); |
|
| 18 | 18 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Validators; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Validators\AbstractValidator; |
| 6 | 6 | |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | * @param bool (optional) $optional |
| 35 | 35 | * @return bool |
| 36 | 36 | */ |
| 37 | - public function validate( $input = null, $optional = false ) { |
|
| 37 | + public function validate($input = null, $optional = false) { |
|
| 38 | 38 | $v = $this->validator->create(); |
| 39 | - return ( $optional ) |
|
| 40 | - ? $v->optional( $v->create()->email() )->validate( $input ) |
|
| 41 | - : $v->email()->validate( $input ); |
|
| 39 | + return ($optional) |
|
| 40 | + ? $v->optional($v->create()->email())->validate($input) |
|
| 41 | + : $v->email()->validate($input); |
|
| 42 | 42 | } |
| 43 | 43 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Validators; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Validators\AbstractValidator; |
| 6 | 6 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * @param bool (optional) $optional |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public function validate( $input = null, $optional = false ) { |
|
| 35 | + public function validate($input = null, $optional = false) { |
|
| 36 | 36 | $v = $this->validator->create(); |
| 37 | - return ( $optional ) |
|
| 38 | - ? $v->optional( $v->create()->intVal() )->validate( $input ) |
|
| 39 | - : $v->intVal()->validate( $input ); |
|
| 37 | + return ($optional) |
|
| 38 | + ? $v->optional($v->create()->intVal())->validate($input) |
|
| 39 | + : $v->intVal()->validate($input); |
|
| 40 | 40 | } |
| 41 | 41 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Validators; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Validators\AbstractValidator; |
| 6 | 6 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param bool (optional) $optional |
| 34 | 34 | * @return bool |
| 35 | 35 | */ |
| 36 | - public function validate( $input = null, $optional = false ){ |
|
| 36 | + public function validate($input = null, $optional = false) { |
|
| 37 | 37 | $args = func_get_args(); |
| 38 | 38 | $params = $args[2]; |
| 39 | 39 | $other_field = $params[0]; |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | $v = $this->validator->create(); |
| 44 | 44 | |
| 45 | 45 | return $v->when( |
| 46 | - $v->create()->key( $other_field, $v->create()->equals( $other_value ) ), |
|
| 47 | - $v->create()->key( $field, $v->create()->notEmpty() ), |
|
| 48 | - $v->create()->key( $field, $v->create()->alwaysValid() ) |
|
| 49 | - )->validate( $_POST ); |
|
| 46 | + $v->create()->key($other_field, $v->create()->equals($other_value)), |
|
| 47 | + $v->create()->key($field, $v->create()->notEmpty()), |
|
| 48 | + $v->create()->key($field, $v->create()->alwaysValid()) |
|
| 49 | + )->validate($_POST); |
|
| 50 | 50 | } |
| 51 | 51 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Validators; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Validators\AbstractValidator; |
| 6 | 6 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * @param bool (optional) $optional |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public function validate( $input = null, $optional = false ) { |
|
| 35 | + public function validate($input = null, $optional = false) { |
|
| 36 | 36 | $v = $this->validator->create(); |
| 37 | - return ( $optional ) |
|
| 38 | - ? $v->optional( $v->create()->digit()->length(1,1) )->validate( $input ) |
|
| 39 | - : $v->digit()->length(1,1)->validate( $input ); |
|
| 37 | + return ($optional) |
|
| 38 | + ? $v->optional($v->create()->digit()->length(1, 1))->validate($input) |
|
| 39 | + : $v->digit()->length(1, 1)->validate($input); |
|
| 40 | 40 | } |
| 41 | 41 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Validators; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Validators\AbstractValidator; |
| 6 | 6 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * @param bool (optional) $optional |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public function validate( $input = null, $optional = false ) { |
|
| 35 | + public function validate($input = null, $optional = false) { |
|
| 36 | 36 | $v = $this->validator->create(); |
| 37 | - return ( $optional ) |
|
| 38 | - ? $v->optional( $v->create()->alpha('-_') )->validate( $input ) |
|
| 39 | - : $v->alpha('-_')->validate( $input ); |
|
| 37 | + return ($optional) |
|
| 38 | + ? $v->optional($v->create()->alpha('-_'))->validate($input) |
|
| 39 | + : $v->alpha('-_')->validate($input); |
|
| 40 | 40 | } |
| 41 | 41 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Validators; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Validators\AbstractValidator; |
| 6 | 6 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * @param bool (optional) $optional |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public function validate( $input = null, $optional = false ) { |
|
| 35 | + public function validate($input = null, $optional = false) { |
|
| 36 | 36 | $v = $this->validator->create(); |
| 37 | - return ( $optional ) |
|
| 38 | - ? $v->optional( $v->create()->arrayType() )->validate( $input ) |
|
| 39 | - : $v->arrayType()->validate( $input ); |
|
| 37 | + return ($optional) |
|
| 38 | + ? $v->optional($v->create()->arrayType())->validate($input) |
|
| 39 | + : $v->arrayType()->validate($input); |
|
| 40 | 40 | } |
| 41 | 41 | } |