{"id":15019844,"url":"https://github.com/opensolutions/doctrine2bridge","last_synced_at":"2025-10-24T18:30:18.326Z","repository":{"id":13380154,"uuid":"16068107","full_name":"opensolutions/doctrine2bridge","owner":"opensolutions","description":"Adds the the power of Doctrine2 to Laravel 4","archived":false,"fork":false,"pushed_at":"2015-09-25T10:47:19.000Z","size":304,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-27T22:20:19.013Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opensolutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-20T10:52:05.000Z","updated_at":"2016-11-04T16:34:25.000Z","dependencies_parsed_at":"2022-09-13T22:43:06.505Z","dependency_job_id":null,"html_url":"https://github.com/opensolutions/doctrine2bridge","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opensolutions","download_url":"https://codeload.github.com/opensolutions/doctrine2bridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219868209,"owners_count":16555875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T19:54:11.120Z","updated_at":"2025-10-24T18:30:17.970Z","avatar_url":"https://github.com/opensolutions.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Doctrine2Bridge\n\nAdds the power of Doctrine2 to Laraval 4 (including authentication and SQL query logging support).\n\nLaravel's Eloquent ORM is nice for lightweight use, however there's little out there that can beat Doctrine when you need a more full-featured ORM.\n\nThis is an integration of Doctrine 2.x to Laravel 4.x as a composer package. Doctrine's EntityManager instance is accessible through a facade named `D2EM` and the cache is directly available via `D2Cache`.\n\nMetadata is currently obtained via the [XML driver](http://docs.doctrine-project.org/en/latest/reference/xml-mapping.html). It should be easy to add additional drivers to this.\n\nAuthentication support is also included via a `Auth/Doctrine2UserProvider` class. Documentation on integrating this with Laravel's own authentication system [can be found here](https://github.com/opensolutions/doctrine2bridge/wiki/Auth).\n\n## Installation\n\nInstallation is the usual for Laravel packages. You can find a detailed worked version of [how to install and test in the wiki](https://github.com/opensolutions/doctrine2bridge/wiki/Install-from-Scratch).\n\nInsert the following in the packages (`require`) section of your composer.json file and run an update (`composer update`):\n\n    \"opensolutions/doctrine2bridge\": \"2.4.*\",\n\nGenerally speaking, we'll try and match our minor versions (2.4.x) with Doctrine's but you should always use the latest `x` version of this.\n\nNote that your minimum stability must be `dev` for Doctrine migrations. If the above command complains, ensure you have the following set in your `composer.json` file:\n\n    \"minimum-stability\": \"dev\"\n\nAdd the service providers to your Laravel application in `app/config/app.php`. In the `'providers'` array add:\n\n    'Doctrine2Bridge\\Doctrine2CacheBridgeServiceProvider',\n    'Doctrine2Bridge\\Doctrine2BridgeServiceProvider',\n\nYou'll need to public and edit the configuration file:\n\n    ./artisan config:publish opensolutions/doctrine2bridge\n\nThis should get you a fresh copy of the configuration file in the directory `app`:\n\n    config/packages/vendor/opensolutions/doctrine2bridge\n\nDocumentation on integrating this with Laravel's own authentication system [can be found here](https://github.com/opensolutions/doctrine2bridge/wiki/Auth).\n\n## Usage\n\nTwo facades are provided - one for the Doctrine2 cache and the other for the entity manager. These can be used as follows:\n\n    D2Cache::save( $key, $value );\n    D2Cache::fetch( $key );\n    \n    D2EM::persist( $object );\n    D2EM::flush();\n    $users = D2EM::getRepository( 'Entities\\User' )-\u003efindAll();\n\n## More Detailed Usage\n\nThe configuration file by default expects to find XML schema definitions under `doctrine/schema`. Let's say for example we have a single schema file called `doctrine/schema/Entities.SampleEntity.dcm.xml` containing:\n\n    \u003c?xml version=\"1.0\"?\u003e\n    \u003cdoctrine-mapping xmlns=\"http://doctrine-project.org/schemas/orm/doctrine-mapping\" xsi=\"http://www.w3.org/2001/XMLSchema-instance\" schemaLocation=\"http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd\"\u003e\n        \u003centity name=\"Entities\\SampleEntity\" repository-class=\"Repositories\\Sample\"\u003e\n            \u003cid name=\"id\" type=\"integer\"\u003e\n                \u003cgenerator strategy=\"AUTO\"/\u003e\n            \u003c/id\u003e\n            \u003cfield name=\"name\" type=\"string\" length=\"255\" nullable=\"true\"/\u003e\n        \u003c/entity\u003e\n    \u003c/doctrine-mapping\u003e\n\nAssuming you've configured your database connection parameters in the config file and you're positioning in the base directory of your project, we can create the entities, proxies and repositories with:\n\n    ./vendor/bin/doctrine2 orm:generate-entities app/models/\n    ./vendor/bin/doctrine2 orm:generate-proxies\n    ./vendor/bin/doctrine2 orm:generate-repositories app/models/\n\nYou can also (drop) and create the database with:\n\n    ./vendor/bin/doctrine2 orm:schema-tool:drop --force\n    ./vendor/bin/doctrine2 orm:schema-tool:create\n\nNow you can add some data to the database:\n\n    $se = new Entities\\SampleEntity;\n    $se-\u003esetName( rand( 0, 100 ) );\n    D2EM::persist( $se );\n    D2EM::flush();\n\nAnd query it:\n\n    echo count( D2EM::getRepository( 'Entities\\SampleEntity' )-\u003efindAll() );\n\nI use the excellent [ORM Designer](http://www.orm-designer.com/) to create and manage my XML schema files.\n\n## Convenience Function for Repositories\n\nIf, like me, you spend a lot of time typing `D2EM::getRepository( 'Entities\\XXX' )`, then add the following to the end of `bootstrap/start.php`:\n\n    include $app['path.base'] . '/vendor/opensolutions/doctrine2bridge/src/bootstrap/d2r.php';\n\nand then you can replace the above with: `D2R( 'XXX' )`. I use *Entities* as my namespace generally so this function is just as follows (which you can easily change to suit yourself):\n\n    function D2R( $entity, $namespace = 'Entities' )\n    {\n        return D2EM::getRepository( $namespace . '\\\\' . $entity );\n    }\n\n## SQL Query Logging\n\nThis package includes an implementation of `Doctrine\\DBAL\\Logging\\SQLLlogger` which times the queries and calls the Laravel [Log](http://laravel.com/docs/errors#logging) facade to log the query execution times and the SQL queries.\n\nThis logger can be enabled in the configuration file.\n\n## License\n\nLike the Laravel framework itself, this project is open-sourced under the [MIT license](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensolutions%2Fdoctrine2bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopensolutions%2Fdoctrine2bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensolutions%2Fdoctrine2bridge/lists"}