PHP code example of rollerworks / exception-parser

1. Go to this page and download the library: Download rollerworks/exception-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rollerworks / exception-parser example snippets



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 


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 


use Rollerworks\Component\ExceptionParser\ExceptionParserManager;

>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 

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

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

$exceptionParser = new ExceptionParserManager($keyTransformer);



$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 
bash
$ php composer.phar