From 232c9ab4eb74b42f7eef04c3717c91fd6403d314 Mon Sep 17 00:00:00 2001 From: Benjamin Paap Date: Wed, 14 Mar 2018 12:04:30 +0100 Subject: [PATCH] Add: Readme --- README.md | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f3590c8 --- /dev/null +++ b/README.md @@ -0,0 +1,203 @@ +# API Sandbox Bundle + +This bundle is designed to prevent requests using your real controllers and responding with a fake +response you defined. It integrates nicely with `NelmioApiDocBundle` and `FOSRestBundle`. + +When using `NelmioApiDocBundle` this bundle will generate `curl` examples for your provided sandbox +requests automatically which will show in the documentation. + +## Requirements + +ApiSandboxBundle required php >= 5.5 and symfony >= 2.7. + +## Installation + +The easiest way to install this library is through [composer](http://getcomposer.org/). +Just add the following lines to your **composer.json** file and run `composer.phar update`: + +```json +{ + "require": { + "bpa/api-sandbox-bundle": "~0.1" + } +} +``` + +## Configuration + +Load the bundle in your `AppKernel.php`: + +```php +class AppKernel extends Kernel { + public function registerBundles() { + // ... + $bundles = [ + // ... + new Bpa\ApiSandboxBundle\ApiSandboxBundle(), + // ... + ]; + // ... + } +} +``` + +I would recommend to create a new environment for your sandbox by copying the `app.php` front controller +to something like `app_sandbox.php`. In your new front controller you have to change the following line +to the new environment: + +```php +$kernel = new AppKernel('sandbox', false); +``` + +Create a new `config_sandbox.yml` in your `app/config` directory with the following contents: + +```yaml +imports: + - { resource: config_prod.yml } + +api_sandbox: + enabled: true + force_response: true +``` + +This takes all settings from your `prod` environment and enables the sandbox for your new `sandbox` +environment. + +## Usage + +### A basic Controller + +When using the `FOSRestBundle` and `NelmioApiDocBundle` for your API an integration within your +application could look something like this: + +```php + [ 'id' => 1, 'title' => 'A Brief History of Time' ], + ]); + } +} +``` + +### Using parameters + +It's possible to define multiple responses for a single Controller action and distinguish between +them by using the `SandboxRequest\Parameter` Annotation like this: + +```php +