Download the PHP package anh/doctrine-extensions-resource without Composer
On this page you can find all versions of the php package anh/doctrine-extensions-resource. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package doctrine-extensions-resource
Doctrine2 resource extension
Extension provides simplified and unified interface for working with resources.
Installation
Symfony integration
There is a bundle or package for that.
Usage
Defining resources
Resource definition is an array with required and optional keys.
Initialization
You should configure object manager to use ResourceRepositoryFactory
as repository factory in order to inject paginator and rule resolver services into repositories. Extension can use any paginator compatible with ResourcePaginatorInterface
.
Create entity manager, event dispatcher, add event subscriber and create ResourceManagerFactory
.
CRUD operations with ResourceManager
.
Each resource type has it's own resource manager, to instantiate it you should use ResourceManagerFactory::create()
.
Events
Code above will generate this events:
- anh_resource.article.pre_create
- anh_resource.article.post_create
- anh_resource.article.pre_update
- anh_resource.article.post_update
- anh_resource.article.pre_delete
- anh_resource.article.post_delete
Fetching resources with ResourceRepository
.
ResourceRepository
has two methods for fetching resources: paginate()
and fetch()
.
See orm-example.php.
Advanced criteria format
You can use advanced criteria format for filtering. It's not limited to equal comparison only. For example:
Advanced comparison
If the field name starts with %
then advanced format for field should follow. It consists of the array with a single element, where key is the comparison operator and value is parameter for operator. Common operators are: >
, <
, >=
, <=
, <>
and others, for full list refer to QueryBuilderAdapter
of each driver.
Comparison types
Symbol #
with following and
or or
is used for changing comparison type. Comparison types can be nested.
Multiple criteria on the same field
If you need a few criteria for the same field, simply add a dash followed by a number. Apply the same for the comparison types.
Rules
Rule is predefined group of criteria for resource. You can define it in resource definition (key rules
). When rule is defined you can use its name in square brackets as criterion for ResourceRepository::paginate()
and ResourceRepository::fetch()
methods.
Auto joins
Query builder adds inner join automatically... (to be written)
This advanced criteria format is valid for all available drivers (ORM, PHPCR-ODM, MongoDB-ODM).
Note
Not all operators are available for each driver.
Credits
Inspired by SyliusResourceBundle from Sylius.
Versioning
Library uses semantic versioning.
License
MIT