Este sería mi resource.
Código PHP:
Ver original<?php
require_once 'Zend/Application/Resource/ResourceAbstract.php';
require_once '/../../vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php';
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\DBAL\Types\Type,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSqlLogger;
class Doctrine_Zend_Doctrine extends Zend_Application_Resource_ResourceAbstract
{
public function init()
{
$options = $this -> getOptions();
// Doctrine (use include_path)
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
$classLoader -> register();
// Entities
$classLoader = new \Doctrine\Common\ClassLoader
('Application\Models',dirname(APPLICATION_PATH
) . DIRECTORY_SEPARATOR . 'library'); $classLoader -> register();
//Proxies
$classLoader = new \Doctrine\Common\ClassLoader
('Application\Proxies', dirname ( APPLICATION_PATH
) . DIRECTORY_SEPARATOR . 'library' ); $classLoader -> register();
//Repositories
$classLoader = new \Doctrine\Common\ClassLoader
('Application\Repositories',dirname(APPLICATION_PATH
) . DIRECTORY_SEPARATOR . 'library'); $classLoader -> register();
// Now configure doctrine
if ('development' == APPLICATION_ENV) {
$cacheClass = isset($options['cacheClass']) ?
$options['cacheClass'] : APPLICATION_PATH
.'\library\vendor\doctrine\cache\lib\Doctrine\Common\Cache\ArrayCache'; //vendor\doctrine\cache\lib\Doctrine\Common\Cache\MemcacheCache
} else {
$cacheClass = isset($options['cacheClass']) ?
$options['cacheClass'] : 'Doctrine\Common\Cache\ApcCache'; }
$cache = new $cacheClass();
$config = new Configuration();
$config -> setMetadataCacheImpl($cache);
$config -> setMetadataDriverImpl(Doctrine\ORM\Mapping\Driver\AnnotationDriver
::create(array($options['entitiesPath']))); $config -> setQueryCacheImpl($cache);
$config -> setProxyDir($options['proxiesPath']);
$config -> setProxyNamespace('Application\Proxies');
$config -> setAutoGenerateProxyClasses(('development' == APPLICATION_PATH));
$em = EntityManager::create(
$this -> _buildConnectionOptions($options['connection']),
$config
);
Zend_Registry::set('em', $em);
// end
return $em;
}
protected function _buildConnectionOptions
(array $options) {
'pdo_sqlite' => array('user', 'password', 'path', 'memory'), 'pdo_mysql' => array('user', 'password', 'host', 'port', 'dbname', 'unix_socket'), 'pdo_pgsql' => array('user', 'password', 'host', 'port', 'dbname'), 'pdo_oci' => array('user', 'password', 'host', 'port', 'dbname', 'charset') );
'driver' => $options['driver']
);
foreach ($connectionSpec[$options['driver']] as $driverOption) {
if (isset($options[$driverOption]) && !is_null($driverOption)) { $connection[$driverOption] = $options[$driverOption];
}
}
if (isset($options['driverOptions']) && !is_null($options['driverOptions'])) { $connection['driverOptions'] = $options['driverOptions'];
}
return $connection;
}
}