From 44e008fdc761e333e40786400628cf0e9dda1289 Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Thu, 7 Nov 2019 13:12:41 +0100 Subject: [PATCH] Add formatting option to RegexParser --- .../Argument/Parser/RegexParser.php | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/CommandLine/Argument/Parser/RegexParser.php b/src/CommandLine/Argument/Parser/RegexParser.php index f1ae888..e0e8a64 100644 --- a/src/CommandLine/Argument/Parser/RegexParser.php +++ b/src/CommandLine/Argument/Parser/RegexParser.php @@ -18,14 +18,20 @@ class RegexParser implements IValueParser { * @var string La regex à respecter */ protected $_regex = ''; + /** + * @var string|null Le format affiché dans la description + */ + protected $_format = ''; /** * Crée un nouveau parseur * * @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->setFormat($format); } /** @@ -42,7 +48,7 @@ class RegexParser implements IValueParser { * @inheritDoc */ 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 */ - public function setRegex($regex = null) { + public function setRegex($regex) { $this->_regex = $regex; 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; + } } \ No newline at end of file