org_heigl / slim-json-helpers
Clone of aporat/slim-json-helpers | Slim3 JSON Request & Response Helpers
1.1.1
2021-01-03 03:58 UTC
Requires
- php: ^7.2 | ^8.0
- psr/container: ^1.0.0
- slim/slim: ~3
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^8.0 | ^9.0
Conflicts
Replaces
README
A clone of the removed aporat/slim-json-helpers
Requirements
- PHP >= 5.5
Usage
use Slim\Http\Request as Request; use JsonHelpers\Renderer as JsonRenderer; $app = new \Slim\App($settings); $container = $app->getContainer(); // register the json response and error handlers $jsonHelpers = new JsonHelpers\JsonHelpers($app->getContainer()); $jsonHelpers->registerResponseView(); $jsonHelpers->registerErrorHandlers(); $this->post('/users', function (Request $request, Response $response, $args) { $user_id = $request->getParam('user_id'); $data = [ 'user_id' => $user_id ]; $response = $this->view->render($response, 200, $data); return $response; }); }