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/Parser/BooleanParser.class.php

38 lines
882 B
PHP

<?php
/**
* Déclaration de la classe CommandLine\Argument\Parser\BooleanParser
*/
namespace CommandLine\Argument\Parser;
use http\Exception\InvalidArgumentException;
/**
* Parseur vers un booléen
*
* Les valeurs suivantes sont acceptées :
* - true , 1, oui, vrai
* - false, 0, non, faux
*
* @package CommandLine\Argument\Parser
*/
class BooleanParser implements IValueParser {
/**
* @inheritDoc
*/
public function parseValue ($arg) {
if(!in_array($arg, array(
'true' , '1', 'oui', 'vrai',
'false', '0', 'non', 'faux',
)))
throw new InvalidArgumentException('La valeur n\'est pas un booléen valide : '.$arg);
return in_array($arg, array('true' , '1', 'oui', 'vrai'));
}
/**
* @inheritDoc
*/
public function getValueDescription () {
return 'boolean';
}
}