public function __construct() { //Set up class loading. You cold use different autoloaders, provider by your //if you want to. require_once APPPATH . 'third_party/DoctrineORM-2.2.2/libraries/Doctrine/Common/ClassLoader.php'; require_once APPPATH . 'third_party/DoctrineORM-2.2.2/libraries/Doctrine/ORM/Tools/Setup.php'; Doctrine\ORM\Tools\Setup::registerAutoloadDirectory(APPPATH . 'third_party/DoctrineORM-2.2.2/libraries/'); $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'third_party/DoctrineORM-2.2.2/libraries'); $doctrineClassLoader->register(); $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies'); $proxiesClassLoader->register(); //Set up caches $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver([APPPATH . 'models/Entities']); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); //Proxy configuration $config->setProxyDir(APPPATH . '/models/proxies'); $config->setProxyNamespace('Proxies'); //Set up logger //$logger = new EchoSQLLogger; //$config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(true); include APPPATH . 'config/database.php'; //Database connection information $connectionOptions = ['driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database'], 'charset' => $db['default']['char_set'], 'driverOptions' => [1002 => 'SET NAMES utf8']]; //Enforce connection character set. This is very important if you are //using MySQL and InnoDB tables! //Doctrine_Manager::connection()->setCharset('utf8'); //Doctrine_Manager::connection()->setCollate('utf8_general_ci'); //Create EntityManager $this->em = EntityManager::create($connectionOptions, $config); }
public function __construct() { // Set up class loading. You could use different autoloaders, provided by your favorite framework, // if you want to. $directory = APPPATH . "third_party/doctrine2-orm"; if (!class_exists('Doctrine\\ORM\\Tools\\Setup', false)) { require $directory . '/Doctrine/ORM/Tools/Setup.php'; } Doctrine\ORM\Tools\Setup::registerAutoloadDirectory($directory); $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'libraries'); $doctrineClassLoader->register(); // Set up models loading $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/")); $entitiesClassLoader->register(); foreach (glob(APPPATH . 'modules/*', GLOB_ONLYDIR) as $m) { $module = str_replace(APPPATH . 'modules/', '', $m); $loader = new ClassLoader($module, APPPATH . 'modules'); $loader->register(); } $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies'); $proxiesClassLoader->register(); // Set up caches $this->config = new Configuration(); $cache = new ArrayCache(); // $cache = new \Doctrine\Common\Cache\ApcCache; $this->config->setMetadataCacheImpl($cache); $this->config->setQueryCacheImpl($cache); // Set up models $models = array(APPPATH . 'models'); foreach (glob(APPPATH . 'modules/*/models', GLOB_ONLYDIR) as $m) { array_push($models, $m); } $driverImpl = $this->config->newDefaultAnnotationDriver($models); $this->config->setMetadataDriverImpl($driverImpl); // Proxy configuration $this->config->setProxyDir(APPPATH . '/models/proxies'); $this->config->setProxyNamespace('Proxies'); // Set up logger // $logger = new EchoSQLLogger; // $this->config->setSQLLogger($logger); $this->config->setAutoGenerateProxyClasses(TRUE); // Database connection information // load database configuration from CodeIgniter // Is the config file in the environment folder? if (!defined('ENVIRONMENT') or !file_exists($file_path = APPPATH . 'config/' . ENVIRONMENT . '/database.php')) { if (!file_exists($file_path = APPPATH . 'config/database.php')) { show_error('The configuration file database.php does not exist.'); } } include $file_path; if (!isset($db) or count($db) == 0) { show_error('No database connection settings were found in the database config file.'); } $this->connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']); // Create EntityManager $this->em = EntityManager::create($this->connectionOptions, $this->config); }
public function __construct() { require_once __DIR__ . '/doctrine/ORM/Tools/Setup.php'; Setup::registerAutoloadDirectory(__DIR__); // Load the database configuration from CodeIgniter require APPPATH . 'config/database.php'; $connection_options = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database'], 'charset' => $db['default']['char_set'], 'driverOptions' => array('charset' => $db['default']['char_set'])); // With this configuration, your model files need to be in application/models/Entity // e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php $models_namespace = 'Entity'; $models_path = APPPATH . 'models'; $proxies_dir = APPPATH . 'models/Proxies'; $metadata_paths = array(APPPATH . 'models'); // Set $dev_mode to TRUE to disable caching while you develop $config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode = true, $proxies_dir); $this->em = EntityManager::create($connection_options, $config); $loader = new ClassLoader($models_namespace, $models_path); $loader->register(); }
public function testDirectoryAutoload() { Setup::registerAutoloadDirectory(__DIR__ . "/../../../../../lib/vendor/doctrine-common/lib"); $this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions())); }
$cf = $config->toArray(); Conjoon_Log::init($cf['log']); } } // set as default adapter for all db operations Conjoon_Db_Table::setDefaultAdapter(Zend_Db::factory($config->database->adapter, array('host' => $config->database->params->host, 'username' => $config->database->params->username, 'password' => $config->database->params->password, 'dbname' => $config->database->params->dbname, 'port' => $config->database->params->port, 'driver_options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8')))); // set tbl prefix Conjoon_Db_Table::setTablePrefix($config->database->table->prefix); // +------------------------------------------------------------------------ // | DOCTRINE // +------------------------------------------------------------------------ /** * @see Doctrine\ORM\Tools\Setup */ require_once 'Doctrine/ORM/Tools/Setup.php'; \Doctrine\ORM\Tools\Setup::registerAutoloadDirectory($LIBRARY_PATH_BOOTSTRAP . '/vendor/doctrine/'); /** * @see Doctrine\Common\ClassLoader */ require_once 'Doctrine/Common/ClassLoader.php'; $classLoader = new \Doctrine\Common\ClassLoader('Conjoon', $LIBRARY_PATH_BOOTSTRAP . '/src/corelib/php/library/'); $classLoader->register(); $doctrineParams = array('driver' => 'pdo_mysql', 'host' => $config->database->params->host, 'user' => $config->database->params->username, 'password' => $config->database->params->password, 'dbname' => $config->database->params->dbname, 'port' => $config->database->params->port, 'driverOptions' => array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8')); $doctrineCacheInstances = array('query_cache' => null, 'metadata_cache' => null); // doctrine cache settings if ($config->application->doctrine->cache->enabled) { $doctrineCacheSections = array('query_cache' => $config->application->doctrine->cache->query_cache, 'metadata_cache' => $config->application->doctrine->cache->metadata_cache); foreach ($doctrineCacheSections as $doctrineCacheKey => $doctrineCacheSection) { if ($doctrineCacheSection->enabled) { // if we do not find a valid extension, we'll be usind // an array cache later on
/** * [USADA POR EL SISTEMA] */ public static function registerAutoload() { \Doctrine\ORM\Tools\Setup::registerAutoloadDirectory(__DIR__ . '/../../Doctrine'); }
if (!file_exists($classLoaderBasePath)) { print 'Error: Could not find classloader base path: ' . $classLoaderBasePath . "\n"; exit; } } if ($props['doctrine.directory'] !== 'pear') { set_include_path($props['doctrine.directory'] . PATH_SEPARATOR . get_include_path()); } use Doctrine\ORM\Tools\Setup; require_once "Doctrine/ORM/Tools/Setup.php"; if ($props['doctrine.directory'] === 'pear') { // use pear supplied doctrine Setup::registerAutoloadPEAR(); } else { // use maven artifacts Setup::registerAutoloadDirectory($props['doctrine.directory']); } // enable classloading for the app $classLoader = new \Doctrine\Common\ClassLoader($props['doctrine.classloader.name'], $classLoaderBasePath); $classLoader->register(); // create a simple "default" Doctrine ORM configuration for annotation mapping $isDevMode = $props['dev.mode']; $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/MyApp/Entities'), $isDevMode); // or if you prefer xml/yaml annotations //$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode); //$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode); // database configuration switch ($props['db.driver']) { case "mysql": $conn = array('driver' => 'pdo_mysql', 'host' => $props['db.host'], 'port' => $props['db.port'], 'dbname' => $props['db.name'], 'user' => $props['db.user'], 'password' => $props['db.password']); break;