https://github.com/dflydev/dflydev-doctrine-orm-service-provider
Doctrine ORM Service Provider
https://github.com/dflydev/dflydev-doctrine-orm-service-provider
Last synced: about 1 year ago
JSON representation
Doctrine ORM Service Provider
- Host: GitHub
- URL: https://github.com/dflydev/dflydev-doctrine-orm-service-provider
- Owner: dflydev
- License: mit
- Created: 2012-10-15T02:20:48.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2023-01-30T16:26:08.000Z (over 3 years ago)
- Last Synced: 2025-04-09T07:04:33.243Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 110 KB
- Stars: 209
- Watchers: 9
- Forks: 58
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
Doctrine ORM Service Provider
=============================
Provides Doctrine ORM Entity Managers as services to Pimple applications.
Features
--------
* Leverages the core [Doctrine Service Provider][1] for either
Silex.
* Default Entity Manager can be bound to any database connection
* Multiple Entity Managers can be defined
* Mechanism for allowing Service Providers to register their own
mappings
Requirements
------------
* PHP 5.3+
* Pimple ~2.1
* Doctrine ~2.3
Currently requires both **dbs** and **dbs.event_manager** services in
order to work. These can be provided by a Doctrine Service Provider
like the [Silex][1] one. If you can or want to fake it, go for it. :)
Installation
------------
Through [Composer](http://getcomposer.org) as [dflydev/doctrine-orm-service-provider][6].
Usage
-----
To get up and running, register `DoctrineOrmServiceProvider` and
manually specify the directory that will contain the proxies along
with at least one mapping.
In each of these examples an Entity Manager that is bound to the
default database connection will be provided. It will be accessible
via **orm.em**.
```php
'pdo_sqlite',
'path' => '/path/to/sqlite.db',
);
// ensure that $container['dbs'] and $container['dbs.event_manager']
// are available, most likely by way of a core service provider.
$container->register(new DoctrineOrmServiceProvider, array(
'orm.proxies_dir' => '/path/to/proxies',
'orm.em.options' => array(
'mappings' => array(
// Using actual filesystem paths
array(
'type' => 'annotation',
'namespace' => 'Foo\Entities',
'path' => __DIR__.'/src/Foo/Entities',
),
array(
'type' => 'xml',
'namespace' => 'Bat\Entities',
'path' => __DIR__.'/src/Bat/Resources/mappings',
),
// XML/YAML driver (Symfony2 style)
// Mapping files can be named like Foo.orm.yml
// instead of Baz.Entities.Foo.dcm.yml
array(
'type' => 'simple_yml',
'namespace' => 'Baz\Entities',
'path' => __DIR__.'/src/Bat/Resources/config/doctrine',
),
),
),
));
```
### Silex
Version 2.x of this service provider is compatible with version 2.x of Silex and version 1.x of this service provider is compatible with version 1.x of Silex. The following is an example of version 2.x of this service provider and version 2.x of Silex.
```php
register(new DoctrineServiceProvider, array(
'db.options' => array(
'driver' => 'pdo_sqlite',
'path' => '/path/to/sqlite.db',
),
));
$app->register(new DoctrineOrmServiceProvider, array(
'orm.proxies_dir' => '/path/to/proxies',
'orm.em.options' => array(
'mappings' => array(
// Using actual filesystem paths
array(
'type' => 'annotation',
'namespace' => 'Foo\Entities',
'path' => __DIR__.'/src/Foo/Entities',
),
array(
'type' => 'xml',
'namespace' => 'Bat\Entities',
'path' => __DIR__.'/src/Bat/Resources/mappings',
),
),
),
));
```
Configuration
-------------
### Parameters
* **orm.em.options**:
Array of Entity Manager options.
These options are available:
* **connection** (Default: default):
String defining which database connection to use. Used when using
named databases via **dbs**.
* **mappings**:
Array of mapping definitions.
Each mapping definition should be an array with the following
options:
* **type**: Mapping driver type, one of `annotation`, `xml`, `yml`, `simple_xml`, `simple_yml` or `php`.
* **namespace**: Namespace in which the entities reside.
*New: the `simple_xml` and `simple_yml` driver types were added in v1.1 and provide support for the [simplified XML driver][8] and [simplified YAML driver][9] of Doctrine.*
Additionally, each mapping definition should contain one of the
following options:
* **path**: Path to where the mapping files are located. This should
be an actual filesystem path. For the php driver it can be an array
of paths
* **resources_namespace**: A namespaceish path to where the mapping
files are located. Example: `Path\To\Foo\Resources\mappings`
Each mapping definition can have the following optional options:
* **alias** (Default: null): Set the alias for the entity namespace.
Each **annotation** mapping may also specify the following options:
* **use_simple_annotation_reader** (Default: true):
If `true`, only simple notations like `@Entity` will work.
If `false`, more advanced notations and aliasing via `use` will
work. (Example: `use Doctrine\ORM\Mapping AS ORM`, `@ORM\Entity`)
Note that if set to `false`, the `AnnotationRegistry` will probably
need to be configured correctly so that it can load your Annotations
classes. See this FAQ:
[Why aren't my Annotations classes being found?](#why-arent-my-annotations-classes-being-found)
* **query_cache** (Default: setting specified by orm.default_cache):
String or array describing query cache implementation.
* **metadata_cache** (Default: setting specified by orm.default_cache):
String or array describing metadata cache implementation.
* **result_cache** (Default: setting specified by orm.default_cache):
String or array describing result cache implementation.
* **hydration_cache** (Default: setting specified by orm.default_cache):
String or array describing hydration cache implementation.
* **types**
An array of custom types in the format of 'typeName' => 'Namespace\To\Type\Class'
* **orm.ems.options**:
Array of Entity Manager configuration sets indexed by each Entity Manager's
name. Each value should look like **orm.em.options**.
Example configuration:
```php
array(
'connection' => 'mysql',
'mappings' => array(),
),
'sqlite' => array(
'connection' => 'sqlite',
'mappings' => array(),
),
);
```
Example usage:
```php