a1essandro / roman-numbers
Easy conversion int <-> roman numbers
dev-master
2016-02-07 17:19 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 4.7.*
- satooshi/php-coveralls: ~1.0
This package is not auto-updated.
Last update: 2025-01-04 21:08:44 UTC
README
Easy conversion int <=> roman numbers
##Requirements This package is guaranteed supported on PHP 5.3 and above.
##Installing ###Composer See more getcomposer.org.
Execute command
composer require a1essandro/roman-numbers
##Usage
###Basic
use NumberFormatter\RomanNumber; $romanFromInt = new RomanNumber(12); echo (string)$romanFromInt; // XII echo $romanFromInt->toInt(); // 12 $romanFromRomat = new RomanNumber('XIX'); echo (string)$romanFromRoman; // XIX echo $romanFromRoman->toInt(); // 19
###Validation
try { new RomanNumber($someVariable); } catch (InvalidStringException $e) { //if $someVariable is invalid string (not correct roman number) } catch (InvalidIntException $e) { //if $someVariable is invalid int (for example -1) } catch (InvalidArgumentException $e) { //if $someVariable is not int or string (invalid type) } //Another way to check validity: $validRomanNumber = 'XXIX'; RomanNumber::isValidRomanNumber($validRomanNumber); // true $invalidRomanNumber = 'XDX'; RomanNumber::isValidRomanNumber($invalidRomanNumber); // false