Permalink
Browse files

Merge pull request #276 from havvg/patch-1

make class targets selectable
  • Loading branch information...
2 parents e95a5d4 + 84df995 commit af6994e3548b78011ff460eef279fbb78d65be92 @willdurand willdurand committed Feb 2, 2012
@@ -15,6 +15,13 @@ class PropelQuickBuilder
{
protected $schema, $platform, $config, $database;
+ protected $classTargets = array('tablemap', 'peer', 'object', 'query', 'peerstub', 'objectstub', 'querystub');
+
+ public function setClassTargets(array $targets)
+ {
+ $this->classTargets = $targets;
+ }
+
public function setSchema($schema)
{
$this->schema = $schema;
@@ -75,18 +82,21 @@ public static function buildSchema($schema, $dsn = null, $user = null, $pass = n
return $builder->build($dsn, $user, $pass, $adapter);
}
- public function build($dsn = null, $user = null, $pass = null, $adapter = null)
+ public function build($dsn = null, $user = null, $pass = null, $adapter = null, array $classTargets = null)
{
if (null === $dsn) {
$dsn = 'sqlite::memory:';
}
if (null === $adapter) {
$adapter = new DBSQLite();
}
+ if (null === $classTargets) {
+ $classTargets = $this->classTargets;
+ }
$con = new PropelPDO($dsn, $user, $pass);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$this->buildSQL($con);
- $this->buildClasses();
+ $this->buildClasses($classTargets);
$name = $this->getDatabase()->getName();
if (!Propel::isInit()) {
Propel::setConfiguration(array('datasources' => array('default' => $name)));
@@ -129,25 +139,29 @@ public function getSQL()
return $this->getPlatform()->getAddTablesDDL($this->getDatabase());
}
- public function buildClasses()
+ public function buildClasses(array $classTargets = null)
{
- eval($this->getClasses());
+ eval($this->getClasses($classTargets));
}
- public function getClasses()
+ public function getClasses(array $classTargets = null)
{
$script = '';
foreach ($this->getDatabase()->getTables() as $table) {
- $script .= $this->getClassesForTable($table);
+ $script .= $this->getClassesForTable($table, $classTargets);
}
return $script;
}
- public function getClassesForTable(Table $table)
+ public function getClassesForTable(Table $table, array $classTargets = null)
{
+ if (null === $classTargets) {
+ $classTargets = $this->classTargets;
+ }
+
$script = '';
- foreach (array('tablemap', 'peer', 'object', 'query', 'peerstub', 'objectstub', 'querystub') as $target) {
+ foreach ($classTargets as $target) {
$script .= $this->getConfig()->getConfiguredBuilder($table, $target)->build();
}
@@ -101,6 +101,20 @@ public function testBuildClasses($builder)
$this->assertTrue(QuickBuildFoo1Peer::getTableMap() instanceof QuickBuildFoo1TableMap);
}
+ /**
+ * @dataProvider simpleSchemaProvider
+ */
+ public function testGetClassesLimitedClassTargets($builder)
+ {
+ $script = $builder->getClasses(array('tablemap', 'peer', 'object', 'query'));
+ $this->assertNotContains('class QuickBuildFoo1 extends BaseQuickBuildFoo1', $script);
+ $this->assertNotContains('class QuickBuildFoo1Peer extends BaseQuickBuildFoo1Peer', $script);
+ $this->assertNotContains('class QuickBuildFoo1Query extends BaseQuickBuildFoo1Query', $script);
+ $this->assertContains('class BaseQuickBuildFoo1 extends BaseObject', $script);
+ $this->assertContains('class BaseQuickBuildFoo1Peer', $script);
+ $this->assertContains('class BaseQuickBuildFoo1Query extends ModelCriteria', $script);
+ }
+
public function testBuild()
{
$schema = <<<EOF

0 comments on commit af6994e

Please sign in to comment.