Created
February 12, 2015 13:03
-
-
Save andybeak/4989d8e566de421fe762 to your computer and use it in GitHub Desktop.
This fixes the "“class” is not a valid entity or mapped super class". See https://stackoverflow.com/questions/15099060/doctrine2-class-is-not-a-valid-entity-or-mapped-super-class
This file contains hidden or 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 | |
/** | |
* Configures and provides an Entity Manager | |
*/ | |
use Doctrine\ORM\Tools\Setup; | |
use Doctrine\ORM\EntityManager; | |
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; | |
use Doctrine\Common\Annotations\AnnotationReader; | |
use Doctrine\Common\Annotations\AnnotationRegistry; | |
class EntityProvider | |
{ | |
public static $em; | |
private function __construct() | |
{} | |
public static function getInstance() | |
{ | |
if(!is_object(self::$em)) | |
{ | |
$entityPaths = [DE_PATH . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR]; | |
$dbParams = array( | |
'driver' => 'pdo_mysql', | |
'user' => DB_USER, | |
'password' => DB_PASSWORD, | |
'dbname' => DB_NAME, | |
'host' => DB_HOST | |
); | |
$config = Setup::createAnnotationMetadataConfiguration($entityPaths, true); | |
$driver = new AnnotationDriver(new AnnotationReader(), $entityPaths); | |
// registering noop annotation autoloader - allow all annotations by default | |
AnnotationRegistry::registerLoader('class_exists'); | |
$config->setMetadataDriverImpl($driver); | |
self::$em = EntityManager::create($dbParams, $config); | |
} | |
return self::$em; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment