{"id":14983661,"url":"https://github.com/danrevah/sandbox-bundle","last_synced_at":"2025-04-10T19:04:32.097Z","repository":{"id":27458605,"uuid":"30937512","full_name":"danrevah/sandbox-bundle","owner":"danrevah","description":"Symfony bundle which is used to create fake API Sandbox response with annotations","archived":false,"fork":false,"pushed_at":"2018-07-14T20:36:00.000Z","size":99,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-24T16:46:03.631Z","etag":null,"topics":["annotations","php","php7","symfony","symfony2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danrevah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-17T21:00:13.000Z","updated_at":"2024-03-03T19:30:35.000Z","dependencies_parsed_at":"2022-08-21T05:40:21.142Z","dependency_job_id":null,"html_url":"https://github.com/danrevah/sandbox-bundle","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danrevah%2Fsandbox-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danrevah%2Fsandbox-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danrevah%2Fsandbox-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danrevah%2Fsandbox-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danrevah","download_url":"https://codeload.github.com/danrevah/sandbox-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248279196,"owners_count":21077406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotations","php","php7","symfony","symfony2"],"created_at":"2024-09-24T14:07:44.798Z","updated_at":"2025-04-10T19:04:32.074Z","avatar_url":"https://github.com/danrevah.png","language":"PHP","funding_links":[],"categories":["Development"],"sub_categories":[],"readme":"# SandboxBundle \u0026nbsp;\n[![Build Status](https://scrutinizer-ci.com/g/danrevah/SandboxBundle/badges/build.png?b=master)](https://scrutinizer-ci.com/g/danrevah/SandboxBundle/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/danrevah/SandboxBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/danrevah/SandboxBundle/?branch=master) [![Latest Stable Version](https://poser.pugx.org/danrevah/sandbox-bundle/v/stable.svg)](https://packagist.org/packages/danrevah/sandbox-bundle) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/340a668f-05a0-47a7-b5e2-c574a3b7e53d/mini.png)](https://insight.sensiolabs.com/projects/340a668f-05a0-47a7-b5e2-c574a3b7e53d)\n\n\u003e SandboxBundle is a Symfony2 Bundle which is mostly used in conditions when you don't want to reach your real controller in a sandbox / testing environment.\n\n\u003e For example, if you have a controller which handles some action let's say a purchase, \n\u003e you could use a fake response instead of creating a real purchase request.\n\u003e Only by using annotations and in your sandbox / testing environment the controller will be overriden with the response you choose (in JSON or XML format).\n\n\n## Table of contents\n\n * [Installation](#installation)\n * [Create a Sandbox environment](#create-a-sandbox-environment)\n * [Single response annotation](#single-response-annotation)\n * [Multi response annotation](#multi-response-annotation)\n\n\n## Installation\n\nThe following instructions outline installation using Composer. If you don't\nhave Composer, you can download it from [http://getcomposer.org/](http://getcomposer.org/)\n\n * Run either of the following commands, depending on your environment:\n\n```\n$ composer require \"danrevah/sandbox-bundle\":\"dev-master\"    \n$ php composer.phar require \"danrevah/sandbox-bundle\":\"dev-master\"    \n```\n\n\n## Create a Sandbox environment\n\n* Copy the file from your `project-root-directory/web/app_dev.php` into the same directory and call the new file `app_sandbox.php`.\n* In the file you've just created `app_sandbox.php` change this line `$kernel = new AppKernel('dev', true); ` to this line `$kernel = new AppKernel('sandbox', true); `\n* Go to `project-root-directory/app/AppKernel.php` and change this line  `if (in_array($this-\u003egetEnvironment(), array('dev', 'test'))) ` to this line `if (in_array($this-\u003egetEnvironment(), array('dev', 'test','sandbox'))) ```\n* In the AppKernel.php file after the `if case` you've just edited, add this `if case` also:\n```php\n    if (in_array($this-\u003egetEnvironment(), array('sandbox'))) {\n        $bundles[] = new danrevah\\SandboxBundle\\SandboxBundle();\n    }\n```\n* Copy the file from `project-root-directory/app/config/config_dev.yml` and call it `config_sandbox.yml`.\n* Add this to the end of your `config_sandbox.yml`:\n```yml\n    sandbox:\n      response:\n        force: true\n        # Force mode means you won't be able to \"fall\"\n        # to the REAL controller if a Sandbox response is not available.\n        # It will produce an error instead.\n```\n* **That's it! you can now access your sandbox environment using `app_sandbox.php`**\n\n## Single Response Annotation\n\nused in situations when you need a constant response while on sandbox enviorment. the response will always be the same.\n\n```php\n    /**\n     * GET /resource\n     *\n     * @ApiSandboxResponse(\n     *      responseCode=200,\n     *      type=\"json\",\n     *      parameters={\n     *          {\"name\"=\"some_parameter\", \"required\"=true}\n     *      },\n     *      resource=\"@SandboxBundle/Resources/responses/token.json\"\n     * )\n     */\n    public function getAction() {\n        return array('foo');\n    }\n```\n\n* `responseCode` (default = 200) - it's the Http response code of the Sandbox response.\n* `type` (default = 'json') - you can choose between 'json' and 'xml'.\n* `parameters` (default = array()) - this is used to validate required parameters in the Sandbox API in order to produce an Exception if the parameter is missing.\n* `resource` (**required**) - the real controller will be overwritten by this, in the above example it will ALWAYS return the contents of the `token.json` instead of the 'foo' from the real getAction(), it won't even go inside.\n\n\n## Multi Response Annotation\n\nused in situations when you need to return different responses depending on the parameters which are being sent.\n\n```php\n    /**\n     * POST /resource\n     *\n     * @ApiSandboxMultiResponse(\n     *      responseCode=200,\n     *      type=\"json\",\n     *      parameters={\n     *          {\"name\"=\"some_parameter\", \"required\"=true}\n     *      },\n     *      responseFallback={\n     *          \"type\"=\"xml\",\n     *          \"responseCode\"=500,\n     *          \"resource\"=\"@SandboxBundle/Resources/responses/error.xml\"\n     *      },\n     *      multiResponse={\n     *          {\n     *              \"type\"=\"xml\",\n     *              \"resource\"=\"@SandboxBundle/Resources/responses/token.xml\",\n     *              \"caseParams\": {\"some_parameter\"=\"1\", \"some_parameter2\"=\"2\"}\n     *          },\n     *          {\n     *              \"resource\"=\"@SandboxBundle/Resources/responses/token.json\",\n     *              \"caseParams\": {\"some_parameter\"=\"3\", \"some_parameter2\"=\"4\"}\n     *          }\n     *      }\n     * )\n     */\n    public function postAction() {\n        return array('bar');\n    }\n```\n \n* `responseCode` (default = 200) - it's the Http response code of the Sandbox response.\n* `type` (default = 'json') - you can choose between 'json' and 'xml'.\n* `parameters` (default = array()) - this is used to validate required parameters in the Sandbox API in order to produce an Exception if the parameter is missing.\n* `multiResponse` (**required**) - used to find matching `parameters` from the request and if the values are equal, it returns a response with the `resource` file mentiond. the parameters `type` and `responseCode` inside the `multiResponse` are not required it will use the parent parameters if none is found inside a matching case.\n* `responseFallback` (**required**) - it's using this response when none of the `multiResponse` `caseParams` has been matched.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanrevah%2Fsandbox-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanrevah%2Fsandbox-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanrevah%2Fsandbox-bundle/lists"}