Download the PHP package cycle/transaction without Composer

On this page you can find all versions of the php package cycle/transaction. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package transaction


CycleORM Logo

[![Build Status](https://img.shields.io/github/actions/workflow/status/cycle/transaction/testing.yml?branch=1.x&style=flat-square&label=tests)](https://github.com/cycle/transaction/actions) [![Codecov Coverage](https://img.shields.io/codecov/c/github/cycle/transaction/1.x?style=flat-square&logo=codecov)](https://app.codecov.io/gh/cycle/transaction/tree/1.x) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square&label=mutation%20score&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fcycle%2Ftransaction%2F1.x)](https://dashboard.stryker-mutator.io/reports/github.com/cycle/transaction/1.x) [![Discord](https://img.shields.io/discord/538114875570913290?style=flat-square&logo=discord&labelColor=7289d9&logoColor=white&color=39456d)](https://discord.gg/spiralphp) [![Follow on Twitter (X)](https://img.shields.io/badge/-Follow-black?style=flat-square&logo=X)](https://x.com/intent/follow?screen_name=SpiralPHP)

Transaction Abstraction for Cycle ORM

This library provides a small transaction abstraction for Cycle ORM. It opens a single database transaction and lets you run raw DBAL operations together with a scoped Entity Manager inside it.

Everything executed within the callback shares one transaction: if the callback throws, the transaction is rolled back; otherwise it is committed. The Entity Manager is scoped to a single database connection for the duration of the callback, so accidental cross-connection writes are rejected instead of silently splitting your work across transactions.


Installation

The preferred way to install this package is through Composer.

PHP Version Require Latest Stable Version Total Downloads


Usage

Obtaining a Transaction

The package ships a single implementation of the Cycle\Transaction\Transaction interface. Build it from your configured ORM and DBAL, or resolve Cycle\Transaction\Transaction from your framework's container if it is registered there.

Basic Example

The callback receives the scoped EntityManagerInterface and the DatabaseInterface of the resolved connection. Persisted entities are flushed and committed automatically when the callback returns.

If the callback throws, the whole transaction — both the Entity Manager changes and the raw DBAL operations — is rolled back.

Returning a Value

transact() returns whatever the callback returns.

Flush Modes

The FlushMode enum controls when and how the scoped Entity Manager flushes its pending changes. Pass it via the $flush argument (defaults to FlushMode::BeforeCommit).

Mode Behaviour
FlushMode::OnWrite Flush every persist/persistState/delete to the database immediately.
FlushMode::BeforeCommit Collect all changes and flush them once, right before the transaction is committed. (default)
FlushMode::FailOnPending Do not flush automatically; throw a TransactionException if any changes are still pending.
FlushMode::SkipPending Do not flush automatically; silently discard any pending changes (only DBAL operations are committed).

Transaction Modes

The TransactionMode enum controls how the Entity Manager's Unit of Work interacts with the open transaction. Pass it via the $emMode argument (defaults to TransactionMode::Current).

Mode Behaviour
TransactionMode::Current Reuse the currently opened transaction. Throws if none is open. (default)
TransactionMode::OpenNew Open a new inner transaction per driver connection and close it on finish.
TransactionMode::Ignore Do not manage transactions for the Unit of Work.
TransactionMode::Exclusive Like OpenNew, but require the transaction to be top-level. Throws if wrapped by another.

Selecting the Database

By default the transaction runs against the default database connection. Use the $source argument to pick another connection — either by its name or by an entity class mapped to it. The scoped Entity Manager then rejects entities that belong to a different connection.


All versions of transaction with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
cycle/database Version ^2.20
cycle/orm Version ^2.18
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cycle/transaction contains the following files

Loading the files please wait ...