PHPackages                             wandersonwhcr/zend-romans - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wandersonwhcr/zend-romans

Abandoned → [wandersonwhcr/laminas-romans](/?search=wandersonwhcr%2Flaminas-romans)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

wandersonwhcr/zend-romans
=========================

Zend Framework Romans Integration

v1.0.2(9y ago)017MITPHPPHP ^7.0

Since Apr 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/wandersonwhcr/zend-romans)[ Packagist](https://packagist.org/packages/wandersonwhcr/zend-romans)[ RSS](/packages/wandersonwhcr-zend-romans/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (13)Versions (19)Used By (0)

zend-romans
===========

[](#zend-romans)

**DEPRECATED** use [Laminas Project Romans Integration](https://github.com/wandersonwhcr/laminas-romans)

[![Latest Stable Version](https://camo.githubusercontent.com/5906c1d7bf798b8bf8bc23b97460cfc96bf07d931af7d7073f21ec73501522d3/68747470733a2f2f706f7365722e707567782e6f72672f77616e646572736f6e776863722f7a656e642d726f6d616e732f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/wandersonwhcr/zend-romans)[![License](https://camo.githubusercontent.com/c36700a63762ea6dea5408e698c17221699e94dc37bb47dce2818f9bae4b7850/68747470733a2f2f706f7365722e707567782e6f72672f77616e646572736f6e776863722f7a656e642d726f6d616e732f6c6963656e73653f666f726d61743d666c6174)](https://packagist.org/packages/wandersonwhcr/zend-romans)

Description
-----------

[](#description)

This package provides a Zend Framework integration for [Romans](https://github.com/wandersonwhcr/romans) library, providing tools to filter a `string` with a Roman number to `int` and vice-versa, validate a `string` that contains this type of number and, finally, hydrate the content to `int`.

Installation
------------

[](#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/zend-romans": "^1.0"
    }
}
```

Usage
-----

[](#usage)

This package provide filters, validators and hydrators to use with Zend Framework projects. Also, this package is provided as a Zend Framework module, automatically configuring services inside application, but this action is not required.

### Filters

[](#filters)

Zend Romans provides a couple of filters to convert a `string` with Roman number to `int` and a Integer to a `string` that represents the input as Roman number.

```
use Zend\Romans\Filter\RomanToInt as RomanToIntFilter;
use Zend\Romans\Filter\IntToRoman as IntToRomanFilter;

$value = 'MCMXCIX';

$filter = new RomanToIntFilter();
$value  = $filter->filter($value); // 1999

$filter = new IntToRomanFilter();
$value  = $filter->filter($value); // MCMXCIX
```

### Validator

[](#validator)

Also, this package include a validator to verify if a `string` contains a valid Roman number.

```
use Zend\Romans\Validator\Roman as RomanValidator;

$validator = new RomanValidator();

$result = $validator->isValid('MCMXCIX'); // true

$result   = $validator->isValid('IAI'); // false
$messages = $validator->getMessages();

/*
$messages = [
    'unknownToken' => 'Unknown token "A" at position 1',
];
*/

$result   = $validator->isValid('XIIIX'); // false
$messages = $validator->getMessages();

/*
$messages = [
    'invalidRoman' => 'Invalid Roman number "XIIX"',
];
 */
```

### Hydrator

[](#hydrator)

There is a hydrator strategy, responsible to handle Roman numbers. Like any other Zend Framework strategy, exceptions will be throw for errors.

```
use InvalidArgumentException;
use Zend\Romans\Hydrator\Strategy\Roman as RomanHydratorStrategy;

$value    = 'MCMXCIX';
$strategy = new RomanHydratorStrategy();

try {
    $value = $strategy->hydrate($value); // 1999
    $value = $strategy->extract($value); // MCMXCIX
} catch (InvalidArgumentException $e) {
    // unable to convert
}
```

### ViewHelper

[](#viewhelper)

Finally, there is a view helper to convert `int` to Roman numbers directly, using an internal filter for this job.

```
use Zend\Romans\View\Helper\Roman as RomanViewHelper;

$helper = new RomanViewHelper();

// Simple Access
echo $helper(1999); // MCMXCIX

// ... or Inside ViewRenderer
echo $this->roman(1999); // MCMXCIX
```

### Module

[](#module)

This package is provided as a Zend Framework module. To initialize this module, add the package namespace into application loaded modules configuration.

```
