Permalink
Browse files

Changed how behaviors are loaded

  • Loading branch information...
1 parent b3ac8ec commit 9c79cde4bcefa4f58e03e136bb87ee9a0ccfa44f @willdurand willdurand committed Dec 21, 2011
Showing with 15 additions and 17 deletions.
  1. +6 −9 src/Propel/Generator/Config/GeneratorConfig.php
  2. +9 −8 src/Propel/Generator/Model/XmlElement.php
@@ -10,17 +10,13 @@
namespace Propel\Generator\Config;
+use Propel\Generator\Exception\BuildException;
use Propel\Generator\Model\Table;
use Propel\Generator\Platform\PlatformInterface;
use Propel\Generator\Reverse\SchemaParserInterface;
use \PDO;
-// Phing dependencies
-require_once 'phing/Phing.php';
-use \Phing;
-use \BuildException;
-
/**
* A class that holds build properties and provide a class loading mechanism for the generator.
*
@@ -32,11 +28,12 @@ class GeneratorConfig implements GeneratorConfigInterface
/**
* The build properties.
*
- * @var array
+ * @var array
*/
private $buildProperties = array();
protected $buildConnections = null;
+
protected $defaultBuildConnection = null;
/**
@@ -45,7 +42,9 @@ class GeneratorConfig implements GeneratorConfigInterface
*/
public function __construct($props = null)
{
- if ($props) $this->setBuildProperties($props);
+ if ($props) {
+ $this->setBuildProperties($props);
+ }
}
/**
@@ -136,8 +135,6 @@ public function getClassname($propname)
throw new BuildException("Unable to find class path for '$propname' property.");
}
- $clazz = Phing::import($classpath);
-
return $clazz;
}
@@ -10,7 +10,7 @@
namespace Propel\Generator\Model;
-use Propel\Generator\Exception\InvalidArgumentException;
+use Propel\Generator\Exception\BehaviorNotFoundException;
/**
* An abstract class for elements represented by XML tags (e.g. Column, Table).
@@ -133,12 +133,11 @@ public function getVendorInfoForType($type)
/**
* Find the best class name for a given behavior
- * Looks in build.properties for path like propel.behavior.[bname].class
- * If not found, tries to autoload [Bname]Behavior
+ * If not found, tries to autoload \Propel\Generator\Behavior\[Bname]\[Bname]Behavior
* If no success, returns 'Behavior'
*
- * @param string $bname behavior name, e.g. 'timestampable'
- * @return string behavior class name, e.g. 'TimestampableBehavior'
+ * @param string $bname A behavior name, e.g. 'timestampable'
+ * @return string A behavior class name, e.g. '\Propel\Generator\Behavior\Timestampable\TimestampableBehavior'
*/
public function getConfiguredBehavior($bname)
{
@@ -147,13 +146,15 @@ public function getConfiguredBehavior($bname)
return $class;
}
}
- // fallback: maybe the behavior is loaded or autoloaded
+
$gen = new PhpNameGenerator();
- if(class_exists($class = '\\Propel\\Generator\\Behavior\\' . $gen->generateName(array($bname, PhpNameGenerator::CONV_METHOD_PHPNAME)) . 'Behavior')) {
+ $phpName = $gen->generateName(array($bname, PhpNameGenerator::CONV_METHOD_PHPNAME));
+
+ if(class_exists($class = sprintf('\\Propel\\Generator\\Behavior\\%s\\%sBehavior', $phpName, $phpName))) {
return $class;
}
- throw new InvalidArgumentException(sprintf('Unknown behavior "%s"; make sure you configured the propel.behavior.%s.class setting in your build.properties', $bname, $bname));
+ throw new BehaviorNotFoundException(sprintf('Unknown behavior "%s"', $bname));
}
/**

0 comments on commit 9c79cde

Please sign in to comment.