Download the PHP package jeronimofagundes/php-roman-numbers without Composer

On this page you can find all versions of the php package jeronimofagundes/php-roman-numbers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-roman-numbers

php-roman-numbers

Support for roman numbers in PHP

Architecture

It was implemented a simple helper class, namespaced "\Jeronimofagundes\Numbers\Roman\Helper", which have two methods to convert to and from arabic numbers.

The autoloading was used following PHP FIG's PSR-4 autoloading standards.

The source code is inside the "src" directory. Dependencies are inside "vendor" directory. Tests are inside "tests" folder.

Testing

To perform unitary tests I used PHPUnit framework. There is one class contaning the tests for the Helper class.

Problem-solving

Conversion Arabic to Roman

The first thing I checked is if the arabic number fits the range [1-3999]. This range was defined by Wikipedia's Roman numerals article.

After that, I fill the input number with zeros to the left so it reaches 4 digits long. Example: 14 turns into 0014.

The next step is convert each character into its corresponding roman. These correspondences are mapped in a constant TO_ROMAN inside the Helper class. There is mappings for "ones", "tens", "hundreds" and "thousands". This way, the first 0 is ignored, the second one ignored as well, 1 turns into X and 4 turns into IV. That means the returned string is XIV.

Conversion Roman to Arabic

This conversion starts checking of the given roman number is valid. I did this using a regular expression.

I mapped some correspondences in a constant FROM_ROMAN in the Helper class. Using this, I read the roman number in the following way:

  1. I start from the most left character.
  2. I read two characters. If this correspondence is mapped in the FROM_ROMAN array, it means it is a subtractive correspondence (like IV, XC or CM), and it gets converted. We move the pointer two characters right and go to step 2 again.
  3. If there is no correspondence in the FROM_ROMAN array, it means it is not a subtractive correspondence. So, we just read one character. That character will have a correspondence in the array, and that value is added to the final result. We move one character to the right and go back to the step two.
  4. The processing ends when the roman number is finished.

How to use this library

In order to one use this library, he/she can require it with composer, the standard PHP library package manager.

and use the following class in his/her code:

I included a file named example.php showing how to use the library. To run it, follow this steps:

  1. Clone this repository and cd into it

  2. . Pull the docker image

  3. Install the dependencies with composer

  4. Run the file example.php:

How to test it

We need to use PHPUnit to execute the tests, and we will do it using docker. Follow this steps:

  1. Clone this repository and cd into it

  2. Pull the docker image

  3. Run PHPUnit

All versions of php-roman-numbers with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jeronimofagundes/php-roman-numbers contains the following files

Loading the files please wait ....