Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Commit

Permalink
Add optional parameter phpName and change namespace for fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Willmann committed Aug 19, 2016
1 parent 89eafeb commit 8303435
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ propel:
generator:
defaultConnection: default
connections: [ default ]
platformClass: \APinnecke\CompositeNumberRange\Platform\MysqlPlatform
platformClass: \FelixWillmann\CompositeNumberRange\Platform\MysqlPlatform
```
## Add behavior to table
Expand All @@ -69,7 +69,7 @@ Following the user <-> document example:
```xml
<table name="document">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<behavior name="\APinnecke\CompositeNumberRange\CompositeNumberRangeBehavior">
<behavior name="\FelixWillmann\CompositeNumberRange\CompositeNumberRangeBehavior">
<parameter name="foreignTable" value="user"/>
</behavior>
</table>
Expand Down Expand Up @@ -101,4 +101,4 @@ $userDocumentId = $document->getUserDocumentId();
## Migrations Notice
Because `propel:migrations:diff` does not know anything about triggers, they have to be checked via SQL Statement. If you use triggers and change something on
any table having triggers appended, they will always appear in your `down()` section of the migration. At the moment you have to remove them by hand,
this bug will be solved in the future during Propel 2 release.
this bug will be solved in the future during Propel 2 release.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "apinnecke/composite-number-range-behavior",
"name": "felixwillmann/composite-number-range-behavior",
"description": "A behavior providing composite number ranges with a foreign key and a composite key.",
"license": "MIT",
"require": {
Expand All @@ -10,7 +10,7 @@
},
"autoload": {
"psr-4": {
"APinnecke\\CompositeNumberRange\\": "src/"
"FelixWillmann\\CompositeNumberRange\\": "src/"
}
},
"authors": [
Expand All @@ -21,6 +21,6 @@
],
"extra": {
"name": "composite_number_range",
"class": "\\APinnecke\\CompositeNumberRange\\CompositeNumberRangeBehavior"
"class": "\\FelixWillmann\\CompositeNumberRange\\CompositeNumberRangeBehavior"
}
}
21 changes: 19 additions & 2 deletions src/CompositeNumberRangeBehavior.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace APinnecke\CompositeNumberRange;
namespace FelixWillmann\CompositeNumberRange;

use Propel\Generator\Model\Behavior;
use Propel\Generator\Model\Column;
Expand All @@ -11,7 +11,8 @@ class CompositeNumberRangeBehavior extends Behavior
{
protected $parameters = array(
'foreignTable' => null,
'refPhpName' => null
'refPhpName' => null,
'phpName' => null,
);

/**
Expand Down Expand Up @@ -46,6 +47,18 @@ protected function getRefPhpName()
return $name;
}

/**
* Gets the phpName parameter from config array.
* will only be set if !== null
*
* @return string
*/
protected function getPhpName()
{
$name = $this->getParameter('phpName');
return $name;
}

/**
* Adds all columns, indexes, constraints and additional tables.
*/
Expand All @@ -54,6 +67,7 @@ public function modifyTable()
$table = $this->getTable();
$tableName = $table->getName();
$foreignTableName = $this->getForeignTable();
$phpName = $this->getPhpName();

// enable reload on insert to force the model to load the trigger generated id(s)
$table->setReloadOnInsert(true);
Expand Down Expand Up @@ -90,6 +104,9 @@ public function modifyTable()
$foreignKey->setForeignTableCommonName($foreignTableName);
$foreignKey->setOnUpdate(ForeignKey::CASCADE);
$foreignKey->setOnDelete(ForeignKey::CASCADE);
if (null !== $phpName) {
$foreignKey->setPhpName($phpName);
}
$table->addForeignKey($foreignKey);

}
Expand Down
8 changes: 4 additions & 4 deletions src/Platform/MysqlPlatform.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace APinnecke\CompositeNumberRange\Platform;
namespace FelixWillmann\CompositeNumberRange\Platform;

use APinnecke\CompositeNumberRange\CompositeNumberRangeBehavior;
use FelixWillmann\CompositeNumberRange\CompositeNumberRangeBehavior;
use Propel\Generator\Model\Diff\TableDiff;
use Propel\Generator\Model\Table;
use Propel\Generator\Platform\MysqlPlatform as BaseMysqlPlatform;

class MysqlPlatform extends BaseMysqlPlatform
{
const BEHAVIOR_NAME = '\APinnecke\CompositeNumberRange\CompositeNumberRangeBehavior';
const BEHAVIOR_NAME = '\FelixWillmann\CompositeNumberRange\CompositeNumberRangeBehavior';

/**
* Returns the actual trigger name in the database. Handy if you don't have the behavior definition
Expand Down Expand Up @@ -185,4 +185,4 @@ protected function createTriggerDDL(Table $table)
return $sql;
}

}
}
6 changes: 3 additions & 3 deletions tests/CompositeNumberRangeBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Propel\Tests\Generator\Behavior\CompositeNumberRange;

use APinnecke\CompositeNumberRange\Platform\MysqlPlatform;
use FelixWillmann\CompositeNumberRange\Platform\MysqlPlatform;
use Propel\Generator\Util\QuickBuilder;
use Propel\Runtime\Adapter\Pdo\MysqlAdapter;
use Propel\Runtime\Collection\ObjectCollection;
Expand All @@ -25,7 +25,7 @@ public function setUp()
<table name="child_table">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="name" type="VARCHAR" size="50" required="false" />
<behavior name="\APinnecke\CompositeNumberRange\CompositeNumberRangeBehavior">
<behavior name="\FelixWillmann\CompositeNumberRange\CompositeNumberRangeBehavior">
<parameter name="foreignTable" value="parent_table"/>
</behavior>
</table>
Expand Down Expand Up @@ -159,4 +159,4 @@ public function testInsertThirdRowWithDifferentParentTableIdCreatesAnotherParent
$this->assertEquals($child2->getParentTableChildTableId(), $sequence->getParentTableMaxSequenceId());
}
}


0 comments on commit 8303435

Please sign in to comment.