PHP code example of axsy / transactional-bundle

1. Go to this page and download the library: Download axsy/transactional-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

axsy / transactional-bundle example snippets


use Axsy\TransactionalBundle\Annotation\Transactionable;

// Acme/SomeBundle/Controllers/SomeController.php
class SomeController extends Controller
{
    /**
     * @Transactionable
     */
    public function performRollbackOnExceptionAction()
    {
        // Persist some changes to the database using Doctrine DBAL or Doctrine ORM, whatever
        // ...
        // ...

        // Throw an exceptions
        // All changes performed upper will be rolled back
        throw new \RuntimeException();
    }
}

use Axsy\TransactionalBundle\Annotation\Transactionable;

// Acme/SomeBundle/SomeService.php
class SomeService
{
    /**
     * @Transactionable
     */
    public function performRollbackOnException()
    {
        // ...
    }

    // ...
    // ...
}

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Axsy\TransactionalBundle\AxsyTransactionalBundle(),
    // ...
);


use Axsy\TransactionalBundle\Annotation\Transactionable;

// Acme/SomeBundle/SomeService.php
class SomeService
{
    /**
     * Transactionable(connection="other", isolation="read_uncommitted")
     */
    public function performRollbackOnException()
    {
        // ...
    }
}

use Axsy\TransactionalBundle\Annotation\Transactionable;

// Acme/SomeBundle/Controllers/SomeController.php
class SomeController extends Controller
{
    /**
     * @Transactionable(noRollbackFor={"Symfony\Component\HttpKernel\Exception\NotFoundHttpException"})
     */
    public function performCommitOnNotFoundHttpExceptionAction()
    {
        // ...
    }
}

use Axsy\TransactionalBundle\Annotation\Transactionable;

// Acme/SomeBundle/SomeService.php
class SomeService
{
    /**
     * @Transactionable(rollbackFor={"Acme\SomeBundle\Exceptions\VeryBadException"})
     */
    public function performRollbackOnVeryBadExceptionOnly()
    {
        // ...
    }
}

use Axsy\TransactionalBundle\Annotation\Transactionable;

// Acme/SomeBundle/Controllers/SomeController.php
/**
 * @Transactionable(noRollbackFor={"Symfony\Component\HttpKernel\Exception\NotFoundHttpException"})
 */
class SomeController extends Controller
{
    public function performCommitOnNotFoundHttpExceptionAction()
    {
        // ...
    }

    public function thisTooAction()
    {
        // ...
    }
}

use Axsy\TransactionalBundle\Annotation\Transactionable;

// Acme/SomeBundle/SomeService.php
/**
 * @Transactionable(rollbackFor={"Acme\SomeBundle\Exceptions\VeryBadException"})
 */
class SomeService
{
    public function performRollbackOnVeryBadExceptionOnlyOnDefaultConnection()
    {
        // ...
    }

    /**
     * @Transactionable(connection="other")
     */
    public function performRollbackOnVeryBadExceptionOnlyOnOtherConnection()
    {
        // ...
    }
}
bash
php composer.phar update