Skip to content
Permalink
Browse files

Remove exception handling

  • Loading branch information...
mabar authored and f3l1x committed Feb 8, 2019
1 parent 22a1e60 commit 0a1848df13fc620b90270528460bce31a4c47394
Showing with 7 additions and 43 deletions.
  1. +7 −11 .docs/README.md
  2. +0 −8 src/DI/NegotiationPlugin.php
  3. +0 −24 src/Decorator/ThrowExceptionDecorator.php
@@ -35,28 +35,24 @@ api:
plugins:
Apitte\Negotiation\DI\NegotiationPlugin:
unification: false
catchException: false
```

- `unification` - Change default `JsonTransformer` to `JsonUnifyTransform`. You will see in next capter.
- `catchException` - Great for front-end developers, convert (catch) Tracy-exception to JSON.
- `unification` - Change default `JsonTransformer` to `JsonUnifyTransform`. You will see in next chapter.

## Negotiation

This plugin adds new features. They are called decorators, negotiators and transformers.

Basically, decorator listen on specic event and can modify incomming request or outgoing response directly or via negotiator.
Basically, decorator listen on specific event and can modify incoming request or outgoing response directly or via negotiator.
The negotiator has the handling logic, if request has an appropriate extension or header and call the transformer.
All modifications (trasforming data from A to B) is done in transformer, e.q. transform array to json.
All modifications (transforming data from A to B) is done in transformer, e.q. transform array to json.

### Decorators

There are 2 predefined decorators:
There is single predefined decorator:

- `ResponseEntityDecorator` - It listens on 2 events, after dispatching and after exception. It means this decorator is trigged when the response is returned from controller
or if some exception is throwed.

- `ThrowExceptionDecorator` - This decorator is appliable only in debug mode. It just diplays the exception for you.
- `ResponseEntityDecorator` - It listens on 2 events, after dispatching and after exception. It means this decorator is triggered when the response is returned from controller
or if some exception is thrown.

### Negotiators

@@ -81,7 +77,7 @@ These classes transform data formats from A to B.
- `CsvTransform` - Transform `entity` -> `csv`, but the entity must have an appropriate data.

- `RendererTransformer` - This is special transformer. If annotation `@Negotiation(renderer = App\Some\Class` has provided renderer attribute,
this transformer recieve that renderer, `entity` -> `renderer(entity)`.
this transformer receive that renderer, `entity` -> `renderer(entity)`.

## Playground

@@ -11,7 +11,6 @@
use Apitte\Core\Exception\Logical\InvalidStateException;
use Apitte\Negotiation\ContentNegotiation;
use Apitte\Negotiation\Decorator\ResponseEntityDecorator;
use Apitte\Negotiation\Decorator\ThrowExceptionDecorator;
use Apitte\Negotiation\DefaultNegotiator;
use Apitte\Negotiation\FallbackNegotiator;
use Apitte\Negotiation\SuffixNegotiator;
@@ -28,7 +27,6 @@ class NegotiationPlugin extends AbstractPlugin
/** @var mixed[] */
protected $defaults = [
'unification' => false,
'catchException' => false,
];
public function __construct(PluginCompiler $compiler)
@@ -108,12 +106,6 @@ public function loadPluginConfiguration(): void
->addTag(ApiExtension::NEGOTIATION_TRANSFORMER_TAG, ['suffix' => 'json'])
->setAutowired(false);
}
if ($config['catchException'] === false && $globalConfig['debug'] === true) {
$builder->addDefinition($this->prefix('decorator.throwException'))
->setFactory(ThrowExceptionDecorator::class)
->addTag(ApiExtension::CORE_DECORATOR_TAG, ['priority' => 99, 'type' => IDecorator::ON_DISPATCHER_EXCEPTION]);
}
}
/**

This file was deleted.

Oops, something went wrong.

0 comments on commit 0a1848d

Please sign in to comment.
You can’t perform that action at this time.