litgroup / event-loop-bundle
React EventLoop integration for Symfony2.
Installs: 679
Dependents: 2
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 1
Type:symfony-bundle
Requires
- php: >=5.4.0
- react/event-loop: 0.4.*
- symfony/framework-bundle: ~2.3
Requires (Dev)
- phpunit/phpunit: 4.1.*@stable
This package is not auto-updated.
Last update: 2022-02-01 12:36:25 UTC
README
🚫 (This project is no longer maintained.)
This bundle integrates react/event-loop library into the Symfony 2.
Installation
Use a Composer to install LitGroupEventLoopBundle.
"require": { "litgroup/event-loop-bundle": "1.0.x-dev" }
Do not forget to register the bundle in the AppKernel:
<?php // AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new LitGroup\Bundle\EventLoopBundle\LitGroupEventLoopBundle(), ]; // ... return $bundles; } // ... }
Configuration
No configuration needed this time.
Basic usage
Using of an event loop
Bundle provides basics loop as a service, named litgroup_event_loop
.
You can use it for injection or directly in your application.
Example:
/** @var \React\EventLoop\LoopInterface $loop */ $loop = $container->get('litgroup_event_loop'); $loop->run();
Periodic Services
Periodic service — service, defined in the dependency injection container, marked by tag litgroup_event_loop.periodic
. These services will be called periodically when loop is running.
Tag has two required attributes:
interval
— interval between calls;method
— service method to call.
Interval can be set as seconds represented by double value or as string with time units (10ms
, 1m
). Interval cannot be less then 1ms.
String representation supports four units:
ms
millisecondss
secondsm
minutesh
hours
Units cannot be mixed.
Example: 10s
, 15m
, 1.5h
Periodic service definition's example
Service class:
<?php class PeriodicService { public function tick() { echo "Tick!"; } }
DIC configuration:
<?xml version="1.0" encoding="UTF-8" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > <services> <service id="periodic_service" class="PeriodicService"> <tag name="litgroup_event_loop.periodic" interval="1s" method="tick"/> </service> </services> </container>
Now, when event loop will be running PeriodicService::tick()
will be called with period in 1 second.
License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
See details in LICENSE file.