• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Doctrine ORM Service Provider

Doctrine ORM Service Provider

Provides Doctrine ORM Entity Managers as services to Pimple applications.

Features

  • Leverages the core Doctrine Service Provider 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 one. If you can or want to fake it, go for it. :)

Installation

Through Composer as dflydev/doctrine-orm-service-provider.

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

// Default entity manager.
$em = $app['orm.em'];

Pimple

<?php

use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
use Pimple\Container;

$container = new Container;

$container['db.options'] = array(
    'driver' => '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

use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
use Silex\Application;
use Silex\Provider\DoctrineServiceProvider;

$app = new Application;

$app->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 and simplified YAML driver 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?
    • 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
    $app['orm.ems.default'] = 'sqlite';
    $app['orm.ems.options'] = array(
        'mysql' => array(
            'connection' => 'mysql',
            'mappings' => array(), 
        ),
        'sqlite' => array(
            'connection' => 'sqlite',
            'mappings' => array(),
        ),
    );

    Example usage:

    <?php
    $emMysql = $app['orm.ems']['mysql'];
    $emSqlite = $app['orm.ems']['sqlite'];
  • orm.ems.default (Default: first Entity Manager processed): String defining the name of the default Entity Manager.

  • orm.proxies_dir: String defining path to where Doctrine generated proxies should be located.

  • orm.proxies_namespace (Default: DoctrineProxy): String defining namespace in which Doctrine generated proxies should reside.

  • orm.auto_generate_proxies: Boolean defining whether or not proxies should be generated automatically.

  • orm.class_metadata_factory_name: Class name of class metadata factory. Class implements Doctrine\Common\Persistence\Mapping\ClassMetadataFactory.

  • orm.default_repository_class: Class name of default repository. Class implements Doctrine\Common\Persistence\ObjectRepository.

  • orm.repository_factory: Repository factory, instance Doctrine\ORM\Repository\RepositoryFactory.

  • orm.entity_listener_resolver: Entity listener resolver, instance Doctrine\ORM\Mapping\EntityListenerResolver.

  • orm.default_cache: String or array describing default cache implementation.

  • orm.add_mapping_driver: Function providing the ability to add a mapping driver to an Entity Manager.

    These params are available:

    • $mappingDriver: Mapping driver to be added, instance Doctrine\Common\Persistence\Mapping\Driver\MappingDriver.
    • $namespace: Namespace to be mapped by $mappingDriver, string.
    • $name: Name of Entity Manager to add mapping to, string, default null.
  • orm.em_name_from_param: Function providing the ability to retrieve an entity manager's name from a param.

    This is useful for being able to optionally allow users to specify which entity manager should be configured for a 3rd party service provider but fallback to the default entity manager if not explitely specified.

    For example:

    <?php
    $emName = $app['orm.em_name_from_param']('3rdparty.provider.em');
    $em = $app['orm.ems'][$emName];

    This code should be able to be used inside of a 3rd party service provider safely, whether the user has defined 3rdparty.provider.em or not.

  • orm.strategy:

    • naming: Naming strategy, instance Doctrine\ORM\Mapping\NamingStrategy.
    • quote: Quote strategy, instance Doctrine\ORM\Mapping\QuoteStrategy.
  • orm.custom.functions:

    • string, numeric, datetime: Custom DQL functions, array of class names indexed by DQL function name. Classes are subclasses of Doctrine\ORM\Query\AST\Functions\FunctionNode.
    • hydration_modes: Hydrator class names, indexed by hydration mode name. Classes are subclasses of Doctrine\ORM\Internal\Hydration\AbstractHydrator.

Services

  • orm.em: Entity Manager, instance Doctrine\ORM\EntityManager.
  • orm.ems: Entity Managers, array of Doctrine\ORM\EntityManager indexed by name.

Frequently Asked Questions

Why aren't my Annotations classes being found?

When use_simple_annotation_reader is set to False for an entity, the AnnotationRegistry needs to have the project's autoloader added to it.

Example:

<?php
$loader = require __DIR__ . '/../vendor/autoload.php';

\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

Why is there no manager registry implementation?

There is already a thirdparty ManagerRegistry implementation at saxulum-doctrine-orm-manager-registry-provider. It support the entity type known of the form component, adds the UniqueEntity validator and a command line integration.

License

MIT, see LICENSE.

Community

If you have questions or want to help out, join us in the #dflydev or #silex-php channels on irc.freenode.net.

Not Invented Here

This project is based heavily on both the core Doctrine Service Provider and the work done by @docteurklein on the docteurklein/silex-doctrine-service-providers project. Some inspiration was also taken from Doctrine Bundle and Doctrine Bridge.

More Repositories

1

dflydev-dot-access-data

Given a deep data structure representing a configuration, access configuration by dot notation.
PHP
590
star
2

git-subsplit

Automate and simplify the process of managing one-way read-only subtree splits.
Shell
328
star
3

dflydev-fig-cookies

Cookies for PSR-7 HTTP Message Interface.
PHP
223
star
4

dflydev-markdown

PHP Markdown & Extra — DEPRECATED
PHP
171
star
5

dflydev-placeholder-resolver

Provides a mechanism to resolve placeholders from an arbitrary data source.
PHP
143
star
6

dflydev-dot-access-configuration

Given a deep data structure representing a configuration, access configuration by dot notation.
PHP
134
star
7

dflydev-embedded-composer

Embed Composer into another application
PHP
71
star
8

dflydev-apache-mime-types

Apache MIME Types
PHP
71
star
9

es-cqrs-broadway-workshop

Introduction to Event Sourcing & CQRS with Broadway workshop project
PHP
68
star
10

dflydev-hawk

Hawk — A PHP Implementation
PHP
67
star
11

embed-github-gist

Embed GitHub Gist WordPress plugin
PHP
47
star
12

dflydev-canal

Analyze content to determine the appropriate Internet media type
PHP
34
star
13

dflydev-git-subsplit-github-webhook

GitHub WebHook for Git subsplits managed by dflydev-git-subsplit.
PHP
28
star
14

just-run-phpunit

Allow developers to "just run phpunit."
27
star
15

check-runs-action

✅ GitHub Check Runs Action
TypeScript
15
star
16

dflydev-base32-crockford

Encode/decode numbers using Douglas Crockford's Base32 Encoding
PHP
13
star
17

dflydev-stack-basic-authentication

HTTP Basic Authentication Stack middleware
PHP
12
star
18

repose-php

Repose is an Object-Relational Mapping (ORM) library for PHP5. Repose implements a Unit of Work (UoW), an Identity Map and generated proxy classes to provide transparent unobtrusive persistence in PHP.
PHP
11
star
19

dflydev-stack-hawk

Hawk Stack middleware
PHP
10
star
20

dflydev-encrypted-fig-cookies

Encrypted Cookies for PSR-7 HTTP Message Interface.
PHP
7
star
21

dflydev-finite-state-machine

Yet another finite-state machine implementation
PHP
7
star
22

dflydev-github-gist-twig-extension

GitHub Gist Twig Extension
PHP
7
star
23

dflydev-util-antPathMatcher

Ant Path Matcher Utility
PHP
6
star
24

old-ninjagrl.com

Architecture demo application for ninjagrl.com
PHP
6
star
25

dflydev-symfony-finder-factory

Symfony Finder Factory
PHP
6
star
26

dflydev-event-store

Naive event store.
PHP
6
star
27

substrate-php

Substrate - An IoC/DI Container for PHP
PHP
5
star
28

dflydev-stack-firewall

Firewall Stack middleware
PHP
5
star
29

dflydev-psr0-resource-locator-service-provider

PSR-0 Resource Locator Service Provider
PHP
4
star
30

dflydev-identity-generator

Provide a standard interface for generating unique string-based identifiers.
PHP
4
star
31

dflydev-embedded-composer-application

Embedded Composer Example Application
PHP
4
star
32

dd-ci-ddauth

Dragonfly Development CodeIgniter Auth Add-on
PHP
4
star
33

composer-tutorial

PHP
3
star
34

jquery-ddNamespace

jQuery Namespace Add-on
JavaScript
3
star
35

dflydev-common-domain-model-identity

Identity for domain models.
PHP
3
star
36

dflydev-psr0-resource-locator-composer

Composer PSR-0 Resource Locator
PHP
3
star
37

dflydev-stack-authentication

STACK-2 Authentication Middlewares
PHP
3
star
38

dflydev-event-store-doctrine-dbal

Doctrine DBAL implementation of a naive event store.
PHP
3
star
39

repose-ci-php

Repose PHP ORM CodeIgniter Library
PHP
3
star
40

streamdeck-restreamio

🔌 Stream Deck Restream.io plugin
CSS
3
star
41

halo-php

Halo Web Application Framework for PHP
PHP
3
star
42

dflydev-psr0-resource-locator

PSR-0 Resource Locator
PHP
3
star
43

dflydev-github-gist-twig-bundle

GitHub Gist Twig Bundle
PHP
3
star
44

dflydev-twig-gitHub-gist-sculpin-bundle

Twig GitHub Gist Sculpin Bundle
PHP
2
star
45

dflydev.com

Dragonfly Development Website
HTML
2
star
46

dflydev-embedded-composer-core

[READ-ONLY] Subtree split of Dflydev\EmbeddedComposer\Core.
PHP
2
star
47

skittle-php

Skittle - A lightweight pure PHP template inclusion library
PHP
2
star
48

dd-ci-vendorlibs

Dragonfly Development CodeIgniter Vendor Libs Add-on
2
star
49

dd-configuration-php

Dragonfly Development PHP Configuration Library
PHP
2
star
50

dflydev-common-domain-model-identity-rhumsaa

Implementation of identity for domain models using rhumsaa/uuid.
PHP
2
star
51

safsi-php

Simple Abstract File System Interface
PHP
2
star
52

nimble-tutorial

Nimble Tutorial
Makefile
2
star
53

dflydev-embedded-composer-console

[READ-ONLY] Subtree split of Dflydev\EmbeddedComposer\Console.
PHP
2
star
54

ddvash

ddVash WordPress Theme
PHP
1
star
55

dflydev-snort

Sniff content to determine things about it.
PHP
1
star
56

dflydev-theme

Generic Theme Framework
PHP
1
star
57

dflydev-snort-buffer

[READ-ONLY] Subtree split of Dflydev\Snort\Buffer.
PHP
1
star
58

just-run-anything

Allow developers to "just run <anything>" where <anything> may exist at arbitrary paths *or* installed globally.
Shell
1
star
59

dflydev-theme-twig-extension

Theme Twig Extension
PHP
1
star
60

dflydev-doctrine-commands-service-provider

Doctrine Commands Service Provider
PHP
1
star
61

dflydev-composer-autoload

Composer Autoload Tools
PHP
1
star
62

lithe-php-single-site

Lithe - Single Site Application
PHP
1
star
63

raffl.io

CSS
1
star
64

dflydev-wp-theme

dflydev WordPress Theme
PHP
1
star
65

dd-image-php

dd-image is useful for doing simple image manipulation operations.
PHP
1
star
66

page-shortcodes

Page Shortcodes WordPress Plugin
PHP
1
star
67

lithe-php

Lithe - a lightweight web application framework for PHP built on Halo and Substrate
PHP
1
star
68

ddrem

ddRem WordPress Them
PHP
1
star
69

dflydev-core-php

Provides basic bootstrapping functionality such as resource locating and class loading.
PHP
1
star
70

dd-logging-php

Dragonfly Development PHP Logging Library
PHP
1
star
71

dd-uri-php

Dragonfly Development PHP URI Library
PHP
1
star
72

dd-idgen-php

Dragonfly Development PHP ID Generation Library
PHP
1
star
73

lithe-php-multiple-sites

Lithe - Multiple Sites Application
PHP
1
star
74

dflydev-common-domain-model-identity-ramsey

Implementation of identity for domain models using ramsey/uuid
PHP
1
star
75

d2code-core-wp-theme

d2code Core WordPress Theme
PHP
1
star
76

dflydev-identity-generator-dbal

Provides a Doctrine DBAL implemetnation of the identity generator data store.
PHP
1
star
77

dd-core-php

Dragonfly Development PHP Core Library
PHP
1
star
78

dflydev-theme-service-provider

Theme Service Provider
PHP
1
star
79

ddrem-iaous

Imagine Arts One's WordPress Theme. Based on ddRem.
JavaScript
1
star
80

dflydev-psr0-resource-locator-composer-service-provider

Composer PSR-0 Resource Locator Service Provider
PHP
1
star
81

dflydev-snort-textorbinary

[READ-ONLY] Subtree split of Dflydev\Snort\TextOrBinary.
PHP
1
star
82

ddknives

ddKnives WordPress Theme
PHP
1
star
83

dflydev-embedded-composer-bundle

[READ-ONLY] Subtree split of Dflydev\EmbeddedComposer\Bundle.
PHP
1
star
84

ddknives-offloc

Offloc's WordPress Theme. Based on ddKnives.
JavaScript
1
star
85

d2code-dflydev-wp-theme

d2code dflydev WordPress Theme
PHP
1
star