*/ class mpDomainFacade { /** * Adds a new product for the given name. * * @param string $productName * @throws mpDomainException */ public function addProduct( $productName ) { // Create a new product $product = new mpProduct( $productName ); // Get the product catalog $catalog = mpProductCatalog::getInstance(); // Create a new transaction $transaction = $catalog->createTransaction( $product ); try { // Start transaction $transaction->begin(); // Add new product to catalog $catalog->addProduct( $product ); // Commit product transaction $transaction->commit(); } catch ( mpProductInTransactionException $e ) { throw new mpDomainException( "Transaction Error", $e->getMessage() ); } catch ( mpProductExistsException $e ) { try { // Rollback product transaction $transaction->rollback(); // Show error message throw new mpDomainException( "Name Error", $e->getMessage() ); } catch ( mpProductTransactionNotOpenException $e ) { // Show error message throw new mpDomainException( "Transaction Error", $e->getMessage() ); } } } } /** * Exception * * @author Manuel Pichler */ class mpDomainException extends RuntimeException { /** * The exception title. * * @type string * @var string $title */ private $title = ""; /** * The exception ctor. * * @param string $title * @param string $message */ public function __construct( $title, $message ) { parent::__construct( $message ); $this->title = $title; } /** * Returns the exception title. * * @return string */ public function getTitle() { return $this->title; } }