Download the PHP package precision-soft/doctrine-utility without Composer
On this page you can find all versions of the php package precision-soft/doctrine-utility. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download precision-soft/doctrine-utility
More information about precision-soft/doctrine-utility
Files in precision-soft/doctrine-utility
Package doctrine-utility
Short Description doctrine utilities library
License MIT
Homepage https://github.com/precision-soft/doctrine-utility
Informations about the package doctrine-utility
Doctrine Utility
Doctrine custom types, functions, and services for MySQL.
You may fork and modify it as you wish.
Any suggestions are welcomed.
Requirements
- PHP 8.2+
- Doctrine ORM 3
- Doctrine DBAL 4
- MySQL (all features — DQL functions, MySqlWalker, and MysqlLockService — require MySQL)
Installation
Usage for AbstractRepository and DoctrineRepository
The purposes for these classes are:
- easier constructor injection for the repositories; the quotes are because these repositories are actual read services in CRUD methodology
- code reuse by using custom filters and join filters
- better find usages for methods because you are forced to implement only what you need
Product.php
ProductRepository.php
Empty array filter behavior
When attachGenericFilters() receives an empty array as a filter value (e.g. ['ids' => []]), it cannot generate a valid IN () clause. The default behavior is EmptyArrayFilterBehavior::MatchNone, which appends an always-false marker condition ('<filterName>' = '<filterName>-emptyFilter') so the query returns zero rows and the offending filter is grep-able in query logs.
To turn empty array filters into hard errors, override getFlags():
getFlags() is the generic configuration hook for repository behavior — every flag is an enum keyed by its class, so future flags only require a new enum (no new method on AbstractRepository).
Logger
Repositories can expose a Psr\Log\LoggerInterface so the abstract repository can warn on observable but non-fatal conditions (e.g. an empty array filter falling back to MatchNone):
By default getLogger() returns null and no logging happens. When provided, warnings include repository, filter, and hint context fields for filtering and remediation.
DQL Functions
This library provides MySQL-specific DQL functions. Register them in your Doctrine configuration:
Available functions:
| Function | DQL Usage | Description |
|---|---|---|
JSON_CONTAINS |
JSON_CONTAINS(field, value [, path]) |
Test whether a JSON document contains a specific value |
JSON_CONTAINS_PATH |
JSON_CONTAINS_PATH(field, 'one'/'all', path [, ...]) |
Test whether a JSON document contains data at one or more paths |
JSON_EXTRACT |
JSON_EXTRACT(field, path [, ...]) |
Extract data from a JSON document |
JSON_SEARCH |
JSON_SEARCH(field, 'one'/'all', search [, escape, path...]) |
Search for a string in a JSON document |
JSON_UNQUOTE |
JSON_UNQUOTE(value) |
Unquote a JSON value |
DATE_FORMAT |
DATE_FORMAT(date, format) |
Format a date |
MysqlLockService
A service for MySQL named locks (advisory locks) via GET_LOCK() / RELEASE_LOCK().
Lock names longer than 64 characters are automatically hashed to fit MySQL's limit. Locks are reference-counted: calling acquire() multiple times with the same name increments a counter, and release() decrements it, only actually releasing the MySQL lock when the count reaches zero.
All errors throw MysqlLockException.
MySqlWalker (USE/FORCE/IGNORE INDEX)
A custom SQL walker for controlling MySQL index hints in DQL queries.
Index names are validated against [a-zA-Z_][a-zA-Z0-9_]* pattern for safety.
Entity Traits
CreatedTrait
Adds a created column (DATETIME, defaults to CURRENT_TIMESTAMP) with getter/setter.
ModifiedTrait
Adds a modified column (DATETIME, defaults to CURRENT_TIMESTAMP) with getter/setter and an automatic #[ORM\PreUpdate] callback.
Important: The consuming entity must have the #[ORM\HasLifecycleCallbacks] attribute for the automatic update to work.
Dev
All versions of doctrine-utility with dependencies
ext-pdo Version *
doctrine/dbal Version 4.*
doctrine/orm Version 3.*
doctrine/persistence Version 3.*
psr/log Version ^2.0 || ^3.0