fix unsaved
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
0e5e671423
commit
7c79d2656a
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
abstract class AbstractField implements IField {
|
||||
protected $name;
|
||||
protected $value;
|
||||
protected $validators = [];
|
||||
|
||||
public function __construct($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
// Autres méthodes...
|
||||
}
|
||||
|
||||
// abstract class AbstractField {
|
||||
// protected $name;
|
||||
// protected $value;
|
||||
// protected $attributes;
|
||||
// protected $errors = [];
|
||||
// protected $validators = [];
|
||||
|
||||
// public function __construct($name, $value = '', $attributes = []) {
|
||||
// $this->name = $name;
|
||||
// $this->value = $value;
|
||||
// $this->attributes = $attributes;
|
||||
// }
|
||||
|
||||
// public function getName() {
|
||||
// return $this->name;
|
||||
// }
|
||||
|
||||
// public function getValue() {
|
||||
// return $this->value;
|
||||
// }
|
||||
|
||||
// public function setValue($value) {
|
||||
// $this->value = $value;
|
||||
// }
|
||||
|
||||
// public function addValidator(callable $validator) {
|
||||
// $this->validators[] = $validator;
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
// public function isValid() {
|
||||
// foreach ($this->validators as $validator) {
|
||||
// if (!$validator($this->value)) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public function getErrors() {
|
||||
// return $this->errors;
|
||||
// }
|
||||
|
||||
// public function addError($error) {
|
||||
// $this->errors[] = $error;
|
||||
// }
|
||||
|
||||
// public function getAttributesAsString() {
|
||||
// $attributesStr = '';
|
||||
// foreach ($this->attributes as $key => $value) {
|
||||
// $attributesStr .= " $key=\"$value\"";
|
||||
// }
|
||||
// return $attributesStr;
|
||||
// }
|
||||
|
||||
// abstract public function render();
|
||||
// }
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
abstract class AbstractType implements FormTypeInterface
|
||||
{
|
||||
|
||||
protected $fields = [];
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function finishView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
class FieldFactory {
|
||||
public static function createField($type, $name) {
|
||||
switch($type) {
|
||||
case 'text': return new TextField($name);
|
||||
// Autres cas...
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class FormBuilder {
|
||||
private $form;
|
||||
|
||||
public function __construct() {
|
||||
$this->form = new BasicForm();
|
||||
}
|
||||
|
||||
public function addText($name, $options) {
|
||||
$this->form->add(FieldFactory::createField('text', $options));
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build() {
|
||||
return $this->form;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
interface FormInterface {
|
||||
public function add(FieldInterface $field);
|
||||
public function remove($fieldName);
|
||||
public function submit($requestData);
|
||||
public function isValid();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<!-- rendering HTML form fields, validating submitted data, mapping the form data into objects and a lot more -->
|
||||
<?php
|
||||
|
||||
class Login extends AbstractForm {
|
||||
// Implémentation spécifique de BasicForm
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class TextField extends AbstractField {
|
||||
public function render() {
|
||||
return "<input type='text' name='{$this->name}' value='{$this->value}' />";
|
||||
}
|
||||
|
||||
public function validate($value) {
|
||||
// Logique de validation
|
||||
}
|
||||
}
|
Loading…
Reference in new issue