Skip to content

Commit

Permalink
Fixed Table::setInterface(), Table::getInterface() usages
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed May 2, 2012
1 parent 1fd5b18 commit f747823
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
9 changes: 5 additions & 4 deletions generator/lib/builder/om/ClassTools.php
Expand Up @@ -25,11 +25,12 @@ class ClassTools
*/
public static function classname($qualifiedName)
{
$pos = strrpos($qualifiedName, '.');
if ($pos === false) {
return $qualifiedName; // there is no '.' in the qualifed name
} else {
if (false !== $pos = strrpos($qualifiedName, '.')) {
return substr($qualifiedName, $pos + 1); // start just after '.'
} elseif (false !== $pos = strrpos($qualifiedName, '\\')) {
return substr($qualifiedName, $pos + 1);
} else {
return $qualifiedName; // there is no '.' in the qualifed name
}
}

Expand Down
14 changes: 8 additions & 6 deletions generator/lib/builder/om/PHP5ObjectBuilder.php
Expand Up @@ -198,12 +198,14 @@ protected function addClassOpen(&$script)
*/
abstract class ".$this->getClassname()." extends ".$parentClass." ";

$interface = ClassTools::getInterface($table);
if ($interface) {
$script .= " implements " . ClassTools::classname($interface);
}
if ($this->getTable()->getInterface()) {
$this->declareClassFromBuilder($this->getInterfaceBuilder());
if ($interface = $this->getTable()->getInterface()) {
$script .= "implements " . ClassTools::classname($interface);

if ($interface !== ClassTools::classname($interface)) {
$this->declareClass($interface);
} else {
$this->declareClassFromBuilder($this->getInterfaceBuilder());
}
}

$script .= "
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/util/PropelQuickBuilder.php
Expand Up @@ -184,7 +184,7 @@ public function getClassesForTable(Table $table, array $classTargets = null)
}

if ($table->getInterface()) {
$script .= $this->getConfig()->getConfiguredBuilder('interface', $target)->build();
$script .= $this->getConfig()->getConfiguredBuilder($table, 'interface')->build();
}

if ($table->treeMode()) {
Expand Down
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

require_once dirname(__FILE__) . '/../../../../../generator/lib/util/PropelQuickBuilder.php';

class GeneratedObjectWithInterfaceTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!class_exists('Foo\MyClassWithInterface')) {
$schema = <<<EOF
<database name="a-database" namespace="Foo">
<table name="my_class_with_interface" interface="MyInterface">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="name" type="VARCHAR" />
</table>
</database>
EOF;
$builder = new PropelQuickBuilder();
$builder->setSchema($schema);
$builder->buildClasses();
}
}

public function testClassHasInterface()
{
$this->assertInstanceOf('Foo\MyInterface', new \Foo\MyClassWithInterface());
}
}

0 comments on commit f747823

Please sign in to comment.