wandersonwhcr / plates-romans
Arabic到罗马数字及反之转换的Plates扩展
1.0.1
2021-04-03 14:32 UTC
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
Arabic到罗马数字及反之转换的Plates扩展
描述
此包扩展为Romans库提供了Plates集成,提供将罗马数字字符串转换为阿拉伯数字字符串以及反之的方法。
安装
此包默认使用Composer作为仓库。您可以通过在composer.json
文件的require
属性中添加包名来安装它,指向最后一个稳定版本。
{ "require": { "wandersonwhcr/plates-romans": "^1.0" } }
用法
此包作为Plates扩展,必须与Plates引擎一起加载。
use League\Plates\Engine; use League\Plates\Romans\Extension\Romans as RomansExtension; $engine = new Engine(); $engine->loadExtension(new RomansExtension());
之后,可以使用方法arabicToRoman
和romanToArabic
在模板内部使用,如下所示。
// 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.
此外,可以使用try..catch语法处理错误。
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 }
开发
您可以使用Docker Compose来构建镜像并运行容器以开发测试此包。
docker-compose build
docker-compose run romans composer install
docker-compose run romans composer test
许可证
此包是开源的,在LICENSE中描述的MIT许可证下可用。