wandersonwhcr / plates-romans
Plates Extension to Convert Arabic to Roman Numerals and Vice Versa
Requires
- php: >=7.4
- league/plates: ^3.0.1
- wandersonwhcr/romans: ^1.0
Requires (Dev)
- php-parallel-lint/php-parallel-lint: 1.2.*
- phpmd/phpmd: 2.9.*
- phpunit/phpunit: 9.5.*
- sebastian/phpcpd: 6.0.*
- slevomat/coding-standard: 6.4.*
- squizlabs/php_codesniffer: 3.5.*
README
Plates Extension to Convert Arabic to Roman Numerals and Vice Versa
Description
This package extension provides a Plates integration for
Romans library, providing methods to
convert a string
with a Roman number to a string
with Arabic and vice-versa.
Installation
This package uses Composer as default repository. You can install it adding the
name of package in require
attribute of composer.json
, pointing to the last
stable version.
{ "require": { "wandersonwhcr/plates-romans": "^1.0" } }
Usage
This package acts as a Plates extension and must be loaded with Plates Engine.
use League\Plates\Engine; use League\Plates\Romans\Extension\Romans as RomansExtension; $engine = new Engine(); $engine->loadExtension(new RomansExtension());
After, methods arabicToRoman
and romanToArabic
can be used inside templates
as example below.
// Outputs MCMXCIX
Arabic 1999 can be represented as <?php echo $this->arabicToRoman('1999') ?> Roman Numeral.
// Outputs 2021
Roman MMXXI can be represented as <?php echo $this->romanToArabic('MMXXI') ?> Arabic Numeral.
Also, errors can be handled using a try..catch syntax.
use League\Plates\Romans\Extension\Exception as ExtensionException; try { $this->arabicToRoman('-1'); } catch (ExtensionException $e) { // Invalid Integer: -1 } try { $this->romanToArabic('Z'); } catch (ExtensionException $e) { // Invalid Token: Z }
Development
You can use Docker Compose to build an image and run a container to develop and test this package.
docker-compose build
docker-compose run romans composer install
docker-compose run romans composer test
License
This package is opensource and available under MIT license described in LICENSE.