Skip to content

Commit

Permalink
expose object lock system logic on readme doc
Browse files Browse the repository at this point in the history
  • Loading branch information
behram committed Jan 10, 2016
1 parent 373f3a9 commit 69abcc4
Showing 1 changed file with 119 additions and 3 deletions.
122 changes: 119 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# DoctrineLockBundle
Lock object against delete, update events

:warning: Under construction, in-consistent, tests incomplete, get your own risk... :sunglasses:
- Lock objects against insert, delete, update events
- Lock entities against delete, update events

### Related Links;###
- https://github.com/doctrine/doctrine2/blob/master/docs/en/reference/transactions-and-concurrency.rst#locking-support
Expand All @@ -12,3 +11,120 @@ Lock object against delete, update events

- Developing steps can be follow from https://github.com/behramcelen/symfony-bundle-develop
- An basic testing and logic command can be found in https://github.com/behramcelen/symfony-bundle-develop/blob/master/src/AppBundle/Command/LockBundleTestCommand.php#L41


Installation
============

Step 1: Download the Bundle
---------------------------

Open a command console, enter your project directory and execute the
following command to download the latest version of this bundle:

```bash
$ composer require enterprisephp/doctrine-lock-bundle "dev-master"
```

This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.

Step 2: Enable the Bundle
-------------------------

Then, enable the bundle by adding it to the list of registered bundles
in the `app/AppKernel.php` file of your project:

```php
<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...

new EP\DoctrineLockBundle\EPDoctrineLockBundle(),
);

// ...
}

// ...
}
```

Usage
============

Doctrine Object Lock
---------------------------
```php
use EP\DoctrineLockBundle\Params\ObjectLockParams;
// ...
$objectLocker = $container->get('ep.doctrine.object.locker');
//lock fully
$objectLocker->lock(new DummyEntity());
//lock delete process
$objectLocker->lock(new DummyEntity(), ObjectLockParams::DELETE_LOCK);
//lock insert process
$objectLocker->lock(new DummyEntity(), ObjectLockParams::INSERT_LOCK);
//lock update process
$objectLocker->lock(new DummyEntity(), ObjectLockParams::UPDATE_LOCK);
```
Doctrine Object UnLock
---------------------------
```php
use EP\DoctrineLockBundle\Params\ObjectLockParams;
// ...
$objectLocker = $container->get('ep.doctrine.object.locker');
//unlock full lock
$objectLocker->unlock(new DummyEntity());
//unlock delete process
$objectLocker->unlock(new DummyEntity(), ObjectLockParams::DELETE_LOCK);
//unlock insert process
$objectLocker->unlock(new DummyEntity(), ObjectLockParams::INSERT_LOCK);
//unlock update process
$objectLocker->unlock(new DummyEntity(), ObjectLockParams::UPDATE_LOCK);
```
Doctrine Object Switch Lock
---------------------------
```php
use EP\DoctrineLockBundle\Params\ObjectLockParams;
// ...
$objectLocker = $container->get('ep.doctrine.object.locker');
//switch full lock
$objectLocker->switchLock(new DummyEntity());
//switch delete process
$objectLocker->switchLock(new DummyEntity(), ObjectLockParams::DELETE_LOCK);
//switch insert process
$objectLocker->switchLock(new DummyEntity(), ObjectLockParams::INSERT_LOCK);
//unswitchlock update process
$objectLocker->switchLock(new DummyEntity(), ObjectLockParams::UPDATE_LOCK);
```
Doctrine Object Is Locked
---------------------------
```php
use EP\DoctrineLockBundle\Params\ObjectLockParams;
// ...
$objectLocker = $container->get('ep.doctrine.object.locker');
//is full locked
$objectLocker->isLocked(new DummyEntity());
//is delete locked
$objectLocker->isLocked(new DummyEntity(), ObjectLockParams::DELETE_LOCK);
//is insert locked
$objectLocker->isLocked(new DummyEntity(), ObjectLockParams::INSERT_LOCK);
//is update locked
$objectLocker->isLocked(new DummyEntity(), ObjectLockParams::UPDATE_LOCK);
```
### Example Use ###
```php
$objectLocker = $container->get('ep.doctrine.object.locker');
//lock object
$objectLocker->lock(new DummyEntity());
$em->persist(new DummyEntity()); //this will throw LockedObjectException
```

0 comments on commit 69abcc4

Please sign in to comment.