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

32 lines
827 B
PHP

<?php
/**
* Déclaration de la classe CommandLine\Argument\Parser\BooleanParser
*/
namespace CommandLine\Argument\Parser;
use Fidit\v3\Exception\InvalidArgument;
/**
* 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 {
public function parseValue ($arg) {
if(!in_array($arg, array(
'true' , '1', 'oui', 'vrai',
'false', '0', 'non', 'faux',
)))
throw new InvalidArgument($arg, 'La valeur n\'est pas un booléen valide');
return in_array($arg, array('true' , '1', 'oui', 'vrai'));
}
public function getValueDescription () {
return 'boolean';
}
}