Last active
December 11, 2015 03:48
-
-
Save gbmoretti/4540205 to your computer and use it in GitHub Desktop.
Problema descrito no tópico "Problema com o ClassLoader Doctrine2" do grupo PHPMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ==== Bootstrap da aplicação ==== */ | |
require_once APPLICATION_PATH . '/../library/Doctrine/Common/ClassLoader.php'; | |
use \Doctrine\Common\ClassLoader, | |
Doctrine\ORM\Configuration as DoctrineConfiguration, | |
Doctrine\Common\EventManager as DoctrineEventManager, | |
Doctrine\ORM\EntityManager as DoctrineEntityManager, | |
Doctrine\Common\Cache\ApcCache as DoctrineApcCache, | |
Doctrine\Common\Cache\ArrayCache as DoctrineArrayCache; | |
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { | |
public function _initClassLoaders() { | |
$loader = new ClassLoader('Doctrine\ORM'); | |
$loader->register(); | |
$loader = new ClassLoader('Doctrine\Common'); | |
$loader->register(); | |
$loader = new ClassLoader('Doctrine\DBAL'); | |
$loader->register(); | |
$loader = new ClassLoader('Symfony', 'Doctrine'); | |
$loader->register(); | |
/* $loader = new ClassLoader('Entity', APPLICATION_PATH . '/default/models'); | |
$loader->register(); */ | |
} | |
public function _initAutoLoader() { | |
$autoloader = Zend_Loader_Autoloader::getInstance(); | |
$autoloader->registerNamespace('Doctrine_'); | |
$autoloader->registerNamespace('E2Tecnologia_'); | |
$autoloader->registerNamespace('Twitter_'); | |
} | |
public function _initDoctrineEntityManager() { | |
$this->bootstrap(array('classLoaders', 'doctrineCache')); | |
$zendConfig = $this->getOptions(); | |
// parameters required for connecting to the database. | |
// the required attributes are driver, host, user, password and dbname | |
$connectionParameters = $zendConfig['doctrine']['connectionParameters']; | |
// now initialize the configuration object | |
$configuration = new DoctrineConfiguration(); | |
// the metadata cache is used to avoid parsing all mapping information every time | |
// the framework is initialized. | |
$configuration->setMetadataCacheImpl($this->getResource('doctrineCache')); | |
// for performance reasons, it is also recommended to use a result cache | |
$configuration->setResultCacheImpl($this->getResource('doctrineCache')); | |
// if you set this option to true, Doctrine 2 will generate proxy classes for your entities | |
// on the fly. This has of course impact on the performance and should therefore be disabled | |
// in the production environment | |
$configuration->setAutoGenerateProxyClasses($zendConfig['doctrine']['autoGenerateProxyClasses']); | |
// the directory, where your proxy classes live | |
$configuration->setProxyDir($zendConfig['doctrine']['proxyPath']); | |
// the proxy classes' namespace | |
$configuration->setProxyNamespace($zendConfig['doctrine']['proxyNamespace']); | |
// the next option tells doctrine which description language we want to use for the mapping | |
// information | |
$configuration->setMetadataDriverImpl( | |
$configuration->newDefaultAnnotationDriver( | |
$zendConfig['doctrine']['entityPath'])); | |
// next, we create an event manager | |
$eventManager = new DoctrineEventManager(); | |
// now we have everything required to initialize the entity manager | |
$entityManager = DoctrineEntityManager::create($connectionParameters, $configuration, $eventManager); | |
Zend_Registry::set('em', $entityManager); | |
return $entityManager; | |
} | |
/** | |
* @return Doctrine\Common\CacheProvider | |
*/ | |
public function _initDoctrineCache() { | |
$cache = null; | |
if (APPLICATION_ENV === 'development') { | |
$cache = new DoctrineArrayCache(); | |
} else { | |
$cache = new DoctrineApcCache(); | |
} | |
return $cache; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ==== Bootstrap do módulo Administrativo ==== */ | |
require_once APPLICATION_PATH . '/../library/Doctrine/Common/ClassLoader.php'; | |
use \Doctrine\Common\ClassLoader; | |
class Administrativo_Bootstrap extends Zend_Application_Module_Bootstrap { | |
public function _initClassLoaders() { | |
$loader = new ClassLoader('Administrativo', APPLICATION_PATH . '/entidades'); | |
$loader->register(); | |
} | |
} | |
?> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Administrativo; | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** | |
* @Entity | |
* @Table(name="usuarios_contribuintes") | |
*/ | |
class UsuarioContribuinte { | |
/** | |
* @var int | |
* @Id | |
* @Column(type="integer") | |
* @GeneratedValue | |
*/ | |
protected $id = null; | |
/** | |
* @var int | |
* @Column(type="integer") | |
*/ | |
protected $im = null; | |
/** | |
* @var boolean | |
* @Column(type="boolean") | |
*/ | |
protected $habilitado = null; | |
/** | |
* @var \Adminstrativo\Usuario | |
* @ManyToOne(targetEntity="Usuario", inversedBy="usuarios_contribuintes") | |
* @JoinColumn(name="id_usuario", referencedColumnName="id") | |
**/ | |
protected $usuario = null; | |
/** | |
* @var \Adminstrativo\UsuarioContribuinteAcao[] | |
* @OneToMany(targetEntity="UsuarioContribuinteAcao", mappedBy="usuarios_contribuintes") | |
*/ | |
protected $usuario_contribuinte_acoes = null; | |
public function __construct() { | |
$this->acoes = new ArrayCollection(); | |
} | |
/** | |
* @return integer | |
*/ | |
public function getId() { | |
return $this->id; | |
} | |
/** | |
* @return integer | |
*/ | |
public function getIm() { | |
return $this->im; | |
} | |
/** | |
* @param integer $im | |
*/ | |
public function setIm($im) { | |
$this->im = $im; | |
} | |
/** | |
* @return boolean | |
*/ | |
public function getHabilitado() { | |
return $this->habilitado; | |
} | |
/** | |
* @param boolean $habilitado | |
*/ | |
public function setHabilitado($habilitado) { | |
$this->habilitado = $habilitado; | |
} | |
/** | |
* @return \Administrativo\Usuario | |
*/ | |
public function getUsuario() { | |
return $this->usuario; | |
} | |
/** | |
* @param \Administrativo\Usuario $usuario | |
*/ | |
public function setUsuario($usuario) { | |
$this->usuario = $usuario; | |
} | |
/** | |
* | |
* @return Administrativo\UsuarioContribuinteAcao[] | |
*/ | |
public function getUsuarioContribuinteAcoes() { | |
return $this->usuario_contribuinte_acoes; | |
} | |
public function addUsuarioContribuinteAcao(Administrativo\UsuarioContribuinteAcao $a) { | |
$this->usuario_contribuinte_acoes[] = $a; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Description of UsuarioContribuinteAcao | |
* | |
* @author guilherme | |
*/ | |
namespace Administrativo; | |
/** | |
* @Entity | |
* @Table(name="usuarios_contribuintes_acoes") | |
*/ | |
class UsuarioContribuinteAcao { | |
/** | |
* @var int | |
* @Id | |
* @Column(type="integer") | |
* @GeneratedValue | |
*/ | |
protected $id = null; | |
/** | |
* @var \Adminstrativo\UsuarioContribuinte | |
* @ManyToOne(targetEntity="UsuarioContribuinte", inversedBy="usuarios_contribuintes_acoes") | |
* @JoinColumn(name="id_usuario_contribuinte", referencedColumnName="id") | |
**/ | |
protected $usuario_contribuinte = null; | |
/** | |
* @var \Adminstrativo\Acao | |
* @ManyToOne(targetEntity="Acao", inversedBy="usuarios_contribuintes_acoes") | |
* @JoinColumn(name="id_acao", referencedColumnName="id") | |
**/ | |
protected $acao = null; | |
/** | |
* @return integer | |
*/ | |
public function getId() { | |
return $this->id; | |
} | |
/** | |
* @return \Administrativo\UsuarioContribuinte | |
*/ | |
public function getUsuarioContribuinte() { | |
return $this->usuario_contribuinte; | |
} | |
/** | |
* @param \Administrativo\UsuarioContribuinte $usuario_contribuinte | |
*/ | |
public function setUsuarioContribuinte($usuario_contribuinte) { | |
$this->usuario_contribuinte = $usuario_contribuinte; | |
} | |
/** | |
* @return \Admnistrativo\Acao | |
*/ | |
public function getAcao() { | |
return $this->acao; | |
} | |
/** | |
* @param \Admnistrativo\Acao $acao | |
*/ | |
public function setAcao($acao) { | |
$this->acao = $acao; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment