diff --git a/README.md b/README.md index 2eed0d3..54985ab 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,26 @@ TypehintableBehavior The **TypehintableBehavior** behavior allows you to add typehints to generated methods (in _Base_ classes). +_This is experimental branch with support for the upcoming Propel2._ + Installation ------------ -Cherry-pick the `TypehintableBehavior.php` file is `src/`, put it somewhere, -then add the following line to your `propel.ini` or `build.properties` configuration file: +The easiest way is through [Composer](https://github.com/composer/composer). Just add the following requirement to your project's `composer.json`: + +``` json +{ + "require": { + "willdurand/propel-typehintable-behavior": "~2.0@dev" + } +} +``` + +Then call -``` ini -propel.behavior.typehintable.class = path.to.TypehintableBehavior +``` bash +$ php composer.phar install ``` diff --git a/composer.json b/composer.json index ead7d97..da0adb1 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,13 @@ "email": "william.durand1@gmail.com" } ], + "type" : "propel-behavior", + "extra": { + "name": "typehintable", + "class": "TypehintableBehavior" + }, "require": { - "propel/propel1": "~1.6" + "propel/propel": "2.0.*@dev" }, "autoload": { "classmap": ["src/"] diff --git a/src/TypehintableBehavior.php b/src/TypehintableBehavior.php index 6c006d0..2f46b44 100644 --- a/src/TypehintableBehavior.php +++ b/src/TypehintableBehavior.php @@ -7,12 +7,18 @@ * * @license MIT License */ +use Propel\Generator\Builder\Om\ObjectBuilder; +use Propel\Generator\Model\Behavior; /** * @author William Durand */ class TypehintableBehavior extends Behavior { + protected $parameters = array( + 'nullable_columns' => null, + ); + private $refFKs = array(); private $crossFKs = array(); @@ -23,16 +29,16 @@ class TypehintableBehavior extends Behavior private $scalars = array('array', 'callable'); - public function objectMethods($builder) + public function objectMethods(ObjectBuilder $builder) { if (null !== $this->getParameter('nullable_columns')) { foreach (explode(',', $this->getParameter('nullable_columns')) as $column) { $this->nullables[] = trim($column); } - - unset($this->parameters['nullable_columns']); } + unset($this->parameters['nullable_columns']); + foreach ($this->getParameters() as $class) { if (!in_array($class, $this->scalars)) { $builder->declareClass($class); @@ -51,8 +57,9 @@ public function objectFilter(&$script) } foreach ($this->getTable()->getCrossFks() as $fkList) { - list($refFK, $crossFK) = $fkList; - $this->crossFKs[$crossFK->getForeignTable()->getName()] = $crossFK->getRefPhpName() ?: $crossFK->getForeignTable()->getPhpName(); + foreach ($fkList->getCrossForeignKeys() as $crossFK) { + $this->crossFKs[$crossFK->getForeignTable()->getName()] = $crossFK->getRefPhpName() ?: $crossFK->getForeignTable()->getPhpName(); + } } foreach ($this->getTable()->getForeignKeys() as $fk) { diff --git a/tests/TypehintableBehaviorTest.php b/tests/TypehintableBehaviorTest.php index 244870f..fe0aac9 100644 --- a/tests/TypehintableBehaviorTest.php +++ b/tests/TypehintableBehaviorTest.php @@ -16,6 +16,7 @@ class TypehintableBehaviorTest extends \PHPUnit_Framework_TestCase { private $schema; + private $con; public function setUp() { @@ -38,7 +39,7 @@ public function setUp() - + @@ -66,12 +67,7 @@ public function setUp() EOF; if (!class_exists('TypehintedObject')) { - $builder = new PropelQuickBuilder(); - $config = $builder->getConfig(); - $config->setBuildProperty('behavior.typehintable.class', __DIR__.'/../src/TypehintableBehavior'); - $builder->setConfig($config); - $builder->setSchema($this->schema); - $builder->build(); + $this->con = \Propel\Generator\Util\QuickBuilder::buildSchema($this->schema); } } @@ -134,7 +130,7 @@ public function testTypehintOnManyToManyRelationRemover() $ref = new ReflectionClass('TypehintedUser'); $parameters = $ref->getMethod('removeTypehintedGroup')->getParameters(); - $this->assertEquals('BaseTypehintedGroup', $parameters[0]->getClass()->getName()); + $this->assertEquals('Base\TypehintedGroup', $parameters[0]->getClass()->getName()); } public function testTypehintIsNullable() @@ -156,6 +152,6 @@ public function testSchemaIsValid() $xml = new DOMDocument(); $xml->loadXML($this->schema); - $this->assertTrue($xml->schemaValidate(__DIR__ . '/../vendor/propel/propel1/generator/resources/xsd/database.xsd')); + $this->assertTrue($xml->schemaValidate(__DIR__ . '/../vendor/propel/propel/resources/xsd/database.xsd')); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9013322..5ca31dd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,5 @@