PHPackages                             rollerworks/exception-parser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. rollerworks/exception-parser

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

rollerworks/exception-parser
============================

Extracts exception-information to an array

v1.0.1(10y ago)08171MITPHPPHP &gt;=5.3.3

Since Jul 6Pushed 10y agoCompare

[ Source](https://github.com/rollerworks-graveyard/rollerworks-exception-parser)[ Packagist](https://packagist.org/packages/rollerworks/exception-parser)[ RSS](/packages/rollerworks-exception-parser/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (1)

RollerworksExceptionParser
==========================

[](#rollerworksexceptionparser)

[![Build Status](https://camo.githubusercontent.com/6bce9a864f3eee479ebae89134d5e48ca571bef828ce60e45218b429275a3350/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f726f6c6c6572776f726b732f726f6c6c6572776f726b732d657863657074696f6e2d7061727365722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/rollerworks/rollerworks-exception-parser)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0e8e359a1a4eb8ed34f7b2f1ef19bcec2ccbb0185c795c44d7b334a524bd3c0b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726f6c6c6572776f726b732f726f6c6c6572776f726b732d657863657074696f6e2d7061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/rollerworks/rollerworks-exception-parser/?branch=master)

This package provides the Rollerworks ExceptionParser which extracts exception-data to an array.

Basically it wraps multiple exception-catch blocks into one call, and returns the parsed information.

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

[](#installation)

### 1. Using Composer

[](#1-using-composer)

To install the Rollerworks ExceptionParser, add `rollerworks/exception-parser` to your composer.json

```
$ php composer.phar require rollerworks/exception-parser:"~1.0"
```

Or manually, by adding the following to your `composer.json` file:

```
// composer.json
{
    // ...
    require: {
        // ...
        "rollerworks/exception-parser": "~1.0"
    }
}
```

Then, you can install the new dependency by running Composer's `update`command from the directory where your `composer.json` file is located:

```
$ php composer update exception-parser
```

**Note:** This package is stand-alone, composer is only used for generating the autoloader class.

You can also use your own autoloader, but make sure its [PSR-4](http://www.php-fig.org/psr/psr-4/) compatible. See the composer.json file in this package for mapping information.

Usage
-----

[](#usage)

Usage is very simple, each exception that you want to process needs a compatible parser which parses the Exception to an array.

The ExceptionParserManager passes trough all the registered exception-parses in order of registration, till one accepts the exception.

When no compatible parser is found an empty array is returned instead.

### Exception class

[](#exception-class)

```
class FieldRequiredException extends \RuntimeException
{
    private $fieldName;
    private $groupIdx;
    private $nestingLevel;

    /**
     * @param string  $fieldName
     * @param integer $groupIdx
     * @param integer $nestingLevel
     */
    public function __construct($fieldName, $groupIdx, $nestingLevel)
    {
        $this->fieldName = $fieldName;
        $this->groupIdx = $groupIdx;
        $this->nestingLevel = $nestingLevel;

        parent::__construct(sprintf('Field "%s" is required but is missing in group %d at nesting level %d.', $fieldName, $groupIdx, $nestingLevel));
    }

    /**
     * @return string
     */
    public function getFieldName()
    {
        return $this->fieldName;
    }

    /**
     * @return int
     */
    public function getGroupIdx()
    {
        return $this->groupIdx;
    }

    /**
     * @return int
     */
    public function getNestingLevel()
    {
        return $this->nestingLevel;
    }
}
```

### Exception Parser

[](#exception-parser)

The `SearchFieldRequiredExceptionParser` exception parser parses the `FieldRequiredException` shown above.

```
use Acme\Exception\FieldRequiredException;
use Rollerworks\Component\ExceptionParser\ExceptionParserInterface;

class SearchFieldRequiredExceptionParser implements ExceptionParserInterface
{
    /**
     * Returns whether the processor accepts the exception.
     *
     * @param \Exception $exception
     *
     * @return bool
     */
    public function accepts(\Exception $exception)
    {
        return $exception instanceof FieldRequiredException;
    }

    /**
     * Returns parameters parsed from the exception.
     *
     * @param \Exception $exception
     *
     * @return array
     */
    public function parseException(\Exception $exception)
    {
        /** @var FieldRequiredException $exception */

        return array(
            'message' => 'Field "{{ field }}" is required but is missing in group {{ group }} at nesting level {{ nesting }}.',
            'field' => $exception->getFieldName(),
            'group' => $exception->getGroupIdx(),
            'nesting' => $exception->getNestingLevel(),
        );
    }
}
```

### ParserManager

[](#parsermanager)

Now register the Parser at the ExceptionParserManager.

**Note:** You can register as many processors as needed.

```
use Rollerworks\Component\ExceptionParser\ExceptionParserManager;

require 'vendor/autoload.php';

$exceptionParser = new ExceptionParserManager();
$exceptionParser->addExceptionParser(new SearchFieldRequiredExceptionParser());

try {
    throw new Acme\Exception\FieldRequiredException('name', 0, 0);
} catch (Exception $exception) {
    $params = $exceptionParser->processException($exception);

    /*
    $params = array(
        'message' => 'Field "{{ field }}" is required but is missing in group {{ group }} at nesting level {{ nesting }}.',
        'field' => 'name',
        'group' => 0,
        'nesting' => 0,
    )
    */
}
```

#### Key transforming

[](#key-transforming)

The ExceptionParserManager also allows to transform the array-key to another format like '{{ name }}'.

'{var}' is the placeholder which is replaced by the current key.

```
$exceptionParser = new ExceptionParserManager('{{ {var} }}');
```

Or you can use a callback that returns the transformed key. This is very useful if the keys contains a prefix or is wrapped inside a special format.

```
$keyTransformer = new function ($value) {
    return ltrim($value, '$');
};

$exceptionParser = new ExceptionParserManager($keyTransformer);
```

**Note:** If the callback returns null or void the key is added as incrementing index. **Only when the "callback" returns null** or void, setting null as constructor value is the default and will not transform the array-keys.

```
require 'vendor/autoload.php';

$keyTransformer = new function ($value) {
    return null;
};

$exceptionParser = new ExceptionParserManager($keyTransformer);
$exceptionParser->addExceptionParser(new ExceptionParser\SearchFieldRequiredExceptionParser());

try {
    throw new Acme\Exception\FieldRequiredException('name', 0, 0);
} catch (Exception $exception) {
    $params = $exceptionParser->processException($exception);

    /*
    $params = array(
        0 => 'Field "{{ field }}" is required but is missing in group {{ group }} at nesting level {{ nesting }}.',
        1 => 'name',
        2 => 0,
        3 => 0,
    )
    */
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~395 days

Total

2

Last Release

3937d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0e812c04e848e9cc3afe6e966d2b81e81308124d96ce5f54eff4db0f8db0ea9?d=identicon)[sstok](/maintainers/sstok)

---

Top Contributors

[![sstok](https://avatars.githubusercontent.com/u/904790?v=4)](https://github.com/sstok "sstok (7 commits)")

---

Tags

parserexceptionerrorrollerworks

### Embed Badge

![Health badge](/badges/rollerworks-exception-parser/health.svg)

```
[![Health](https://phpackages.com/badges/rollerworks-exception-parser/health.svg)](https://phpackages.com/packages/rollerworks-exception-parser)
```

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k902.6M1.8k](/packages/nikic-php-parser)[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k910.8M118](/packages/doctrine-lexer)[erusev/parsedown

Parser for Markdown.

15.0k151.8M732](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

2.9k404.0M702](/packages/league-commonmark)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
