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.
Download maatify/persistence
More information about maatify/persistence
Files in maatify/persistence
Package persistence
Short Description Standalone, framework-agnostic PDO ordering and pagination utilities for Maatify projects.
License MIT
Homepage https://github.com/Maatify/persistence
Informations about the package persistence
[](https://packagist.org/packages/maatify/persistence) [](https://packagist.org/packages/maatify/persistence) [](LICENSE) [](phpstan.neon) **Documentation:**
[](CHANGELOG.md) [](PERSISTENCE_PACKAGE_REFERENCE.md) [](SECURITY.md) [](CONTRIBUTING.md) **Ecosystem and usage:**
[](https://packagist.org/packages/maatify/persistence) [](https://packagist.org/packages/maatify/persistence) [](https://github.com/Maatify) [](https://packagist.org/packages/maatify/persistence) *Standalone, framework-agnostic PDO utilities for Maatify projects, providing robust scoped and global ordering, and pagination tools. Designed and verified for MySQL environments.* > **Note:** PDO Pagination is available starting with v1.1.0.
🚀 Key Features
- Global and Scoped Ordering: Easily manage display order across an entire table or within a specific scope.
- Transaction Ownership: Handles its own transactions and locks the necessary scope reliably.
- SQL Identifier Validation: Ensures table and column configurations are safe and properly quoted.
- Soft-Delete Filtering: Optional support for ignoring soft-deleted rows in ordering calculations.
- Scope Isolation: Ensures only the affected range within the configured scope is updated.
- PDO Pagination: Deterministic offset pagination with strict normalization, bounds checking, and safe whitelist-based sorting.
⚙️ Requirements
Runtime requirements:
- PHP
>= 8.2 ext-pdomaatify/exceptions ^1.0
Database behavior:
- The package behavior is designed and verified against MySQL.
📦 Installation
⚡ Quick Usage
PDO Pagination
🧩 Public Runtime API
The package currently provides the following public classes for PDO ordering and pagination:
⚠️ Critical Runtime Behavior
getNextPosition():
- Does not start a transaction.
- Does not lock the applicable scope.
- For concurrent inserts, the host application must provide the transaction and locking mechanism required to serialize position allocation.
moveWithinScope():
- Rejects inconsistent scope usage.
- Rejects
id <= 0. - Rejects
newOrder <= 0. - Rejects caller-owned active PDO transactions.
- Owns its own transaction.
- Locks the applicable active scope using
SELECT ... FOR UPDATE. - Reads the current order from the database within the same transaction.
- Does not trust a current order provided by the caller.
- Returns
falseif the target row is missing. - Clamps values higher than the maximum position to the maximum available position.
- Returns
trueif the movement is a no-op (already at the requested position). - Moves only the affected range.
- Does not globally normalize pre-existing gaps.
- Rolls back and returns
falseif the final target update fails. - Rolls back on any Throwable after starting the transaction.
- Rethrows the original Throwable without arbitrary wrapping.
rowExistsInScope():
- Returns
falseforid <= 0. - Returns
falseif the row is not found within the configured scope. - Treats soft-deleted rows as non-existent if
deletedAtColumnis configured. - Throws
InvalidOrderingOperationExceptionon invalid scope usage. - External PDO errors propagate unmodified.
PDO Pagination:
- Normalizes page and per-page limits strictly.
- Uses safe whitelist-based sorting.
- Host application owns SQL, scopes, mapping, and filters.
- Package handles count queries and offset calculation.
- Does not alter or require active PDO transactions.
🏛️ Architecture Guarantees
- Standalone Composer package.
- Framework-agnostic.
- Host-agnostic.
- PDO-based.
- No ORM.
- No framework bindings.
- No HTTP endpoints, UI, controllers, or routes.
- No host table ownership.
- No generic application repository abstraction.
- The host provides the PDO connection.
- Trusted SQL identifiers.
- Runtime values use prepared statements.
🛡️ 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.
📚 Documentation
For a comprehensive guide, please refer to the main technical reference:
- Persistence Package Reference
Other important documentation:
- Changelog
- Security Policy
- Contributing Guide
- Code of Conduct
- Architecture Decision Records
- Package Building Standard
- CI Workflow Standard
- Library Presentation Standard
✅ Quality Status
- PHP 8.2–8.5 verification in CI.
- PHPStan Level Max.
- Unit, Regression, and MySQL Integration tests.
- Lowest dependencies verification.
- Stable CI Gate.
Integration testing:
- Real MySQL is required for Integration tests.
- SQLite is not an Integration substitute.
- MySQL
8.4.10is the currently verified CI baseline.
🛠️ Development and Testing
composer test:integration and composer test require a real MySQL database. SQLite is explicitly not an integration substitute.
Set the following environment variables for Integration tests:
PERSISTENCE_TEST_MYSQL_DSNPERSISTENCE_TEST_MYSQL_USERPERSISTENCE_TEST_MYSQL_PASSWORD
📄 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