Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit 50a8732d2fdf2d571cd01fa1ff646817470e7b4b @Mparaiso committed Mar 18, 2013
Showing with 142 additions and 0 deletions.
  1. 0 .gitignore
  2. +19 −0 LICENSE
  3. +10 −0 README.md
  4. +19 −0 SYMFONY LICENSE
  5. +32 −0 composer.json
  6. +62 −0 src/Mparaiso/Provider/DoctrineORMServiceProvider.php
0 .gitignore
No changes.
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2013 M.Paraiso
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
10 README.md
@@ -0,0 +1,10 @@
+Doctrine ORM Service Provider
+=============================
+
+Doctrine ORM silex extension
+----------------------------
+
+author : M.Paraiso
+contact: mparaiso@online.fr
+
+status: work in progress
19 SYMFONY LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2010-2013 Fabien Potencier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
32 composer.json
@@ -0,0 +1,32 @@
+{
+ "name": "mparaiso/doctrineormserviceprovider",
+ "description": "Doctrine ORM for Silex",
+ "keywords": [
+ "silex",
+ "extensions",
+ "orm",
+ "doctrine"
+ ],
+ "homepage": "https://github.com/Mparaiso/aclserviceprovider",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "MParaiso",
+ "email": "mparaiso@online.fr"
+ }
+ ],
+ "require-dev": {
+ "silex/silex": "*"
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "doctrine/orm": "2.3.*",
+ "symfony/console":"2.2.*"
+ },
+ "suggest": {},
+ "autoload": {
+ "psr-0": {
+ "Mparaiso": "src/"
+ }
+ }
+}
62 src/Mparaiso/Provider/DoctrineORMServiceProvider.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Mparaiso\Provider;
+
+use Silex\ServiceProviderInterface;
+use Silex\Application;
+use Doctrine\ORM\Tools\Setup;
+use Doctrine\ORM\EntityManager;
+
+class DoctrineORMServiceProvider implements ServiceProviderInterface {
+
+ public function boot(Application $app) {
+
+ }
+
+ public function register(Application $app) {
+ $app["em.proxy_dir"] = null;
+ $app["em"] = $app->share(function($app) {
+ if (!is_array($app["em.metadata"]["path"])) {
+ throw new \Exception("\$app['em.metadata']['path'] must be an array of paths");
+ }
+ if ($app["em.metadata"]["type"] === "annotation") {
+ $app["em.config"] = function($app) {
+ return Setup::createAnnotationMetadataConfiguration(
+ $app["em.metadata"]["path"],
+ $app["em.is_dev_mode"],
+ $app["em.proxy_dir"]
+ );
+ };
+ } elseif ($app["em.metadata"]["type"] === "xml") {
+ $app["em.config"] = function($app) {
+ return Setup::createXMLMetadataConfiguration(
+ $app["em.metadata"]["path"],
+ $app["em.is_dev_mode"],
+ $app["em.proxy_dir"]
+ );
+ };
+ } elseif ($app["em.metadata"]["type"] === "yaml") {
+ $app["em.config"] = function($app) {
+ return Setup::createYAMLMetadataConfiguration(
+ $app["em.metadata"]["path"],
+ $app["em.is_dev_mode"],
+ $app["em.proxy_dir"]);
+ };
+ }
+ $app["em.is_dev_mode"] = $app->share(function($app){
+ return $app["debug"];
+ });
+ // si le service em.options n'est pas déclaré , utiliser le service db de DoctrineServiceProvider
+ if(!isset($app["em.options"]) && $app["db"]){
+ $app["em.options"] = $app["db"];
+ }
+ $em = EntityManager::create($app["em.options"], $app["em.config"]);
+ if(isset($app["em.logger"])){
+ $em->getConfiguration()->setSQLLogger($app["em.logger"]);
+ }
+ return $em;
+ }
+ );
+ }
+
+}

0 comments on commit 50a8732

Please sign in to comment.
Something went wrong with that request. Please try again.