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
No related branches found
No related tags found
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 @@ ...@@ -20,7 +20,7 @@
"ext-curl": "*", "ext-curl": "*",
"ext-json": "*", "ext-json": "*",
"wpdesk/wp-persistence": "^2.0|^3.0", "wpdesk/wp-persistence": "^2.0|^3.0",
"wpdesk/wp-view": "^1.1" "wpdesk/wp-view": "^2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "<7", "phpunit/phpunit": "<7",
......
...@@ -11,6 +11,7 @@ use WPDesk\Persistence\PersistentContainer; ...@@ -11,6 +11,7 @@ use WPDesk\Persistence\PersistentContainer;
* @package WPDesk\Forms * @package WPDesk\Forms
*/ */
interface ContainerForm { interface ContainerForm {
/** /**
* @param ContainerInterface $data * @param ContainerInterface $data
* *
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace WPDesk\Forms; namespace WPDesk\Forms;
interface Escaper { interface Escaper {
/** @param mixed $value */ /** @param mixed $value */
public function escape( $value ): string; public function escape( $value ): string;
} }
...@@ -11,6 +11,7 @@ namespace WPDesk\Forms; ...@@ -11,6 +11,7 @@ namespace WPDesk\Forms;
* @package WPDesk\Forms * @package WPDesk\Forms
*/ */
interface Field { interface Field {
public function get_name(): string; public function get_name(): string;
/** @return mixed */ /** @return mixed */
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
use BadMethodCallException;
use WPDesk\Forms\Field; use WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer; use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\NoSanitize; use WPDesk\Forms\Sanitizer\NoSanitize;
...@@ -17,6 +18,7 @@ use WPDesk\Forms\Validator\RequiredValidator; ...@@ -17,6 +18,7 @@ use WPDesk\Forms\Validator\RequiredValidator;
* @package WPDesk\Forms * @package WPDesk\Forms
*/ */
abstract class BasicField implements Field { abstract class BasicField implements Field {
use Field\Traits\HtmlAttributes; use Field\Traits\HtmlAttributes;
const DEFAULT_PRIORITY = 10; const DEFAULT_PRIORITY = 10;
...@@ -57,7 +59,7 @@ abstract class BasicField implements Field { ...@@ -57,7 +59,7 @@ abstract class BasicField implements Field {
} }
public function get_serializer(): Serializer { 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 { final public function get_name(): string {
...@@ -154,33 +156,32 @@ abstract class BasicField implements Field { ...@@ -154,33 +156,32 @@ abstract class BasicField implements Field {
return $this->attributes['id'] ?? sanitize_title( $this->get_name() ); return $this->attributes['id'] ?? sanitize_title( $this->get_name() );
} }
final public function is_multiple(): bool { final public function is_multiple(): bool {
return $this->attributes['multiple']; return isset( $this->attributes['multiple'] );
} }
final public function set_disabled(): Field { final public function set_disabled(): Field {
$this->attributes['disabled'] = true; $this->attributes['disabled'] = 'disabled';
return $this; return $this;
} }
final public function is_disabled(): bool { final public function is_disabled(): bool {
return $this->attributes['disabled']; return $this->attributes['disabled'] ?? false;
} }
final public function set_readonly(): Field { final public function set_readonly(): Field {
$this->attributes['readonly'] = true; $this->attributes['readonly'] = 'readonly';
return $this; return $this;
} }
final public function is_readonly(): bool { final public function is_readonly(): bool {
return $this->attributes['readonly']; return $this->attributes['readonly'] ?? false;
} }
final public function set_required(): Field { final public function set_required(): Field {
$this->attributes['required'] = true; $this->attributes['required'] = 'required';
return $this; return $this;
} }
...@@ -231,7 +232,7 @@ abstract class BasicField implements Field { ...@@ -231,7 +232,7 @@ abstract class BasicField implements Field {
} }
final public function is_required(): bool { final public function is_required(): bool {
return $this->attributes['required']; return isset( $this->attributes['required'] );
} }
final public function get_priority(): int { final public function get_priority(): int {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
class ButtonField extends NoValueField { class ButtonField extends NoValueField {
public function get_template_name(): string { public function get_template_name(): string {
return 'button'; return 'button';
} }
......
...@@ -5,6 +5,7 @@ namespace WPDesk\Forms\Field; ...@@ -5,6 +5,7 @@ namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field; use WPDesk\Forms\Field;
class CheckboxField extends BasicField { class CheckboxField extends BasicField {
const VALUE_TRUE = 'yes'; const VALUE_TRUE = 'yes';
const VALUE_FALSE = 'no'; const VALUE_FALSE = 'no';
......
...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer; ...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class DatePickerField extends BasicField { class DatePickerField extends BasicField {
public function __construct() { public function __construct() {
$this->add_class( 'date-picker' ); $this->add_class( 'date-picker' );
$this->set_placeholder( 'YYYY-MM-DD' ); $this->set_placeholder( 'YYYY-MM-DD' );
......
...@@ -5,7 +5,9 @@ namespace WPDesk\Forms\Field; ...@@ -5,7 +5,9 @@ namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field; use WPDesk\Forms\Field;
class Header extends NoValueField { class Header extends NoValueField {
public function __construct() { public function __construct() {
parent::__construct();
$this->meta['header_size'] = ''; $this->meta['header_size'] = '';
} }
......
...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer; ...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class HiddenField extends BasicField { class HiddenField extends BasicField {
public function get_type(): string { public function get_type(): string {
return 'hidden'; return 'hidden';
} }
......
...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer; ...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\EmailSanitizer; use WPDesk\Forms\Sanitizer\EmailSanitizer;
class InputEmailField extends BasicField { class InputEmailField extends BasicField {
public function get_type(): string { public function get_type(): string {
return 'email'; return 'email';
} }
......
...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer; ...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class InputNumberField extends BasicField { class InputNumberField extends BasicField {
public function get_type(): string { public function get_type(): string {
return 'number'; return 'number';
} }
......
...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer; ...@@ -6,6 +6,7 @@ use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer; use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class InputTextField extends BasicField { class InputTextField extends BasicField {
public function get_sanitizer(): Sanitizer { public function get_sanitizer(): Sanitizer {
return new TextFieldSanitizer(); return new TextFieldSanitizer();
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
class MultipleInputTextField extends InputTextField { class MultipleInputTextField extends InputTextField {
public function get_template_name(): string { public function get_template_name(): string {
return 'input-text-multiple'; return 'input-text-multiple';
} }
......
...@@ -8,6 +8,7 @@ namespace WPDesk\Forms\Field; ...@@ -8,6 +8,7 @@ namespace WPDesk\Forms\Field;
* @package WPDesk\Forms * @package WPDesk\Forms
*/ */
abstract class NoValueField extends BasicField { abstract class NoValueField extends BasicField {
public function __construct() { public function __construct() {
$this->set_name( '' ); $this->set_name( '' );
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
class Paragraph extends NoValueField { class Paragraph extends NoValueField {
public function get_template_name(): string { public function get_template_name(): string {
return 'paragraph'; return 'paragraph';
} }
......
...@@ -6,6 +6,7 @@ use WPDesk\Forms\Serializer\ProductSelectSerializer; ...@@ -6,6 +6,7 @@ use WPDesk\Forms\Serializer\ProductSelectSerializer;
use WPDesk\Forms\Serializer; use WPDesk\Forms\Serializer;
class ProductSelect extends SelectField { class ProductSelect extends SelectField {
public function __construct() { public function __construct() {
$this->set_multiple(); $this->set_multiple();
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
class RadioField extends BasicField { class RadioField extends BasicField {
public function get_template_name(): string { public function get_template_name(): string {
return 'input-radio'; return 'input-radio';
} }
......
...@@ -18,7 +18,7 @@ class SelectField extends BasicField { ...@@ -18,7 +18,7 @@ class SelectField extends BasicField {
} }
public function set_multiple(): Field { public function set_multiple(): Field {
$this->attributes['multiple'] = true; $this->attributes['multiple'] = 'multiple';
return $this; return $this;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field; namespace WPDesk\Forms\Field;
class SubmitField extends NoValueField { class SubmitField extends NoValueField {
public function get_template_name(): string { public function get_template_name(): string {
return 'input-submit'; return 'input-submit';
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment