@@ -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 @@ 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 | } |