qpautrat / woohoolabs-yin-bundle
Implements woohoolabs/yin framework into Symfony
Installs: 39 283
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 5
Open Issues: 2
Type:symfony-bundle
Requires
- php: ^7.1.0
- psr/http-factory: ^1.0
- sensio/framework-extra-bundle: ^5.4
- symfony/psr-http-message-bridge: ^1.2
- woohoolabs/yin: ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- nyholm/psr7: ^1.2
- phpspec/phpspec: ^4.3
README
This bundle implements woohoolabs/yin library into Symfony framework.
Note: 5.x
is for Yin 4.x
, 4.x
is for Yin 3.x
and 3.x
is for Yin 0.11
Installation
$ composer require qpautrat/woohoolabs-yin-bundle
Then for Symfony 3.x and before, like for any other bundle, include it in your Kernel class:
public function registerBundles() { $bundles = array( // ... new QP\WoohoolabsYinBundle\QPWoohoolabsYinBundle(), ); // ... }
Symfony 4+ will automatically register the bundle.
Configuration
By default jsonApi
class is intialized with Yin's ExceptionFactory
.
You can provide your own factory implementation.
To do that you have to define which service to use in your global configuration like this:
qp_woohoolabs_yin: exception_factory: my_exception_factory_service
Usage
Configure service binding:
services: _defaults: #... bind: WoohooLabs\Yin\JsonApi\JsonApi: '@qp_woohoolabs_yin.json_api'
Then you can use qp_woohoolabs_yin.json_api
service by injecting it in the constructor:
namespace App\Controller; use Psr\Http\Message\ResponseInterface; use WoohooLabs\Yin\JsonApi\JsonApi; class DefaultController { /** * @var JsonApi */ private $jsonApi; public function __construct(JsonApi $jsonApi) { $this->jsonApi = $jsonApi; } public function index(): ResponseInterface { return $this->jsonApi->respond()->ok(new HelloDocument(), 'hello'); } }
Or in the action method directly:
namespace App\Controller; use Psr\Http\Message\ResponseInterface; use WoohooLabs\Yin\JsonApi\JsonApi; class DefaultController { public function index(JsonApi $jsonApi): ResponseInterface { return $jsonApi->respond()->ok(new HelloDocument(), 'hello'); } }