Doctrine ORM Service Provider for Silex
This extension sets up Doctrine ORM for Silex by reusing the database connection established with the DBAL extension (the default DoctrineServiceProvider included with Silex)., (*1)
You'll find the following topics in this README:
* Dependencies
* Installation
* Configuration
* Usage, (*2)
Dependencies
Installation
You basically have three options to add this extension to your Silex project. We'd strongly recommend the first option!, (*3)
composer.json
http://packagist.org/packages/fredjuvaux/silex-orm-provider, (*4)
Add to the dependencies in your projects composer.json file:, (*5)
"fredjuvaux/doctrine-orm-provider": "1.0.*@dev"
And update your dependencies:, (*6)
php composer.phar update
This is by far the easiest way, since it automatically adds the Doctrine dependencies and adds everything to the autoloading mechanism supplied by Composer., (*7)
More information on Composer can be found on getcomposer.org., (*8)
Git
Another option is to clone the project:, (*9)
cd /path/to/your_project/vendor
git clone git@github.com:fredjuvaux/silex-orm-provider.git
Or you can add it as a submodule if your project is in a git repository too:, (*10)
cd /path/to/your_project
git submodule add git@github.com:fredjuvaux/silex-orm-provider.git vendor/silex-orm-extension
This will require you to manually install all the dependencies. Also note that you'll need to add the provider to the Silex autoloader (or whatever autoloading mechanism) by hand. More on both subjects can be found below., (*11)
Download an archive
GitHub also gives you the option to download an ZIP-archive, which you can extract in your vendor folder. This method will also require you to manually install all the dependencies and add everything to your autoloader., (*12)
Configuration
First of all you should have the Doctrine DBAL connection configured. For more information about configuring the DoctrineServiceProvider, I'd recommend reading this page of the Silex documentation., (*13)
Registering the Doctrine ORM Service Provider is rather straight forward:, (*14)
<?php
/* ... */
$app['autoloader']->registerNamespace('ORM', __DIR__ . '/vendor/silex-orm-extension/lib');
$app->register(new ORM\Provider\DoctrineORMServiceProvider(), array(
'db.orm.class_path' => __DIR__.'/../vendor/doctrine/orm/lib',
'db.orm.proxies_dir' => __DIR__.'/../var/cache/doctrine/Proxy',
'db.orm.proxies_namespace' => 'DoctrineProxy',
'db.orm.auto_generate_proxies' => true,
'db.orm.entities' => array(array(
'type' => 'annotation',
'path' => __DIR__.'/Entity',
'namespace' => 'Entity',
)),
));
/* ... */
Note: If you don't want to use the internal autoloader of Silex (because you're using another one, like the one generated by composer for example), you can leave out the line starting with $app['autoloader']
and the db.orm.class_path parameter., (*15)
Parameters (and their default values)
Below you'll find all the parameters with their defaults (they can also be found in DoctrineORMServiceProvider::setOrmDefaults)., (*16)
-
db.orm.auto_generated_proxies, (*17)
Default: true
, (*18)
Sets whether proxy classes should be generated automatically at runtime by Doctrine.
If set to false
, proxy classes must be generated manually using the Doctrine command line tools.
It is recommended to disable autogeneration for a production environment., (*19)
-
db.orm.cache, (*20)
Default: new ArrayCache
, (*21)
Defines what caching method should be used. The default (ArrayCache) should be fine when you're developing, but in a production environment you probably want to change this to something like APC or Memcache.
More information can be found in Chapter 22. Caching of the Doctrine 2 ORM 2.1 documentation., (*22)
-
db.orm.class_path, (*23)
You only need to use this if you want to autoload the Doctrine 2 ORM classes using the Silex autoloader.
It should point to the folder where the classes is stored (the lib folder on the Doctrine repository)., (*24)
-
db.orm.entities, (*25)
Default:, (*26)
array(
array(
'type' => 'annotation',
'path' => 'Entity',
'namespace' => 'Entity',
)
)
An array of arrays which should contain:
* ``type``: Type of metadata driver used (``annotation``, ``yml``, ``xml``)
* ``path``: Path to where the metadata is stored
* ``namespace``: Namespace used for the entities
The Doctrine ORM Service Provider uses a _DriverChain_ internally to configure Doctrine 2 ORM.
This allows you to use mixed types of metadata drivers in a single project.
-
db.orm.proxies_dir, (*27)
Default: cache/doctrine/Proxy
, (*28)
Sets the directory where Doctrine generates any proxy classes.
For a detailed explanation on proxy classes and how they are used in Doctrine, refer to section 3.5 Proxy Objects of the Doctrine ORM documentation., (*29)
-
db.orm.proxies_namespace, (*30)
Default: DoctrineProxy
, (*31)
Sets the namespace to use for generated proxy classes.
For a detailed explanation on proxy classes and how they are used in Doctrine, refer to section 3.5 Proxy Objects of the Doctrine ORM documentation., (*32)
Usage
You can access the EntityManager by calling $app['db.orm.em']
., (*33)