Skip to content

Instantly share code, notes, and snippets.

@caseyamcl
Created September 17, 2015 20:32
Show Gist options
  • Save caseyamcl/db86e1a28ad9fed96cce to your computer and use it in GitHub Desktop.
Save caseyamcl/db86e1a28ad9fed96cce to your computer and use it in GitHub Desktop.
Entity Generator for Doctrine?
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createYAMLMetadataConfiguration(array(__DIR__), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
$mFactory = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
$mFactory->setEntityManager($entityManager);
$entityGenerator = new \Doctrine\ORM\Tools\EntityGenerator();
// We need to build an instance of this: Doctrine\Common\Persistence\Mapping\ClassMetadata
$metadata = '....';
$entityGenerator->setGenerateAnnotations(true);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setNumSpaces(4);
$entityGenerator->setAnnotationPrefix('ORM');
$entityGenerator->setFieldVisibility('protected');
$entityGenerator->generateEntityClass($metadata);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment