Download the PHP package orbitale/doctrine-tools without Composer
On this page you can find all versions of the php package orbitale/doctrine-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download orbitale/doctrine-tools
More information about orbitale/doctrine-tools
Files in orbitale/doctrine-tools
Package doctrine-tools
Short Description A pack of tools to use with Doctrine ORM
License MIT
Homepage https://github.com/Orbitale/DoctrineTools
Informations about the package doctrine-tools
:warning: This package is abandoned, please use Orbitale/ArrayFixture instead
Orbitale Doctrine Tools
This library is composed of multiple tools to be used with the Doctrine ORM.
Documentation
- Installation
- Usage
- Entity Repository
- Doctrine Fixtures
Installation
Simply install the library with Composer:
Usage
Entity Repository
There are 3 ways of using EntityRepositoryHelperTrait
:
-
In your own repositories, just extend the Orbitale's one:
-
If you are using Symfony, you can override the default entity manager in the configuration:
- If you are using Doctrine "natively", you can override the default entity repository class in the Doctrine Configuration class:
This way, you can use your EntityRepository exactly like before, it just adds new cool methods!
Just take a look at the EntityRepositoryHelperTrait class to see what nice features it adds!
Doctrine Fixtures
This class is used mostly when you have to create Doctrine Fixtures, and when you want the most simple way to do it.
To use it, you must install doctrine/data-fixtures
(and doctrine/doctrine-fixtures-bundle
if you are using Symfony).
Here is a small example of a new fixtures class:
Using a callable to get a reference
When you have self-referencing relationships, you may need a reference of an object that may have already been persisted.
For this, first, you should set the flushEveryXIterations
option to 1
(view below) to allow flushing on every iteration.
And next, you can set a callable
element as the value of your object so you can interact manually with the injected object
as 1st argument, and the AbstractFixture
object as 2nd argument.
The EntityManagerInterface
is also injected as 3rd argument in case you need to do some specific requests or query through another
table.
Example here:
This allows perfect synchronicity when dealing with self-referencing relations.
Methods of the AbstractFixture
class that can be overriden:
getOrder()
(default0
) to change the order in which the fixtures will be loaded.getReferencePrefix()
(defaultnull
) to add a reference in the Fixtures' batch so you can use them later. References are stored as{referencePrefix}-{id|__toString()}
.getMethodNameForReference()
(defaultgetId
) to specify which method on the object is used to specify the reference. Defaults togetId
and always falls back to__toString()
if exists.flushEveryXIterations()
(default0
) to flush in batches instead of flushing only once at the end of all fixtures persist.disableLogger()
to disable SQL queries logging, useful to save memory at runtime.
This way, 2 objects are automatically persisted in the database, and they're all identified with their ID.
Also, if you run the symfony app/console doctrine:fixtures:load
using the --append
option, the IDs will be detected
in the database and will not be inserted twice, with no error so you can really use fixtures as reference datas!
Take a look at the AbstractFixture class to see what other methods you can override!
All versions of doctrine-tools with dependencies
doctrine/orm Version ^2.6
doctrine/persistence Version ^1.3
doctrine/instantiator Version ^1.1