Skip to content
Snippets Groups Projects
Commit ca1c9040 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

Merge branch 'feature/strong-typing-pp' into 'feature/strong-typing'

Feature/strong typing pp

See merge request !23
parents 679dcfd9 41941369
Branches
Tags
3 merge requests!28release: 3.0.0,!23Feature/strong typing pp,!19Add strong typing for 3.0 version
Pipeline #6505 passed
Showing
with 36 additions and 17 deletions
......@@ -20,7 +20,7 @@
"ext-curl": "*",
"ext-json": "*",
"wpdesk/wp-persistence": "^2.0|^3.0",
"wpdesk/wp-view": "^1.1"
"wpdesk/wp-view": "^2"
},
"require-dev": {
"phpunit/phpunit": "<7",
......
......@@ -11,6 +11,7 @@ use WPDesk\Persistence\PersistentContainer;
* @package WPDesk\Forms
*/
interface ContainerForm {
/**
* @param ContainerInterface $data
*
......
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms;
interface Escaper {
/** @param mixed $value */
public function escape( $value ): string;
}
......@@ -11,6 +11,7 @@ namespace WPDesk\Forms;
* @package WPDesk\Forms
*/
interface Field {
public function get_name(): string;
/** @return mixed */
......
......@@ -2,6 +2,7 @@
namespace WPDesk\Forms\Field;
use BadMethodCallException;
use WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\NoSanitize;
......@@ -17,6 +18,7 @@ use WPDesk\Forms\Validator\RequiredValidator;
* @package WPDesk\Forms
*/
abstract class BasicField implements Field {
use Field\Traits\HtmlAttributes;
const DEFAULT_PRIORITY = 10;
......@@ -57,7 +59,7 @@ abstract class BasicField implements Field {
}
public function get_serializer(): Serializer {
throw new \BadMethodCallException('You must define your serializer in a child class.');
throw new BadMethodCallException( 'You must define your serializer in a child class.' );
}
final public function get_name(): string {
......@@ -154,33 +156,32 @@ abstract class BasicField implements Field {
return $this->attributes['id'] ?? sanitize_title( $this->get_name() );
}
final public function is_multiple(): bool {
return $this->attributes['multiple'];
return isset( $this->attributes['multiple'] );
}
final public function set_disabled(): Field {
$this->attributes['disabled'] = true;
$this->attributes['disabled'] = 'disabled';
return $this;
}
final public function is_disabled(): bool {
return $this->attributes['disabled'];
return $this->attributes['disabled'] ?? false;
}
final public function set_readonly(): Field {
$this->attributes['readonly'] = true;
$this->attributes['readonly'] = 'readonly';
return $this;
}
final public function is_readonly(): bool {
return $this->attributes['readonly'];
return $this->attributes['readonly'] ?? false;
}
final public function set_required(): Field {
$this->attributes['required'] = true;
$this->attributes['required'] = 'required';
return $this;
}
......@@ -231,7 +232,7 @@ abstract class BasicField implements Field {
}
final public function is_required(): bool {
return $this->attributes['required'];
return isset( $this->attributes['required'] );
}
final public function get_priority(): int {
......
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field;
class ButtonField extends NoValueField {
public function get_template_name(): string {
return 'button';
}
......
......@@ -5,6 +5,7 @@ namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
class CheckboxField extends BasicField {
const VALUE_TRUE = 'yes';
const VALUE_FALSE = 'no';
......
......@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class DatePickerField extends BasicField {
public function __construct() {
$this->add_class( 'date-picker' );
$this->set_placeholder( 'YYYY-MM-DD' );
......
......@@ -5,7 +5,9 @@ namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
class Header extends NoValueField {
public function __construct() {
parent::__construct();
$this->meta['header_size'] = '';
}
......
......@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class HiddenField extends BasicField {
public function get_type(): string {
return 'hidden';
}
......
......@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\EmailSanitizer;
class InputEmailField extends BasicField {
public function get_type(): string {
return 'email';
}
......
......@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class InputNumberField extends BasicField {
public function get_type(): string {
return 'number';
}
......
......@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class InputTextField extends BasicField {
public function get_sanitizer(): Sanitizer {
return new TextFieldSanitizer();
}
......
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field;
class MultipleInputTextField extends InputTextField {
public function get_template_name(): string {
return 'input-text-multiple';
}
......
......@@ -8,6 +8,7 @@ namespace WPDesk\Forms\Field;
* @package WPDesk\Forms
*/
abstract class NoValueField extends BasicField {
public function __construct() {
$this->set_name( '' );
}
......
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field;
class Paragraph extends NoValueField {
public function get_template_name(): string {
return 'paragraph';
}
......
......@@ -6,6 +6,7 @@ use WPDesk\Forms\Serializer\ProductSelectSerializer;
use WPDesk\Forms\Serializer;
class ProductSelect extends SelectField {
public function __construct() {
$this->set_multiple();
}
......
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field;
class RadioField extends BasicField {
public function get_template_name(): string {
return 'input-radio';
}
......
......@@ -18,7 +18,7 @@ class SelectField extends BasicField {
}
public function set_multiple(): Field {
$this->attributes['multiple'] = true;
$this->attributes['multiple'] = 'multiple';
return $this;
}
......
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field;
class SubmitField extends NoValueField {
public function get_template_name(): string {
return 'input-submit';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment