1. Go to this page and download the library: Download inneair/transaction-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/ */
inneair / transaction-bundle example snippets
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Inneair\TransactionBundle\InneairTransactionBundle(),
);
// ...
}
// ...
}
use Exception;
use MyCompany\MyBundle\MyException;
use Inneair\TransactionBundle\Annotation\Transactional;
/**
* @Transactional(policy=Transactional::REQUIRED, noRollbackExceptions={Exception::class, MyException::class})
*/
class AccountManager
{
// ...
}
use Exception;
use MyCompany\MyBundle\MyException;
use Inneair\TransactionBundle\Annotation\Transactional;
class AccountManager
{
/**
* @Transactional(policy=Transactional::REQUIRED, noRollbackExceptions={Exception::class, MyException::class})
*/
public function createAccount(Account $account)
{
// ...
}
}
namespace Inneair\Demo\Model;
class Company
{
/**
* ID of the company.
* @var integer
*/
private $id;
/**
* Name of the company.
* @var string
*/
private $name;
// Let's imagine there are a getter/setter for all properties.
// ...
}
namespace Inneair\Demo\Model;
class Person
{
/**
* ID of the person.
* @var integer
*/
private $id;
/**
* First name of the person.
* @var string
*/
private $firstName;
/**
* The company the person belongs to.
* @var Company
*/
private $company;
// Let's imagine there are a getter/setter for all properties.
// ...
}
namespace Inneair\Demo\Service;
use Inneair\TransactionBundle\Annotation\Transactional;
class CompanyManager implements CompanyManagerInterface
{
/**
* Adds a company.
*
* @param Company $company The company.
* @return Company The new company.
* @throws BusinessException If an existing company has already the same name.
* @Transactional
*/
public function addCompany(Company $company)
{
// Check there is not another company with the same name in the repository, or throw a business exception!
// -> probably a request to the persistence layer...
// Insert the company in a repository.
// -> probably a request to the persistence layer...
return $company;
}
}
namespace Inneair\Demo\Service;
use Inneair\TransactionBundle\Annotation\Transactional;
class PersonManager implements PersonManagerInterface
{
/**
* Company manager.
* @var CompanyManagerInterface
*/
private $companyManager;
/**
* Adds a person.
*
* @param Person $person The person.
* @return Person The new person.
* @Transactional
*/
public function addPerson(Person $person)
{
// Add the company.
$person->setCompany($this->companyManager->addCompany($person->getCompany()));
// Insert the person in a repository
// -> probably a request to the persistence layer...
return $person;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.