@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Rules; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Rules\AbstractRule; |
| 6 | 6 | |
@@ -34,7 +34,7 @@ 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 | $args = func_get_args(); |
| 39 | 39 | $params = $args[2]; |
| 40 | 40 | $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()->notEmpty() ), |
|
| 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()->notEmpty()), |
|
| 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\Rules; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Rules\AbstractRule; |
| 6 | 6 | |
@@ -32,18 +32,18 @@ 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 | $args = func_get_args(); |
| 37 | 37 | $params = $args[2]; |
| 38 | 38 | $other_field = $params[0]; |
| 39 | 39 | |
| 40 | 40 | $v = $this->validator->create(); |
| 41 | 41 | |
| 42 | - if( $optional ) { |
|
| 42 | + if ($optional) { |
|
| 43 | 43 | return $v->optional( |
| 44 | - $v->create()->not( $v->create()->equals( $_POST[ $other_field ] )) ) |
|
| 45 | - ->validate( $input ); |
|
| 44 | + $v->create()->not($v->create()->equals($_POST[$other_field])) ) |
|
| 45 | + ->validate($input); |
|
| 46 | 46 | } |
| 47 | - return $v->not( $v->create()->equals( $_POST[ $other_field ] ))->validate( $input ); |
|
| 47 | + return $v->not($v->create()->equals($_POST[$other_field]))->validate($input); |
|
| 48 | 48 | } |
| 49 | 49 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Rules; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Rules\AbstractRule; |
| 6 | 6 | |
@@ -32,13 +32,13 @@ 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 | $args = func_get_args(); |
| 37 | 37 | $params = $args[2]; |
| 38 | 38 | |
| 39 | 39 | $v = $this->validator->create(); |
| 40 | - return ( $optional ) |
|
| 41 | - ? $v->optional( $v->create()->callback( $params[0] ) )->validate( $input ) |
|
| 42 | - : $v->callback( $params[0] )->validate( $input ); |
|
| 40 | + return ($optional) |
|
| 41 | + ? $v->optional($v->create()->callback($params[0]))->validate($input) |
|
| 42 | + : $v->callback($params[0])->validate($input); |
|
| 43 | 43 | } |
| 44 | 44 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Rules; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Rules\AbstractRule; |
| 6 | 6 | |
@@ -32,14 +32,14 @@ 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 | $args = func_get_args(); |
| 37 | - $params = isset( $args[2] ) ? $args[2]: false; |
|
| 38 | - $format = ( isset( $params[0] ) ) ? $params[0] : null; |
|
| 37 | + $params = isset($args[2]) ? $args[2] : false; |
|
| 38 | + $format = (isset($params[0])) ? $params[0] : null; |
|
| 39 | 39 | |
| 40 | 40 | $v = $this->validator->create(); |
| 41 | - return ( $optional ) |
|
| 42 | - ? $v->optional( $v->create()->date( $format ) )->validate( $input ) |
|
| 43 | - : $v->date( $format )->validate( $input ); |
|
| 41 | + return ($optional) |
|
| 42 | + ? $v->optional($v->create()->date($format))->validate($input) |
|
| 43 | + : $v->date($format)->validate($input); |
|
| 44 | 44 | } |
| 45 | 45 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @since 0.10.0 |
| 71 | 71 | * |
| 72 | - * @return WFV\FormComposite |
|
| 72 | + * @return FormComposite |
|
| 73 | 73 | */ |
| 74 | 74 | public function actualize() { |
| 75 | 75 | return $this->form; |
@@ -80,8 +80,7 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @since 0.10.0 |
| 82 | 82 | * |
| 83 | - * @param string $action |
|
| 84 | - * @return WFV\Artisan\FormArtisan |
|
| 83 | + * @return FormArtisan |
|
| 85 | 84 | */ |
| 86 | 85 | public function create() { |
| 87 | 86 | $this->form = new FormComposite( $this ); |
@@ -94,7 +93,7 @@ discard block |
||
| 94 | 93 | * |
| 95 | 94 | * @since 0.10.0 |
| 96 | 95 | * |
| 97 | - * @return WFV\Artisan\FormArtisan |
|
| 96 | + * @return FormArtisan |
|
| 98 | 97 | */ |
| 99 | 98 | public function errors() { |
| 100 | 99 | $this->collection['errors'] = new ErrorCollection( $this->labels() ); |
@@ -107,7 +106,7 @@ discard block |
||
| 107 | 106 | * |
| 108 | 107 | * @since 0.10.0 |
| 109 | 108 | * |
| 110 | - * @return WFV\Artisan\FormArtisan |
|
| 109 | + * @return FormArtisan |
|
| 111 | 110 | */ |
| 112 | 111 | public function input() { |
| 113 | 112 | $guard = new InspectionAgent( $this->action ); |
@@ -121,7 +120,7 @@ discard block |
||
| 121 | 120 | * |
| 122 | 121 | * @since 0.10.0 |
| 123 | 122 | * |
| 124 | - * @return WFV\Artisan\FormArtisan |
|
| 123 | + * @return FormArtisan |
|
| 125 | 124 | */ |
| 126 | 125 | public function rules() { |
| 127 | 126 | $this->collection['rules'] = new RuleCollection( $this->config ); |
@@ -7,7 +7,6 @@ |
||
| 7 | 7 | use WFV\Collection\ErrorCollection; |
| 8 | 8 | use WFV\Collection\InputCollection; |
| 9 | 9 | use WFV\Collection\RuleCollection; |
| 10 | - |
|
| 11 | 10 | use WFV\FormComposite; |
| 12 | 11 | |
| 13 | 12 | /** |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Artisan; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Agent\InspectionAgent; |
| 6 | 6 | use WFV\Contract\ArtisanInterface; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param array $config |
| 60 | 60 | * @param string $action |
| 61 | 61 | */ |
| 62 | - public function __construct( array $config, $action ) { |
|
| 62 | + public function __construct(array $config, $action) { |
|
| 63 | 63 | $this->config = $config; |
| 64 | 64 | $this->action = $action; |
| 65 | 65 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @return WFV\Artisan\FormArtisan |
| 85 | 85 | */ |
| 86 | 86 | public function create() { |
| 87 | - $this->form = new FormComposite( $this ); |
|
| 87 | + $this->form = new FormComposite($this); |
|
| 88 | 88 | return $this; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return WFV\Artisan\FormArtisan |
| 98 | 98 | */ |
| 99 | 99 | public function errors() { |
| 100 | - $this->collection['errors'] = new ErrorCollection( $this->labels() ); |
|
| 100 | + $this->collection['errors'] = new ErrorCollection($this->labels()); |
|
| 101 | 101 | return $this; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | * @return WFV\Artisan\FormArtisan |
| 111 | 111 | */ |
| 112 | 112 | public function input() { |
| 113 | - $guard = new InspectionAgent( $this->action ); |
|
| 114 | - $this->collection['input'] = new InputCollection( $guard ); |
|
| 113 | + $guard = new InspectionAgent($this->action); |
|
| 114 | + $this->collection['input'] = new InputCollection($guard); |
|
| 115 | 115 | return $this; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @return WFV\Artisan\FormArtisan |
| 125 | 125 | */ |
| 126 | 126 | public function rules() { |
| 127 | - $this->collection['rules'] = new RuleCollection( $this->config ); |
|
| 127 | + $this->collection['rules'] = new RuleCollection($this->config); |
|
| 128 | 128 | return $this; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @return array |
| 139 | 139 | */ |
| 140 | 140 | protected function labels() { |
| 141 | - return array_map( function( $item ) { |
|
| 141 | + return array_map(function($item) { |
|
| 142 | 142 | return $item['label']; |
| 143 | 143 | }, $this->config); |
| 144 | 144 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @since 0.10.0 |
| 38 | 38 | * |
| 39 | - * @param ArtisanInterface $builder |
|
| 39 | + * @param FormArtisan $builder |
|
| 40 | 40 | */ |
| 41 | 41 | public function __construct( FormArtisan $builder ) { |
| 42 | 42 | $this->alias = $builder->action; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @since 0.10.0 |
| 91 | 91 | * |
| 92 | - * @return WFV\Collection\InputCollection |
|
| 92 | + * @return Collection\InputCollection |
|
| 93 | 93 | */ |
| 94 | 94 | public function input() { |
| 95 | 95 | return $this->utilize('input'); |
@@ -153,6 +153,8 @@ discard block |
||
| 153 | 153 | * @param string $response |
| 154 | 154 | * @param string (optional) $field |
| 155 | 155 | * @param string (optional) $value |
| 156 | + * @param string $field |
|
| 157 | + * @param string $value |
|
| 156 | 158 | * @return string|null |
| 157 | 159 | */ |
| 158 | 160 | protected function string_or_null( $response, $field = null, $value = null ) { |
@@ -3,8 +3,6 @@ |
||
| 3 | 3 | defined( 'ABSPATH' ) || die(); |
| 4 | 4 | |
| 5 | 5 | use WFV\Artisan\FormArtisan; |
| 6 | -use WFV\Contract\ValidateInterface; |
|
| 7 | -use WFV\RuleFactory; |
|
| 8 | 6 | |
| 9 | 7 | /** |
| 10 | 8 | * Form Composition |
@@ -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\Artisan\FormArtisan; |
| 6 | 6 | use WFV\Contract\ValidateInterface; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param ArtisanInterface $builder |
| 40 | 40 | */ |
| 41 | - public function __construct( FormArtisan $builder ) { |
|
| 41 | + public function __construct(FormArtisan $builder) { |
|
| 42 | 42 | $this->alias = $builder->action; |
| 43 | 43 | $this->collection = $builder->collection; |
| 44 | 44 | } |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | * @param string $value Value to compare against. |
| 53 | 53 | * @return string|null |
| 54 | 54 | */ |
| 55 | - public function checked_if( $field = null, $value = null ) { |
|
| 56 | - return $this->string_or_null( 'checked', $field, $value ); |
|
| 55 | + public function checked_if($field = null, $value = null) { |
|
| 56 | + return $this->string_or_null('checked', $field, $value); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | * @param callable (optional) $callback |
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | - public function display( $field = null, callable $callback = null ) { |
|
| 71 | - echo $input = $this->utilize('input')->escape( $field ); |
|
| 70 | + public function display($field = null, callable $callback = null) { |
|
| 71 | + echo $input = $this->utilize('input')->escape($field); |
|
| 72 | 72 | return $input; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @return bool |
| 116 | 116 | */ |
| 117 | 117 | public function is_valid() { |
| 118 | - return ( $this->input()->is_populated() ) && |
|
| 118 | + return ($this->input()->is_populated()) && |
|
| 119 | 119 | !$this->has_errors(); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | * @param string $value Value to compare against. |
| 151 | 151 | * @return string|null |
| 152 | 152 | */ |
| 153 | - public function selected_if( $field = null, $value = null ) { |
|
| 154 | - return $this->string_or_null( 'selected', $field, $value ); |
|
| 153 | + public function selected_if($field = null, $value = null) { |
|
| 154 | + return $this->string_or_null('selected', $field, $value); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function token_fields() { |
| 165 | 165 | // TODO - Move markup into something - perhaps a renderable interface? |
| 166 | - $token_name = $this->alias . '_token'; |
|
| 167 | - echo $nonce_field = wp_nonce_field( $this->alias, $token_name, false, false ); |
|
| 168 | - echo $action_field = '<input type="hidden" name="action" value="'. $this->alias .'">'; |
|
| 166 | + $token_name = $this->alias.'_token'; |
|
| 167 | + echo $nonce_field = wp_nonce_field($this->alias, $token_name, false, false); |
|
| 168 | + echo $action_field = '<input type="hidden" name="action" value="'.$this->alias.'">'; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | * @param string (optional) $value |
| 180 | 180 | * @return string|null |
| 181 | 181 | */ |
| 182 | - protected function string_or_null( $response, $field = null, $value = null ) { |
|
| 182 | + protected function string_or_null($response, $field = null, $value = null) { |
|
| 183 | 183 | $input = $this->utilize('input'); |
| 184 | - return ( $input->contains( $field, $value ) ) ? $response : null; |
|
| 184 | + return ($input->contains($field, $value)) ? $response : null; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @param string $component Key indentifier. |
| 194 | 194 | */ |
| 195 | - protected function utilize( $component ) { |
|
| 196 | - return $this->collection[ $component ]; |
|
| 195 | + protected function utilize($component) { |
|
| 196 | + return $this->collection[$component]; |
|
| 197 | 197 | } |
| 198 | 198 | } |
@@ -17,7 +17,6 @@ |
||
| 17 | 17 | |
| 18 | 18 | require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php'; |
| 19 | 19 | |
| 20 | -use WFV\FormComposite; |
|
| 21 | 20 | use WFV\RuleFactory; |
| 22 | 21 | use WFV\Validator; |
| 23 | 22 | use WFV\Artisan\Director; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die(); |
|
| 2 | +defined('ABSPATH') || die(); |
|
| 3 | 3 | /* |
| 4 | 4 | Plugin Name: WFV - Form Validation |
| 5 | 5 | Plugin URI: https://macder.github.io/wfv/ |
@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | License URI: https://github.com/macder/wfv-validation/blob/master/LICENSE |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -define( 'WFV_VALIDATE_VERSION', '0.12.0' ); |
|
| 15 | -define( 'WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7' ); |
|
| 16 | -define( 'WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
|
| 14 | +define('WFV_VALIDATE_VERSION', '0.12.0'); |
|
| 15 | +define('WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7'); |
|
| 16 | +define('WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
| 17 | 17 | |
| 18 | -require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php'; |
|
| 18 | +require_once WFV_VALIDATE__PLUGIN_DIR.'/vendor/autoload.php'; |
|
| 19 | 19 | |
| 20 | 20 | use WFV\FormComposite; |
| 21 | 21 | use WFV\RuleFactory; |
@@ -33,17 +33,17 @@ discard block |
||
| 33 | 33 | * @param array $form Form arguments |
| 34 | 34 | * @param bool $trim Trim whitespace from beginning and end of string |
| 35 | 35 | */ |
| 36 | -function wfv_create( $action, array &$form, $trim = true ) { |
|
| 37 | - $messages = new MessageCollection( $form ); |
|
| 36 | +function wfv_create($action, array &$form, $trim = true) { |
|
| 37 | + $messages = new MessageCollection($form); |
|
| 38 | 38 | |
| 39 | - $builder = new FormArtisan( $form, $action ); |
|
| 40 | - $form = ( new Director() ) |
|
| 41 | - ->with( 'input' ) |
|
| 42 | - ->with( 'rules' ) |
|
| 43 | - ->with( 'errors' ) |
|
| 44 | - ->compose( $builder ); |
|
| 39 | + $builder = new FormArtisan($form, $action); |
|
| 40 | + $form = (new Director()) |
|
| 41 | + ->with('input') |
|
| 42 | + ->with('rules') |
|
| 43 | + ->with('errors') |
|
| 44 | + ->compose($builder); |
|
| 45 | 45 | |
| 46 | - if( $form->input()->is_populated() ) { |
|
| 47 | - ( new Validator( new RuleFactory(), $messages ) )->validate( $form ); |
|
| 46 | + if ($form->input()->is_populated()) { |
|
| 47 | + (new Validator(new RuleFactory(), $messages))->validate($form); |
|
| 48 | 48 | } |
| 49 | 49 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Contract; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * |
@@ -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\FormComposite; |
| 6 | 6 | use WFV\Collection\InputCollection; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @param RuleFactory $factory |
| 51 | 51 | */ |
| 52 | - public function __construct( RuleFactory $factory, MessageCollection $messages ) { |
|
| 52 | + public function __construct(RuleFactory $factory, MessageCollection $messages) { |
|
| 53 | 53 | $this->factory = $factory; |
| 54 | 54 | $this->messages = $messages; |
| 55 | 55 | } |
@@ -62,20 +62,20 @@ discard block |
||
| 62 | 62 | * @param FormComposite $form |
| 63 | 63 | * @return bool |
| 64 | 64 | */ |
| 65 | - public function validate( FormComposite $form ) { |
|
| 65 | + public function validate(FormComposite $form) { |
|
| 66 | 66 | $rule_collection = $form->rules(); |
| 67 | - $rules = $rule_collection->get_array( true ); |
|
| 67 | + $rules = $rule_collection->get_array(true); |
|
| 68 | 68 | |
| 69 | - foreach( $rules as $field => $ruleset ) { |
|
| 70 | - $input = $this->field_value( $form->input(), $field ); |
|
| 71 | - $optional = $rule_collection->is_optional( $field ); |
|
| 69 | + foreach ($rules as $field => $ruleset) { |
|
| 70 | + $input = $this->field_value($form->input(), $field); |
|
| 71 | + $optional = $rule_collection->is_optional($field); |
|
| 72 | 72 | |
| 73 | - foreach( $ruleset as $index => $rule ) { |
|
| 74 | - $params = $rule_collection->get_params( $field, $index ); |
|
| 75 | - $this->is_valid( $this->factory->get( $rule ), $field, $input, $optional, $params ); |
|
| 73 | + foreach ($ruleset as $index => $rule) { |
|
| 74 | + $params = $rule_collection->get_params($field, $index); |
|
| 75 | + $this->is_valid($this->factory->get($rule), $field, $input, $optional, $params); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | - return $this->result( $form ); |
|
| 78 | + return $this->result($form); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | * @param string $field |
| 88 | 88 | * @param array $template |
| 89 | 89 | */ |
| 90 | - protected function add_error( $field, array $template ) { |
|
| 91 | - $message = ( $this->messages->has( $field ) ) |
|
| 92 | - ? $this->messages->get_msg( $field, $template['name'] ) |
|
| 90 | + protected function add_error($field, array $template) { |
|
| 91 | + $message = ($this->messages->has($field)) |
|
| 92 | + ? $this->messages->get_msg($field, $template['name']) |
|
| 93 | 93 | : $template['message']; |
| 94 | - $this->errors[ $field ][ $template['name'] ] = $message; |
|
| 94 | + $this->errors[$field][$template['name']] = $message; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | * @param string $field |
| 119 | 119 | * @return string|array|null |
| 120 | 120 | */ |
| 121 | - protected function field_value( InputCollection $input, $field ) { |
|
| 122 | - if( $input->has( $field ) ) { |
|
| 121 | + protected function field_value(InputCollection $input, $field) { |
|
| 122 | + if ($input->has($field)) { |
|
| 123 | 123 | $input = $input->get_array(); |
| 124 | - return $input[ $field ]; |
|
| 124 | + return $input[$field]; |
|
| 125 | 125 | } |
| 126 | 126 | return null; |
| 127 | 127 | } |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | * @param bool $optional |
| 138 | 138 | * @param array (optional) $params |
| 139 | 139 | */ |
| 140 | - protected function is_valid( ValidateInterface $rule, $field, $value, $optional, $params = false ) { |
|
| 141 | - $params[] = ( $params ) ? $field : false; |
|
| 142 | - $valid = $rule->validate( $value, $optional, $params ); |
|
| 143 | - if( !$valid ){ |
|
| 144 | - $this->add_error( $field, $rule->template() ); |
|
| 140 | + protected function is_valid(ValidateInterface $rule, $field, $value, $optional, $params = false) { |
|
| 141 | + $params[] = ($params) ? $field : false; |
|
| 142 | + $valid = $rule->validate($value, $optional, $params); |
|
| 143 | + if (!$valid) { |
|
| 144 | + $this->add_error($field, $rule->template()); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | * @param FormComposite $form |
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | - protected function result( FormComposite $form ) { |
|
| 158 | - $valid = empty( $this->errors ); |
|
| 159 | - if( !$valid ) { |
|
| 160 | - $form->errors()->set_errors( $this->errors ); |
|
| 157 | + protected function result(FormComposite $form) { |
|
| 158 | + $valid = empty($this->errors); |
|
| 159 | + if (!$valid) { |
|
| 160 | + $form->errors()->set_errors($this->errors); |
|
| 161 | 161 | } |
| 162 | - $this->trigger_post_validate_action( $form, $valid ); |
|
| 162 | + $this->trigger_post_validate_action($form, $valid); |
|
| 163 | 163 | return $valid; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @param FormComposite $form |
| 174 | 174 | * @param bool $is_valid |
| 175 | 175 | */ |
| 176 | - protected function trigger_post_validate_action( FormComposite $form, $is_valid = false ) { |
|
| 177 | - $action = ( true === $is_valid ) ? $form->name() : $form->name() .'_fail'; |
|
| 178 | - do_action( $action, $form ); |
|
| 176 | + protected function trigger_post_validate_action(FormComposite $form, $is_valid = false) { |
|
| 177 | + $action = (true === $is_valid) ? $form->name() : $form->name().'_fail'; |
|
| 178 | + do_action($action, $form); |
|
| 179 | 179 | } |
| 180 | 180 | } |