Permalink
Browse files

[Generator] Added more methods to the GeneratorConfigInterface, allow…

…ed to load behaviors from a QuickGeneratorConfig instance
  • Loading branch information...
1 parent d6506a5 commit 3d68575d18ab628371b3e6a4d51419e05c297e23 @willdurand willdurand committed Apr 10, 2012
View
4 generator/lib/builder/util/XmlToAppData.php
@@ -70,9 +70,9 @@ public function __construct(PropelPlatformInterface $defaultPlatform = null, $de
/**
* Set the AppData generator configuration
*
- * @param GeneratorConfig $generatorConfig
+ * @param GeneratorConfigInterface $generatorConfig
*/
- public function setGeneratorConfig(GeneratorConfig $generatorConfig)
+ public function setGeneratorConfig(GeneratorConfigInterface $generatorConfig)
{
$this->app->setGeneratorConfig($generatorConfig);
}
View
20 generator/lib/config/GeneratorConfigInterface.php
@@ -9,7 +9,6 @@
*/
/**
- *
* @package propel.generator.config
*/
interface GeneratorConfigInterface
@@ -21,29 +20,38 @@
* @param string $type The type of builder ('ddl', 'sql', etc.)
* @return DataModelBuilder
*/
- public function getConfiguredBuilder(Table $table, $type);
+ function getConfiguredBuilder(Table $table, $type);
/**
* Gets a configured Pluralizer class.
*
* @return Pluralizer
*/
- public function getConfiguredPluralizer();
+ function getConfiguredPluralizer();
/**
* Gets a specific propel (renamed) property from the build.
*
* @param string $name
* @return mixed
*/
- public function getBuildProperty($name);
+ function getBuildProperty($name);
/**
* Sets a specific propel (renamed) property from the build.
*
* @param string $name
* @param mixed $value
*/
- public function setBuildProperty($name, $value);
+ function setBuildProperty($name, $value);
+
+ /**
+ * Creates and configures a new Platform class.
+ */
+ function getConfiguredPlatform(PDO $con = null, $database = null);
-}
+ /**
+ * Gets a configured behavior class
+ */
+ function getConfiguredBehavior($name);
+}
View
32 generator/lib/config/QuickGeneratorConfig.php
@@ -10,6 +10,7 @@
require_once dirname(__FILE__) . '/GeneratorConfig.php';
require_once dirname(__FILE__) . '/GeneratorConfigInterface.php';
+require_once dirname(__FILE__) . '/../platform/DefaultPlatform.php';
/**
*
@@ -39,6 +40,8 @@ class QuickGeneratorConfig implements GeneratorConfigInterface
protected $buildProperties = array();
+ private $generatorConfig = null;
+
public function __construct()
{
$this->setBuildProperties($this->parsePseudoIniFile(dirname(__FILE__) . '/../../default.properties'));
@@ -145,4 +148,31 @@ public function setBuildProperty($name, $value)
$this->buildProperties[$name] = $value;
}
-}
+ /**
+ * {@inheritdoc}
+ */
+ public function getConfiguredPlatform(PDO $con = null, $database = null)
+ {
+ return new DefaultPlatform($con);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getConfiguredBehavior($name)
+ {
+ $this->initGeneratorConfig();
+
+ return $this->generatorConfig->getConfiguredBehavior($name);
+ }
+
+ private function initGeneratorConfig()
+ {
+ if (null === $this->generatorConfig) {
+ $this->generatorConfig = new GeneratorConfig();
+ foreach ($this->buildProperties as $key => $value) {
+ $this->generatorConfig->setBuildProperty($key, $value);
+ }
+ }
+ }
+}
View
4 generator/lib/model/AppData.php
@@ -89,9 +89,9 @@ public function getPlatform()
/**
* Set the generator configuration
*
- * @param GeneratorConfig $generatorConfig
+ * @param GeneratorConfigInterface $generatorConfig
*/
- public function setGeneratorConfig(GeneratorConfig $generatorConfig)
+ public function setGeneratorConfig(GeneratorConfigInterface $generatorConfig)
{
$this->generatorConfig = $generatorConfig;
}

0 comments on commit 3d68575

Please sign in to comment.