@@ -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,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\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 | |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param string $value Value to compare against. |
| 127 | 127 | * @return string|null |
| 128 | 128 | */ |
| 129 | - public function selected_if( $field = null, $value = null ) { |
|
| 130 | - return $this->string_or_null( 'selected', $field, $value ); |
|
| 129 | + public function selected_if($field = null, $value = null) { |
|
| 130 | + return $this->string_or_null('selected', $field, $value); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function token_fields() { |
| 141 | 141 | // TODO - Move markup into something - perhaps a renderable interface? |
| 142 | - $token_name = $this->alias . '_token'; |
|
| 143 | - echo $nonce_field = wp_nonce_field( $this->alias, $token_name, false, false ); |
|
| 144 | - echo $action_field = '<input type="hidden" name="action" value="'. $this->alias .'">'; |
|
| 142 | + $token_name = $this->alias.'_token'; |
|
| 143 | + echo $nonce_field = wp_nonce_field($this->alias, $token_name, false, false); |
|
| 144 | + echo $action_field = '<input type="hidden" name="action" value="'.$this->alias.'">'; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | * @param string (optional) $value |
| 156 | 156 | * @return string|null |
| 157 | 157 | */ |
| 158 | - protected function string_or_null( $response, $field = null, $value = null ) { |
|
| 158 | + protected function string_or_null($response, $field = null, $value = null) { |
|
| 159 | 159 | $input = $this->utilize('input'); |
| 160 | - return ( $input->contains( $field, $value ) ) ? $response : null; |
|
| 160 | + return ($input->contains($field, $value)) ? $response : null; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @param string $component Key indentifier. |
| 170 | 170 | */ |
| 171 | - protected function utilize( $component ) { |
|
| 172 | - return $this->collection[ $component ]; |
|
| 171 | + protected function utilize($component) { |
|
| 172 | + return $this->collection[$component]; |
|
| 173 | 173 | } |
| 174 | 174 | } |
@@ -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.11.3' ); |
|
| 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.11.3'); |
|
| 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 | * |