Download the PHP package wyrihaximus/json-throwable without Composer
On this page you can find all versions of the php package wyrihaximus/json-throwable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wyrihaximus/json-throwable
More information about wyrihaximus/json-throwable
Files in wyrihaximus/json-throwable
Package json-throwable
Short Description 📠 JSON encode and decode throwables and exceptions
License MIT
Informations about the package json-throwable
JSON encode and decode throwables and exceptions
Installation
To install via Composer, use the command below, it will automatically detect the latest version and bind it with ~
.
Usage
This package comes with four functions:
throwable_json_encode
- Encodes any Throwable to a JSON stringthrowable_encode
- Encodes any Throwable to an arraythrowable_json_decode
- Decodes a JSON string in the format fromthrowable_json_encode
into the originalException
orError
throwable_decode
- Decodes an array in the format fromthrowable_encode
into the originalException
orError
Heads up
There are a few gotchas when using this package.
- Both the encoding functions drop the arguments from the trace.
- Because we can't overwrite the trace, a new one will be placed in the
originalTrace
property when available. - Any previous
Throwable
s will also be encoded and decoded but always withthrowable_json_*
.
Example of gaining access to the original trace, it isn't optimal, but it works:
Alternatively you can use the trait supplied by this package:
Including additional properties from throwables
If your throwables include any properties you'd want to take along when it gets encoded, implement the AdditionalPropertiesInterface
returning a list of all properties you'd want to haved included in the encoding:
Encode/Decode array type hint
When you're calling throwable_encode
or throwable_decode
the array (return) type hint has the following signature:
This signature isn't enforce by PHP but tools like PHPStan
or Psalm
will use it to assert type safety from a static analysis pont of view.
Contributing
Please see CONTRIBUTING for details.
License
Copyright 2020 Cees-Jan Kiewiet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All versions of json-throwable with dependencies
doctrine/instantiator Version ^1.0.5 || ^2.0.0
thecodingmachine/safe Version ^1.3.3 || ^2.0.0
wyrihaximus/json-utilities Version ^1.3.1