webstronauts / react-bundle
Bundle for getting async support in Symfony through React's promises.
Installs: 224
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^5.5|^7.0
- react/event-loop: ^0.4
- react/promise: ^2.2
- symfony/framework-bundle: ^2.7|^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.11
- scrutinizer/ocular: ^1.1
- sllh/php-cs-fixer-styleci-bridge: ^2.0
This package is not auto-updated.
Last update: 2018-10-30 14:45:35 UTC
README
This bundle is getting async support in Symfony through React's promises. When added to your kernel you can do things like this in your controller:
// src/Appbundle/Controller/DefaultController.php namespace AppBundle\Controller; use React\Promise\Deferred; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends controller { public function indexAction() { $deferred = new Deferred(); // Do some funky asynchronous programming here... $this->callAsynchronousMethod(function ($result) use ($deferred) { $deferred->resolve($result); }); return $deferred->promise(); } }
Documentation
Installation
- Add this bundle to your composer.json:
php composer.phar require webstronauts/react-bundle
- Add this bundle to your application's kernel:
// app/ApplicationKernel.php public function registerBundles() { return array( // ... new Webstronauts\Bundle\ReactBundle\WebstronautsReactBundle(), // ... ); }
- There's no step 3! This is everything you need to do to make Symfony asynchronous.
Technical notes
This bundle listens to the kernel.view
event for controller results and wraps it
in a promise so either the resolved promise or any other result is returned and
handled by Symfony as excepted. In
case of a rejected promise, the corresponding exception is thrown.
Internally it uses an event-loop instance
to add asynchronous execution of callbacks to Symfony. When any promises are unresolved,
the event-loop keeps running on the kernel.terminate
event. Keep in mind that with
an incorrect configuration of your webserver, the response is returned after the kernel
is terminated.
Tests
To run the test suite, you need install the dependencies via composer, then run PHPUnit.
composer install php vendor/bin/phpunit
License
MIT © The Webstronauts