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.
phpcommandline/Argument/Value/FixedValue.class.php

74 lines
1.9 KiB
PHP

<?php
/**
* Déclaration de CommandLine\Argument\Value\FixedValue
*/
namespace CommandLine\Argument\Value;
use CommandLine\Argument\IArgumentValueDescription;
use CommandLine\Argument\ParseResult;
/**
* Argument devant correspondre une valeur fixe
*
* @property string $value {@see $_value $_value}.
*
* @package CommandLine\Argument
*/
class FixedValue extends ValueAbstract implements IArgumentValueDescription {
/**
* @var string La valeur que doit avoir l'argument
*/
protected $_value;
/**
* Crée un nouvel argument de type valeur
*
* @param int $position La position
* @param string $varName Le nom de la variable
* @param string $value La valeur
* @param string|null $description La description
* @param boolean $optional Valeur optionnelle ?
*
* @throws \Fidit\v3\Exception\InvalidArgument Si l'un des paramètres n'est pas correct
*/
public function __construct ($varName, $value, $description, $optional = false) {
parent::__construct($value, $description, $optional);
$this->setVarName($varName);
$this->setValue($value);
}
public function parse ($args) {
if($args[0] == $this->getValue())
return new ParseResult($this->getValue(), 1);
return null;
}
public function getValueDescription () {
return '"'.$this->getValue().'"';
}
/**
* La valeur.
*
* @return string La valeur.
*
* @see $_value
*/
public function getValue() {
return $this->_value;
}
/**
* Définit la valeur
*
* @param string $value La valeur
*
* @return $this
*
* @see $_value
*/
public function setValue($value) {
$this->_value = $value;
return $this;
}
}