Skip to content

Commit

Permalink
Changed how behaviors are loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Dec 22, 2011
1 parent b3ac8ec commit 9c79cde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
15 changes: 6 additions & 9 deletions src/Propel/Generator/Config/GeneratorConfig.php
Expand Up @@ -10,17 +10,13 @@


namespace Propel\Generator\Config; namespace Propel\Generator\Config;


use Propel\Generator\Exception\BuildException;
use Propel\Generator\Model\Table; use Propel\Generator\Model\Table;
use Propel\Generator\Platform\PlatformInterface; use Propel\Generator\Platform\PlatformInterface;
use Propel\Generator\Reverse\SchemaParserInterface; use Propel\Generator\Reverse\SchemaParserInterface;


use \PDO; 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. * A class that holds build properties and provide a class loading mechanism for the generator.
* *
Expand All @@ -32,11 +28,12 @@ class GeneratorConfig implements GeneratorConfigInterface
/** /**
* The build properties. * The build properties.
* *
* @var array * @var array
*/ */
private $buildProperties = array(); private $buildProperties = array();


protected $buildConnections = null; protected $buildConnections = null;

protected $defaultBuildConnection = null; protected $defaultBuildConnection = null;


/** /**
Expand All @@ -45,7 +42,9 @@ class GeneratorConfig implements GeneratorConfigInterface
*/ */
public function __construct($props = null) public function __construct($props = null)
{ {
if ($props) $this->setBuildProperties($props); if ($props) {
$this->setBuildProperties($props);
}
} }


/** /**
Expand Down Expand Up @@ -136,8 +135,6 @@ public function getClassname($propname)
throw new BuildException("Unable to find class path for '$propname' property."); throw new BuildException("Unable to find class path for '$propname' property.");
} }


$clazz = Phing::import($classpath);

return $clazz; return $clazz;
} }


Expand Down
17 changes: 9 additions & 8 deletions src/Propel/Generator/Model/XmlElement.php
Expand Up @@ -10,7 +10,7 @@


namespace Propel\Generator\Model; 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). * An abstract class for elements represented by XML tags (e.g. Column, Table).
Expand Down Expand Up @@ -133,12 +133,11 @@ public function getVendorInfoForType($type)


/** /**
* Find the best class name for a given behavior * 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 \Propel\Generator\Behavior\[Bname]\[Bname]Behavior
* If not found, tries to autoload [Bname]Behavior
* If no success, returns 'Behavior' * If no success, returns 'Behavior'
* *
* @param string $bname behavior name, e.g. 'timestampable' * @param string $bname A behavior name, e.g. 'timestampable'
* @return string behavior class name, e.g. 'TimestampableBehavior' * @return string A behavior class name, e.g. '\Propel\Generator\Behavior\Timestampable\TimestampableBehavior'
*/ */
public function getConfiguredBehavior($bname) public function getConfiguredBehavior($bname)
{ {
Expand All @@ -147,13 +146,15 @@ public function getConfiguredBehavior($bname)
return $class; return $class;
} }
} }
// fallback: maybe the behavior is loaded or autoloaded
$gen = new PhpNameGenerator(); $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; 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));
} }


/** /**
Expand Down

0 comments on commit 9c79cde

Please sign in to comment.