Download the PHP package maatify/persistence without Composer

On this page you can find all versions of the php package maatify/persistence. 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 persistence

# Maatify Persistence ![Maatify.dev](https://www.maatify.dev/assets/img/img/maatify_logo_white.svg) **Package status:**
[![Latest Version](https://img.shields.io/packagist/v/maatify/persistence.svg)](https://packagist.org/packages/maatify/persistence) [![PHP Version](https://img.shields.io/packagist/php-v/maatify/persistence.svg)](https://packagist.org/packages/maatify/persistence) [![License: MIT](https://img.shields.io/packagist/l/maatify/persistence.svg)](LICENSE) [![PHPStan: Level Max](https://img.shields.io/badge/PHPStan-level%20max-brightgreen.svg)](phpstan.neon) **Documentation:**
[![Changelog](https://img.shields.io/badge/Changelog-View-blue.svg)](CHANGELOG.md) [![Package Reference](https://img.shields.io/badge/Reference-Read-blue.svg)](PERSISTENCE_PACKAGE_REFERENCE.md) [![Security Policy](https://img.shields.io/badge/Security-Policy-blue.svg)](SECURITY.md) [![Contributing Guide](https://img.shields.io/badge/Contributing-Guide-blue.svg)](CONTRIBUTING.md) **Ecosystem and usage:**
[![Monthly Downloads](https://img.shields.io/packagist/dm/maatify/persistence)](https://packagist.org/packages/maatify/persistence) [![Total Downloads](https://img.shields.io/packagist/dt/maatify/persistence)](https://packagist.org/packages/maatify/persistence) [![Maatify Ecosystem](https://img.shields.io/badge/Maatify-Ecosystem-blueviolet)](https://github.com/Maatify) [![Install](https://img.shields.io/badge/Install-composer%20require%20maatify%2Fpersistence-blue)](https://packagist.org/packages/maatify/persistence) *Standalone, framework-agnostic PDO utilities for Maatify projects, providing robust scoped and global ordering, composable transaction support, and pagination tools. Designed and verified for MySQL environments.* > **Note:** PDO Pagination is available starting with v1.1.0. > > **Released vs Unreleased:** `composer require maatify/persistence` installs the > latest tagged release, `v1.4.0`. Everything marked *Unreleased* in this README > exists on `main` only and is **not** in `v1.4.0`; no later version number has > been assigned. See [Availability](#-availability-v140-vs-unreleased).

๐Ÿš€ Key Features

โš™๏ธ Requirements

Runtime requirements:

Database behavior:

๐Ÿ“ฆ Installation

๐Ÿงญ Availability: v1.4.0 vs Unreleased

API availability (does the symbol exist in the tagged release?):

Capability Status
ScopedOrderingConfig, ScopedOrderingManager::getNextPosition(), moveWithinScope(), rowExistsInScope() Released in v1.4.0
PdoTransactionRunner, PdoSavepointTransactionRunner, TransactionRunnerInterface, SavepointTransactionRunnerInterface, TransactionExecutionException Released in v1.4.0
PDO Pagination Released (since v1.1.0)
ScopedOrderingManager::getNextPositionForUpdate() Unreleased
PdoDeadlockRetryTransactionRunner, PdoDeadlockRetrySavepointTransactionRunner, InvalidTransactionConfigurationException Unreleased
Deprecation of PdoTransactionRunner and PdoSavepointTransactionRunner Unreleased (not deprecated in v1.4.0)

Behavior changes of an API that already exists in v1.4.0 (the symbol and its signature are released; the behavior below is on main only):

Behavior of moveWithinScope() v1.4.0 main (Unreleased)
Stale-snapshot clamp in a caller-owned REPEATABLE READ transaction (Issue #33) Clamps against a separate non-locking maximum Clamps against the maximum of the rows its locking read returns
Failure in a caller-owned transaction (Issue #55, ADR 0005): range shift or target write throws, or the target write changes no row (false) If shifts had already been executed and the caller's transaction survives (not aborted by the server), they stay in it and a later commit() persists them. No such partial work exists when the call fails before the first shift Throwing path: its own shifts are undone with an operation-local savepoint (best effort, when the transaction is still alive) and the original exception is rethrown. false path: the undo must succeed, then false is returned (no exception); if the undo fails, that failure is thrown instead of false. If the undo fails on the throwing path, the shifts stay and the original exception still wins
Exceptions in a caller-owned transaction (Issue #55) The method itself raised no TransactionExecutionException from savepoint control statements (it issued none) Can throw TransactionExecutionException (a class that exists in v1.4.0) when its own savepoint control statement fails, the dead-transaction guard fires, or an undo/RELEASE fails as described above
Extra statements in a caller-owned transaction (Issue #55) None A mutating move that succeeds adds exactly SAVEPOINT and RELEASE SAVEPOINT. After a failure inside the savepointed window, cleanup runs ROLLBACK TO SAVEPOINT and then attempts RELEASE SAVEPOINT (not promised when the driver reports no active transaction or a cleanup statement fails). A no-op, a missing row, an invalid argument or a failing SAVEPOINT add no ROLLBACK TO or RELEASE

The two tables answer different questions. A method listed as Released in the first table can still behave differently from main when it appears in the second table, and the guides and examples describe main. Without an active transaction (the package-owned path), moveWithinScope() behaves as in v1.4.0 with respect to the Issue #55 change.

One engine caveat applies to the released API too: on MariaDB with innodb_snapshot_isolation=ON, a caller-owned moveWithinScope() in v1.4.0 can raise 1020 and lose the caller's whole transaction. See Ordering Guarantees on MariaDB.

Unreleased means merged to main but not tagged. A class that exists on main cannot be installed with composer require maatify/persistence until a release that contains it is tagged.

โšก Quick Usage

This example uses only APIs that exist in the released v1.4.0. It manages the transaction with plain PDO calls; v1.4.0 also ships the PdoTransactionRunner / PdoSavepointTransactionRunner classes (listed in Public Runtime API), and the Unreleased replacements are shown further below.

This is error propagation in a transaction you own, not a retry: the block attempts a best-effort rollback and rethrows the original exception unchanged, so a PDOException with driver code 1213 reaches your caller intact. The rollback itself is not guaranteed (for example, a dead connection can make it fail; the server then discards the transaction when the session ends). Re-running the whole unit of work after 1213 is a separate, deliberate decision of the code that owns the transaction (see Deadlock 1213 Is Fatal); the package's own opt-in replay is Unreleased.

Ordering index requirement. moveWithinScope() is not compatible with a UNIQUE (scope, order) index on the ordering columns: it shifts the rows between the old and the new position with a single UPDATE per direction, and the unique check runs row by row, so ordinary moves fail with duplicate-key error 1062 (only no-op moves and some moves over gaps succeed). A UNIQUE index is still a valid safety net for allocation inserts, but do not add it to a table whose rows you move with this method. See Unique Indexes and moveWithinScope().

Unreleased: next-position allocation and the deadlock-retry runner

Unreleased. The classes and method below are on main only and are not part of v1.4.0.

Inside a PDO transaction, getNextPositionForUpdate() reads the latest committed maximum with a locking read, which avoids the stale-snapshot duplicate positions that the plain read can produce under REPEATABLE READ:

On MariaDB with innodb_snapshot_isolation=ON this call can raise 1020 when your transaction's snapshot is older than a concurrent commit. The server has then already rolled back the whole transaction: let the exception reach the code that owns it and restart the unit of work; never catch it and keep writing. See Ordering Guarantees on MariaDB.

Composing PDO Mutations in One Transaction

Use the transaction runner when several mutations must commit or roll back together. Every participant must use the same PDO connection. When the runner starts the transaction (no transaction is active), a failure rolls back every mutation in the callback. The released v1.4.0 class for this is PdoTransactionRunner; the example below uses the Unreleased PdoDeadlockRetryTransactionRunner, which behaves the same at its default configuration:

Who rolls back: owned vs caller-owned transactions

TransactionRunnerInterface exposes only run(callable $callback), so a consumer service can depend on the shared transaction abstraction without knowing about PDO. The released v1.4.0 provides two PDO implementations with different behavior (PdoTransactionRunner and PdoSavepointTransactionRunner); neither replaces the other. The Unreleased generation below keeps the same two behaviors and adds optional deadlock replay.

Unreleased: PdoDeadlockRetryTransactionRunner

Unreleased: PdoDeadlockRetrySavepointTransactionRunner

โš ๏ธ Deadlock 1213 Is Fatal to the Surrounding Transaction

When MySQL/InnoDB reports a deadlock (PDOException, SQLSTATE 40001, driver code 1213) it has already rolled back the entire transaction of the victim on the server. This holds for a caller-owned transaction too, including the work the caller did before it called the runner, and a savepoint does not help: the savepoint disappears with the transaction.

Evidence (MySQL 8.4.10 and MariaDB 11.8.9 only): Issue #46 study sources on PR #45.

Optional deadlock replay

Both constructors take int $maxDeadlockRetries = 0 (allowed range 0 to 3). With the default 0 nothing is replayed. With a positive value, a transaction the runner owns is replayed from a fresh BEGIN when its callback fails with a MySQL deadlock (PDOException, SQLSTATE 40001, driver code 1213): immediately the first time, then after a random wait of 0-10 ms and 0-20 ms. After the last attempt the original final PDOException is rethrown.

The whole callback runs again on every replay. Keep effects that a ROLLBACK cannot undo (e-mails, HTTP calls, queues, files, other connections) outside the callback, after run() returns, or make them idempotent. Never begin, commit, or roll back the runner-owned transaction inside the callback (PDO methods or SQL), and never end it through an implicit commit (DDL, or session/autocommit changes). Keeping that transaction intact is a mandatory precondition of replay: callbacks that end or replace it are outside the supported contract and get no transaction-identity guarantee. A transaction the callback already ended is not replayed when the connection is outside a transaction at the deadlock; if the callback ended it and started another transaction that then deadlocks, the runner cannot tell and would replay (see the Package Reference).

Nothing else is retried: not lock wait timeouts (1205) or other errors, not BEGIN/COMMIT failures, and never a caller-owned transaction or savepoint (a deadlock has already rolled the whole caller transaction back; the caller decides). A BEGIN or COMMIT that fails without throwing (PDO returns false) raises TransactionExecutionException: the callback never runs without the transaction, and an uncommitted result is never returned. The value 3 matches the configuration measured in the Issue #32 study, which covers one synchronized 8-connection workload, not every load. This capability is Unreleased and not part of the stable v1.4.0.

PdoTransactionRunner and PdoSavepointTransactionRunner are deprecated on main (Unreleased deprecation; they are not deprecated in v1.4.0) but remain public and behavior-compatible in 1.x; see the compatibility inventory.

For the detailed behavioral contract and runner selection guidance, see the PDO Transaction Architecture.

PDO Pagination

๐Ÿงฉ Public Runtime API

The released v1.4.0 provides the following public classes for PDO ordering, transactions, and pagination:

Unreleased (on main, not in v1.4.0): ScopedOrderingManager::getNextPositionForUpdate(), and the classes below.

PdoTransactionRunner and PdoSavepointTransactionRunner remain public and autoloadable for backward compatibility with 1.x consumers. On main they are deprecated in favor of PdoDeadlockRetryTransactionRunner and PdoDeadlockRetrySavepointTransactionRunner (Unreleased).

OrderingTransactionException remains public and autoloadable for backward compatibility with 1.x consumers, but is deprecated. moveWithinScope() now participates in an active caller-owned PDO transaction and no longer throws it for that condition.

โš ๏ธ Critical Runtime Behavior

Choosing between the two next-position reads (both are supported):

getNextPosition():

getNextPositionForUpdate() (Unreleased, not in v1.4.0):

Engine condition for both locking ordering calls: see Ordering Guarantees on MariaDB.

moveWithinScope():

Ordering Guarantees on MariaDB (innodb_snapshot_isolation)

Tested cells: MySQL 8.0.46 and 8.4.10; MariaDB 10.11.18, 11.4.7 and 11.8.9; REPEATABLE READ. Everything else is untested (study).

Inside a caller-owned transaction whose REPEATABLE READ snapshot is older than another connection's commit, getNextPositionForUpdate() (Unreleased) and the moveWithinScope() clamp need a current read. That is guaranteed only where the engine performs one for locking statements:

Engine / setting Result
MySQL 8.0 / 8.4 Works (tested)
MariaDB, innodb_snapshot_isolation=OFF (default on 10.11.18 and 11.4.7) Works, same as MySQL (tested)
MariaDB, innodb_snapshot_isolation=ON (default on 11.8.9) Raises the engine's PDOException, driver code 1020, unchanged

Details, propagation through the runners, and rejected package-side alternatives: Package Reference.

Unique Indexes and moveWithinScope()

moveWithinScope() shifts the rows between the current and the new position with one UPDATE ... SET order = order ยฑ 1 and then writes the target row. InnoDB checks a unique index row by row while the UPDATE runs (the check is not deferred), so a UNIQUE (scope, order) index rejects the intermediate state with duplicate-key error 1062. In the study on main, this failed for most moves (for sequential positions only no-op moves passed), inside and outside a caller-owned transaction.

PdoDeadlockRetryTransactionRunner (Unreleased):

PdoDeadlockRetrySavepointTransactionRunner (Unreleased):

rowExistsInScope():

PDO Pagination:

๐Ÿ›๏ธ Architecture Guarantees

๐Ÿ›ก๏ธ Exception and Error Propagation

All package-defined exceptions implement the marker interface Maatify\Persistence\Exception\PersistenceException. However, this interface is not a catch-all. PDOException or other external Throwables may propagate without wrapping and require a separate catch or an outer Throwable boundary if handling is needed.

๐Ÿ” Security and Trust Boundaries

The ScopedOrderingConfig validates and quotes all configured table and column identifiers. However, these identifiers must still be provided as trusted application configurations (e.g., constants), never as raw user input. All actual runtime values are safely passed using PDO prepared statements.

๐Ÿงช Examples

Five standalone, runnable scripts (they use the Unreleased getNextPositionForUpdate() and PdoDeadlockRetryTransactionRunner, so they need main, not v1.4.0) cover allocating a position and inserting a row end to end, including rollback, the REPEATABLE READ stale-snapshot case, empty scopes, and lock timeouts. They need a real MySQL test database:

See the How-to-Use guide for the list, setup, and limits. getNextPositionForUpdate() is Unreleased and is not part of the stable v1.4.0.

A separate runnable script covers moving a row (moveWithinScope()) inside a caller-owned REPEATABLE READ transaction whose snapshot is older than another connection's commit (rows 1-3 in the snapshot, rows 4-5 committed meanwhile, first row moved to position 5):

See How to Use: Moving a Row Inside an Ordered Scope. The movement fix is Unreleased and is not part of the stable v1.4.0; the allocation examples above do not exercise the movement path.

Two runnable scripts produce a real InnoDB deadlock with a second process and show the opt-in deadlock replay: an owned transaction replayed and committed once (side effect after commit runs once), and a caller-owned transaction that is never replayed:

The deadlock-retry runners are Unreleased and not part of the stable v1.4.0.

๐Ÿ“š Documentation

For a comprehensive guide, please refer to the main technical reference:

Practical guides (they document main; each marks which parts are Unreleased):

Other important documentation:

โœ… Quality Status

Integration testing:

๐Ÿ› ๏ธ Development and Testing

composer check:whitespace verifies the whole committed tree plus local changes (a bare git diff --check on a clean checkout compares nothing). composer check:residue is a read-only check for leftover package-owned MySQL test objects. composer check:lowest runs the lowest-dependencies sequence. The full CI-to-local mapping is in CONTRIBUTING.md.

composer test:integration, composer test:consumer, and composer test require a real MySQL database. SQLite is explicitly not an integration substitute. The Consumer Verification Harness creates a separate Composer root, installs this package as a non-symlinked dependency, and performs two clean runs.

Set the following environment variables for Integration tests:

For workflow syntax validation, install actionlint v1.7.12 with the checksum pinned in .github/workflows/ci.yml, then run:

The CI workflow-lint job and this local command cover every workflow under .github/workflows/.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘ค Author

Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect
https://www.maatify.dev


[Built with โค๏ธ by Maatify.dev โ€” Unified Ecosystem for Modern PHP Libraries](https://www.maatify.dev)

All versions of persistence with dependencies

PHP Build Version
Package Version
Requires ext-pdo Version *
maatify/exceptions Version ^1.0
php Version >=8.2
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 maatify/persistence contains the following files

Loading the files please wait ...