<?php /** * xenFramework (http://xenframework.com/) * * This file is part of the xenframework package. * * (c) Ismael Trascastro <*****@*****.**> * * @link http://github.com/xenframework for the canonical source repository * @copyright Copyright (c) xenFramework. (http://xenframework.com) * @license MIT License - http://en.wikipedia.org/wiki/MIT_License * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require __DIR__ . '/../vendor/xenframework/xen/src/xen/db/doctrine/DoctrineBootstrap.php'; use xen\db\doctrine\DoctrineBootstrap; $config = (require 'setup.php'); $databases = (require __DIR__ . '/../application/configs/databases.php'); $driver = $databases[$config['db']]['driver']; $username = $databases[$config['db']]['username']; $password = $databases[$config['db']]['password']; $dbname = $databases[$config['db']]['dbname']; $dbConfig = (object) ['driver' => $driver, 'username' => $username, 'password' => $password, 'dbname' => $dbname]; $entityManager = DoctrineBootstrap::bootstrap($dbConfig, $config['package']); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager))); return $helperSet;
/** * _dependencyDatabase * * Load the database config 'application/configs/databases.php' * * Can exists more than one database: * * The first time 'application/configs/databases.php' is loaded into Databases resource * * Each Database resource is named as follows: Database_ID_Orm * * Orm can be: * * - pdo * - doctrine * * So when this method is called with $db ID, it creates the Database_$db_$orm resource * and stores it in the container * * * @param string $db The ID of the database * * @param string $orm * * @throws bootstrap\exception\ContainerDependencyDatabaseNotFoundException */ protected function _dependencyDatabase($db, $orm) { if (!$this->resourceExists('Databases')) { $databases = (require 'application/configs/databases.php'); $this->addResource('Databases', $databases); } if (!array_key_exists($db, $this->getResource('Databases'))) { throw new ContainerDependencyDatabaseNotFoundException('Dependency database ' . $db . ' not found in ' . '"application/configs/databases.php"'); } $databasesResource = $this->getResource('Databases'); $dbConfig = new Config($databasesResource[$db]); if ($orm == 'pdo' || $orm == '') { $adapter = new Adapter($dbConfig); } else { if ($orm == 'doctrine') { $adapter = DoctrineBootstrap::bootstrap($dbConfig, $this->getResource('Package'), $this->getResource('AppStage')); } } $resource = 'Database_' . $db; if ($orm != '') { $resource .= '_' . $orm; } $this->addResource($resource, $adapter); }