| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
Runtime requirements:
Database behavior:
composer require maatify/persistenceuse Maatify\Persistence\Pdo\Ordering\ScopedOrderingConfig;
use Maatify\Persistence\Pdo\Ordering\ScopedOrderingManager;
// 1. Configure the ordering behavior for a table
$config = new ScopedOrderingConfig(
table: 'maa_shipping_rates',
scopeColumn: 'method_id', // Use null for global ordering
idColumn: 'id',
orderColumn: 'display_order',
deletedAtColumn: 'deleted_at', // Use null if soft-deletes are not used
);
$ordering = new ScopedOrderingManager();
// 2. Get the next position for a new insert
$nextPosition = $ordering->getNextPosition(
pdo: $pdo,
config: $config,
scopeValue: 2, // Use null for global ordering
);
// 3. Move an existing row within its scope
$success = $ordering->moveWithinScope(
pdo: $pdo,
config: $config,
scopeValue: 2, // Use null for global ordering
id: 15,
newOrder: 4,
);use Maatify\Persistence\Pdo\Pagination\PaginationConfig;
use Maatify\Persistence\Pdo\Pagination\PageRequest;
use Maatify\Persistence\Pdo\Pagination\PdoPaginationQueryDescriptor;
use Maatify\Persistence\Pdo\Pagination\PdoPaginator;
use Maatify\Persistence\Pdo\Pagination\SortWhitelist;
use Maatify\Persistence\Pdo\Pagination\SortDirectionEnum;
$config = new PaginationConfig(
defaultPerPage: 10,
maxPerPage: 100,
minPerPage: 1,
sortWhitelist: new SortWhitelist([
'id' => 'id',
'created' => 'created_at',
'name' => 'user_name',
]),
defaultSortBy: 'created',
defaultSortDirection: SortDirectionEnum::DESC,
tieBreakerSortBy: 'id',
tieBreakerDirection: SortDirectionEnum::DESC
);
$query = new PdoPaginationQueryDescriptor(
totalSql: 'SELECT COUNT(*) FROM users',
totalParams: [],
filteredCountSql: 'SELECT COUNT(*) FROM users WHERE status = :status',
filteredCountParams: ['status' => 'active'],
dataSql: 'SELECT id, user_name, created_at FROM users WHERE status = :status',
dataParams: ['status' => 'active']
);
$request = new PageRequest(page: 2, perPage: 15, sortBy: 'name', sortDirection: 'ASC');
$paginator = new PdoPaginator();
$result = $paginator->paginate(
pdo: $pdo,
query: $query,
request: $request,
config: $config,
mapper: fn(array $row) => (object) $row
);The package currently provides the following public classes for PDO ordering and pagination:
Maatify\Persistence\Pdo\Ordering\ScopedOrderingConfig;
Maatify\Persistence\Pdo\Ordering\ScopedOrderingManager;
Maatify\Persistence\Pdo\Pagination\PageRequest;
Maatify\Persistence\Pdo\Pagination\SortDirectionEnum;
Maatify\Persistence\Pdo\Pagination\SortWhitelist;
Maatify\Persistence\Pdo\Pagination\PaginationConfig;
Maatify\Persistence\Pdo\Pagination\PdoPaginationQueryDescriptor;
Maatify\Persistence\Pdo\Pagination\PageResult;
Maatify\Persistence\Pdo\Pagination\PdoPaginator;
// Exceptions
Maatify\Persistence\Exception\PersistenceException;
Maatify\Persistence\Exception\InvalidOrderingConfigurationException;
Maatify\Persistence\Exception\InvalidOrderingOperationException;
Maatify\Persistence\Exception\OrderingTransactionException;
Maatify\Persistence\Exception\InvalidPaginationConfigurationException;
Maatify\Persistence\Exception\InvalidPaginationQueryException;
Maatify\Persistence\Exception\PaginationExecutionException;getNextPosition():
moveWithinScope():
rowExistsInScope():
PDO Pagination:
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.
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.
For a comprehensive guide, please refer to the main technical reference:
Other important documentation:
Integration testing:
composer validate --strict
composer analyse
composer test:unit
composer test:regression
vendor/bin/php-cs-fixer fix --dry-run --diffcomposer 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:
This project is licensed under the MIT License - see the LICENSE file for details.
Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect
https://www.maatify.dev
| Back | FazBrowse Home | New Git URL |