You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.0 KiB
PHP
80 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Déclaration de CommandLine\Argument\Value\Value
|
|
*/
|
|
namespace CommandLine\Argument\Value;
|
|
|
|
use CommandLine\Argument\IArgumentValueDescription;
|
|
use CommandLine\Argument\Parser\IValueParser;
|
|
use CommandLine\Argument\ParseResult;
|
|
use CommandLine\Exception\IncorrectParse;
|
|
use RangeException;
|
|
|
|
/**
|
|
* Argument de type "valeur"
|
|
*
|
|
* @package CommandLine\Argument\Value
|
|
*/
|
|
class Value extends ValueAbstract implements IArgumentValueDescription {
|
|
/**
|
|
* @var IValueParser Parseur pour la valeur
|
|
*/
|
|
protected $_valueParser;
|
|
|
|
/**
|
|
* Crée un nouvel argument de type valeur
|
|
*
|
|
* @param string $name Le nom
|
|
* @param string|null $description La description
|
|
* @param IValueParser $valueParser Le parseur de valeur.
|
|
* @param boolean $optional Valeur optionnelle ?
|
|
*/
|
|
public function __construct ($name, $description, IValueParser $valueParser, $optional = false) {
|
|
parent::__construct($name, $description, $optional);
|
|
|
|
$this->setValueParser($valueParser);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function parse ($args) {
|
|
try {
|
|
return new ParseResult($this->_valueParser->parseValue($args[0]), 1);
|
|
}
|
|
catch (RangeException $e) {
|
|
throw new IncorrectParse('Échec du parsage de la valeur "' . $args[0] . '"', 0, $e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getValueDescription () {
|
|
return $this->_valueParser->getValueDescription();
|
|
}
|
|
|
|
/**
|
|
* Le parseur de valeur.
|
|
*
|
|
* @return IValueParser Le parseur.
|
|
*
|
|
* @see $_valueParser
|
|
*/
|
|
public function getValueParser() {
|
|
return $this->_valueParser;
|
|
}
|
|
/**
|
|
* Définit le parseur de valeur
|
|
*
|
|
* @param IValueParser $valueParser Le parseur
|
|
*
|
|
* @return $this
|
|
*
|
|
* @see $_valueParser
|
|
*/
|
|
public function setValueParser(IValueParser $valueParser) {
|
|
$this->_valueParser = $valueParser;
|
|
return $this;
|
|
}
|
|
} |