for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Roman plugin for Craft CMS 3.x
*
* Convert an integer into roman numerals and vice versa.
* @link dominion-designs.com
* @copyright Copyright (c) 2019 Jalen Davenport
*/
namespace jalendport\roman\services;
use craft\base\Component;
* RomanService Service
* @author Jalen Davenport
* @package Roman
* @since 1.0.0
class RomanService extends Component
{
* @var string
private $result = '';
* @var array
public $romanNumerals = [
'M' => 1000,
'CM' => 900,
'D' => 500,
'CD' => 400,
'C' => 100,
'XC' => 90,
'L' => 50,
'XL' => 40,
'X' => 10,
'IX' => 9,
'V' => 5,
'IV' => 4,
'I' => 1
];
* @param null $number
$number
null
* @return string|null
public function getRoman($number = null)
$this->result = null;
foreach($this->romanNumerals as $key => $value)
$matches = (int)($number / $value);
$this->result .= str_repeat($key, $matches);
$number %= $value;
}
return $this->result;
* @param null $roman
$roman
public function getNumber($roman = null)
while (strpos($roman, $key) === 0)
$this->result += $value;
$roman = substr($roman, strlen($key));