royalcms / wrappers-php-json
The Most Useful Wrappers For PHP Functions
Installs: 115
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/royalcms/wrappers-php-json
Requires
- php: ^7.2
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8.0 || ^9.3
README
The Most Useful Wrappers For PHP Functions
This package contains most useful wrappers for native PHP functions.
Install
Require this package with composer using the following command:
$ composer require royalcms/wrappers-php-json "^2.0"
Installed
composeris required (how to install composer).
You need to fix the major version of package.
Usage
\Tarampampam\Wrappers\Json
This wrapper was wrote for throwing exceptions (JsonEncodeDecodeException) on any tries to work with wrong json string or converting wrong object into json string.
Also method ::decode(...) by default returns associated array instead object ($assoc = true).
Examples:
<?php use Tarampampam\Wrappers\Json; Json::encode(['foo' => 'bar']); // {"foo":"bar"} Json::encode(tmpfile()); // Throws an exception - value cannot be resource Json::decode('{"foo":"bar"}'); // ['foo' => 'bar'] Json::decode('{"foo":"bar"}', false); // $object->foo === bar Json::decode('{"foo":"ba'); // Throws an exception - wrong json string Json::encode([], JSON_EMPTY_ARRAYS_TO_OBJECTS); // {} Json::encode(['foo' => []], JSON_EMPTY_ARRAYS_TO_OBJECTS); // {"foo":{}} Json::encode(['foo' => 'bar'], JSON_PRETTY_PRINT_2_SPACES); // { // "foo": "bar" // }
Testing
For package testing we use phpunit framework and docker-ce + docker-compose as develop environment. So, just write into your terminal after repository cloning:
$ make build $ make latest # or 'make lowest' $ make test
Changes log
Changes log can be found here.
Support
If you will find any package errors, please, make an issue in current repository.
License
This is open-sourced software licensed under the MIT License.