bacart / symfony-common
Symfony common utils
Requires
- php: ^7.3
Requires (Dev)
- doctrine/doctrine-bundle: ^2.0
- doctrine/mongodb-odm-bundle: ^4.1
- doctrine/orm: ^2.7
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12
- rector/rector: ^0.6
- symfony/framework-bundle: ^5.0
- symfony/lock: ^5.0
- symfony/messenger: ^5.0
- symfony/security-core: ^5.0
- symfony/security-csrf: ^5.0
- symfony/security-http: ^5.0
- symfony/translation: ^5.0
- symfony/validator: ^5.0
Suggests
- doctrine/mongodb-odm: Doctrine MongoDB Object Document Mapper (ODM)
- doctrine/orm: Doctrine 2 Object Relational Mapper (ORM)
- friendsofphp/php-cs-fixer: A tool to automatically fix PHP Coding Standards issues
- phpstan/phpstan: PHPStan - PHP Static Analysis Tool
- rector/rector: Instant upgrade and refactoring of your PHP code
- symfony/framework-bundle: The FrameworkBundle defines the main framework configuration, from sessions and translations to forms, validation, routing and more.
- symfony/lock: Creates and manages locks, a mechanism to provide exclusive access to a shared resource.
- symfony/messenger: The Messenger component helps application send and receive messages to/from other applications or via message queues.
- dev-master / 0.3.x-dev
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.30
- v0.1.29
- v0.1.28
- v0.1.27
- v0.1.26
- v0.1.25
- v0.1.24
- v0.1.23
- v0.1.22
- v0.1.21
- v0.1.20
- v0.1.19
- v0.1.18
- v0.1.17
- v0.1.16
- v0.1.15
- v0.1.14
- v0.1.13
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2021-03-19 00:27:59 UTC
README
Allows to create lockable commands in Symfony projects. Also includes aware interfaces and traits.
Installation
Using command line:
Run the following command and you will get the latest version by Packagist.
composer require bacart/symfony-common
Using composer.json
To use the newest (maybe unstable) version add following into your composer.json:
{ "require": { "bacart/symfony-common": "dev-master" } }
Usage example
Use AbstractLockableCommand
as parent class of your command.
use Bacart\SymfonyCommon\Command\AbstractLockableCommand; class SomeCommand extends AbstractLockableCommand { ... }
From now on your command will be able to run only once a time. You can also override a getLockTtl()
method to set a lock lifetime in seconds (defaults to 60).
If your command execution is too complex and may take more than lock lifetime you can extend it with EventDispatcher
:
use Bacart\SymfonyCommon\Aware\Interfaces\EventDispatcherAwareInterface; use Bacart\SymfonyCommon\Aware\Traits\EventDispatcherAwareTrait; use Bacart\SymfonyCommon\Command\AbstractLockableCommand; class SomeService implements EventDispatcherAwareInterface { use EventDispatcherAwareTrait; public function someLongRunningMethod() { ... // extend a command lock TTL $this->dispatcher->dispatch(LockableCommandInterface::LOCKABLE_COMMAND_REFRESH_EVENT_NAME); ... } }
All the examples assume that you are using an autowiring.
License
This project is released under the MIT license.
About
Project development is led by the Bacart team.