form/src/Element.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2017-06-01 09:44:36 +00:00
<?php
namespace Krutush\Form;
class Element{
protected $data = array();
public function __construct(string $name){
$this->data['name'] = $name;
}
2017-06-10 15:21:03 +00:00
public function rename(string $name): self{
$this->data['name'] = $name;
return $this;
}
2017-06-01 09:44:36 +00:00
public function name() : string{ return $this->data['name']; }
2017-06-10 15:21:03 +00:00
public function required(bool $value = true) : self{
2017-06-01 09:44:36 +00:00
$this->data['required'] = $value;
return $this;
}
2018-04-25 17:15:57 +00:00
public function value(string $value = null) : self{
2017-06-01 09:44:36 +00:00
$this->data['value'] = $value;
return $this;
}
2018-04-25 17:15:57 +00:00
public function get(){
2017-06-01 09:44:36 +00:00
return $this->data['value'];
}
2017-06-10 15:21:03 +00:00
public function error(bool $value = true) : self{
2017-06-01 09:44:36 +00:00
$this->data['error'] = $value;
return $this;
}
2018-04-25 17:15:57 +00:00
public function valid($data)/* :bool|string */{
2017-06-01 09:44:36 +00:00
if((!isset($data) || empty($data)) && isset($this->data['required']) && $this->data['required'] == true)
return 'requis';
return true;
}
public function html(string $more = '') : string{
return '<span '.$more.'></span>';
}
}