PHP code example of php-arsenal / doctrine-odm-transactional-document-manager

1. Go to this page and download the library: Download php-arsenal/doctrine-odm-transactional-document-manager 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/ */

    

php-arsenal / doctrine-odm-transactional-document-manager example snippets




namespace YourNamespace;

use PhpArsenal\DoctrineOdmTransactionalDocumentManager\TransactionalDocumentManager;

class ProductManager
{
    public function __construct(
        private TransactionalDocumentManager $documentManager, 
        private ProductRepository $productRepository
    ) {
    }
 
    public function publishProducts(): void
    {
        $products = $this->productRepository->findBy(['published' => false]);
 
        $this->documentManager->startTransaction();
 
        foreach ($products as $product) {
            $product->setPublished(true);
        }
 
        $this->documentManager->flush([
            'session' => $this->documentManager->getSession(),
        ]);
 
        $this->documentManager->commitTransaction();
    }
}