{"id":19241391,"url":"https://github.com/opensolutions/doctrine2bridge-l5","last_synced_at":"2025-04-21T08:32:40.479Z","repository":{"id":26995807,"uuid":"30459746","full_name":"opensolutions/doctrine2bridge-l5","owner":"opensolutions","description":"Brings the power of Doctrine2 to Laravel 5","archived":false,"fork":false,"pushed_at":"2015-09-25T10:46:26.000Z","size":344,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T11:53:42.931Z","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":"2015-02-07T15:24:31.000Z","updated_at":"2017-07-13T12:43:47.000Z","dependencies_parsed_at":"2022-06-26T03:35:02.384Z","dependency_job_id":null,"html_url":"https://github.com/opensolutions/doctrine2bridge-l5","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge-l5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge-l5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge-l5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensolutions%2Fdoctrine2bridge-l5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opensolutions","download_url":"https://codeload.github.com/opensolutions/doctrine2bridge-l5/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250023601,"owners_count":21362433,"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-11-09T17:11:16.995Z","updated_at":"2025-04-21T08:32:40.169Z","avatar_url":"https://github.com/opensolutions.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NB: You are advised to use this project from here on in: http://laraveldoctrine.org/ \n\n# Doctrine2Bridge for Laravel 5\n\nAdds the power of Doctrine2 to Laraval 5 (including authentication and SQL query logging support).\n\nFor Laravel4, see [opensolutions/doctrine2bridge](https://github.com/opensolutions/doctrine2bridge)\n\nLaravel's Eloquent ORM is nice for rapid development and the active model pattern. However there's little out\nthere that can beat Doctrine2 when you need a more full-featured ORM.\n\nThis is an integration of Doctrine 2.x to Laravel 5.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-l5/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-l5\": \"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\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 publish and edit the configuration files:\n\n    ./artisan vendor:publish --provider \"Doctrine2Bridge\\Doctrine2CacheBridgeServiceProvider\"\n    ./artisan vendor:publish --provider \"Doctrine2Bridge\\Doctrine2BridgeServiceProvider\"\n\nThis should get you a fresh copy of the configuration files (`d2bcache.php` and `db2doctrine.php`) in the configs directory.\n\nNow, edit these as well as setting Laravel5's own `cache.php` and `database.php` appropriately.\n\nThe default directory for Doctrine2's xml schema is `database/xml`. This can be configured in `config/d2bdoctrine.php`.\n\nDocumentation on integrating this with Laravel's own authentication system [can be found here](https://github.com/opensolutions/doctrine2bridge-l5/wiki/Auth).\n\n## Usage\n\nFour bindings are created which can be injected via Laravel's IoC in the standard manner:\n\n * `Doctrine\\ORM\\EntityManagerInterface` (which is an instance of Doctrine\\ORM\\EntityManager)\n * `Doctrine\\Common\\Cache\\Cache` (which is an instance of the appropriate cache provider)\n * `Doctrine\\ORM\\Mapping\\ClassMetadataFactory` (used in this package by the console generator commands)\n * `Doctrine2Bridge\\Support\\Repository` (used by the `D2R` facade, see below)\n\nThree facades are provided - for the Doctrine2 cache, the entity manager and a convenience repository generator. 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\nTypically we'd create and use a repository as follows:\n\n    $sample = D2EM::getRepository( '\\Entities\\SampleEntity' )-\u003efind(5);\n\nAssuming `d2bdoctrine.namespaces.models =\u003e 'Entities'`, then we can use the `D2R` facade in any of the following ways to achieve the same result:\n\n    $sample = D2R::r( 'SampleEntity' )-\u003efind(5);\n    $sample = D2R::r( 'Entities\\SampleEntity' )-\u003efind(5);\n    $sample = D2R::r( 'SampleEntity', 'Entities' )-\u003efind(5);\n\n## More Detailed Usage\n\nThe configuration file by default expects to find XML schema definitions under `database/xml`. Let's say for example we have a single schema file called `database/xml/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 positioned in the base directory of your project, we can create the entities, proxies and repositories with:\n\n    ./artisan d2b:generate:entities\n    ./artisan d2b:generate:proxies\n    ./artisan d2b:generate:repositories\n\nThere is also a handy shortcut for this:\n\n    ./artisan d2b:generate:all\n\nRead the output of these commands as they may need to be run twice.\n\nWe also bundle a full Doctrine2 CLI utilty so the above could also be done via:\n\n    ./vendor/bin/d2b-doctrine2 orm:generate-entities database/\n    ./vendor/bin/d2b-doctrine2 orm:generate-proxies\n    ./vendor/bin/d2b-doctrine2 orm:generate-repositories database/\n\nYou can also (drop) and create the database with:\n\n    ./artisan d2b:schema:drop --commit\n    ./artisan d2b:schema:create --commit\n\nAnd you can update and validate via:\n\n    ./artisan d2b:schema:update --commit\n    ./artisan d2b:schema:validate\n\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 [Skipper](http://www.skipper18.com/) to create and manage my XML schema files.\n\n## Convenience Function for Repositories\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## Inspiration\n\nBased on my original package [opensolutions/doctrine2bridge](https://github.com/opensolutions/doctrine2bridge) for Laravel4. Some additional inspiration when porting to Laravel5 from [mitchellvanw/laravel-doctrine](https://github.com/mitchellvanw/laravel-doctrine).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensolutions%2Fdoctrine2bridge-l5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopensolutions%2Fdoctrine2bridge-l5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensolutions%2Fdoctrine2bridge-l5/lists"}