Add formatting option to RegexParser

master 1.1.0
Julien Rosset 6 years ago
parent 429df447dd
commit 44e008fdc7

@ -18,14 +18,20 @@ class RegexParser implements IValueParser {
* @var string La regex à respecter * @var string La regex à respecter
*/ */
protected $_regex = ''; protected $_regex = '';
/**
* @var string|null Le format affiché dans la description
*/
protected $_format = '';
/** /**
* Crée un nouveau parseur * Crée un nouveau parseur
* *
* @param string $regex Le motif à respecter * @param string $regex Le motif à respecter
* @param string|null $format Le format à afficher
*/ */
public function __construct ($regex) { public function __construct ($regex, $format = null) {
$this->setRegex($regex); $this->setRegex($regex);
$this->setFormat($format);
} }
/** /**
@ -42,7 +48,7 @@ class RegexParser implements IValueParser {
* @inheritDoc * @inheritDoc
*/ */
public function getValueDescription () { public function getValueDescription () {
return $this->getRegex(); return is_null($this->getFormat()) ? $this->getRegex() : $this->getFormat();
} }
/** /**
@ -62,8 +68,30 @@ class RegexParser implements IValueParser {
* *
* @return $this * @return $this
*/ */
public function setRegex($regex = null) { public function setRegex($regex) {
$this->_regex = $regex; $this->_regex = $regex;
return $this; return $this;
} }
/**
* Le format à afficher
*
* @return string|null Le format
*
* @see $_format
*/
public function getFormat() {
return $this->_format;
}
/**
* Modifie le format à afficher
*
* @param string|null $format Le nouveau format
*
* @return $this
*/
public function setFormat($format = null) {
$this->_format = $format;
return $this;
}
} }
Loading…
Cancel
Save