Skip to content

Commit

Permalink
Merge pull request propelorm#816 from fzerorubigd/master
Browse files Browse the repository at this point in the history
First try to load platform from the user provided build properties, try ...
  • Loading branch information
willdurand committed Jan 14, 2014
2 parents 1eda8f3 + 82a7a32 commit e53ccc8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
7 changes: 4 additions & 3 deletions generator/lib/config/GeneratorConfig.php
Expand Up @@ -164,11 +164,12 @@ public function getBuilderClassname($type)
public function getConfiguredPlatform(PDO $con = null, $database = null)
{
$buildConnection = $this->getBuildConnection($database);
if (null !== $buildConnection['adapter']) {
$clazz = Phing::import('platform.' . ucfirst($buildConnection['adapter']) . 'Platform');
} elseif ($this->getBuildProperty('platformClass')) {
//First try to load platform from the user provided build properties
if ($this->getBuildProperty('platformClass')) {
// propel.platform.class = platform.${propel.database}Platform by default
$clazz = $this->getClassname('platformClass');
} elseif (null !== $buildConnection['adapter']) {
$clazz = Phing::import('platform.' . ucfirst($buildConnection['adapter']) . 'Platform');
} else {
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/generator/platform/CustomPlatform.php
@@ -0,0 +1,6 @@
<?php

class CustomPlatform extends DefaultPlatform
{

}
19 changes: 19 additions & 0 deletions test/fixtures/generator/platform/buildtime-conf.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<log>
<level>7</level>
</log>
<propel>
<datasources>
<datasource id="default">
<!-- I want to use this platform but with my custom platform -->
<adapter>pgsql</adapter>
<connection>
<dsn>pgsql:host=localhost;port=5432;dbname=postgres;</dsn>
<user>postgres</user>
<password>password</password>
</connection>
</datasource>
</datasources>
</propel>
</config>
31 changes: 31 additions & 0 deletions test/testsuite/generator/platform/CustomPlatformTest.php
@@ -0,0 +1,31 @@
<?php

class CustomPlatformTest extends PHPUnit_Framework_TestCase
{
/**
* @var GeneratorConfig
*/
protected $generatorConfig;

public function setUp()
{
$projectDir = realpath(__DIR__ . '/../../../fixtures/generator/platform/');
$platformClass = str_replace('/', '.', $projectDir) . '.CustomPlatform';
$props = array(
"propel.project" => "kfw-propel",
"propel.database" => "pgsql", // Or anything else
"propel.projectDir" => $projectDir,
"propel.platform.class" => $platformClass,
"propel.buildtime.conf.file" => "buildtime-conf.xml"

);

$this->generatorConfig = new GeneratorConfig($props);
}

public function testGetPLatform()
{
$this->assertInstanceOf('CustomPlatform', $this->generatorConfig->getConfiguredPlatform());
$this->assertInstanceOf('CustomPlatform', $this->generatorConfig->getConfiguredPlatform(null, 'default'));
}
}

0 comments on commit e53ccc8

Please sign in to comment.