sintonia/library/propel/docs/behavior/alternative_coding_standard...

90 lines
2.4 KiB
Plaintext

= Alternative Coding Standards Behavior =
The `alternative_coding_standards` behavior changes the coding standards of the model classes generated by Propel to match your own coding style.
== Basic Usage ==
In the `schema.xml`, use the `<behavior>` tag to add the `alternative_coding_standards` behavior to a table:
{{{
#!xml
<table name="book">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="title" type="VARCHAR" required="true" primaryString="true" />
<behavior name="alternative_coding_standards" />
</table>
}}}
Rebuild your model, and you're ready to go. The code of the model classes now uses an alternative set of coding standards:
{{{
#!php
<?php
// in om/BaseBook.php
/**
* Set the value of [title] column.
*
* @param string $v new value
* @return Table4 The current object (for fluent API support)
*/
public function setTitle($v)
{
if ($v !== null)
{
$v = (string) $v;
}
if ($this->title !== $v)
{
$this->title = $v;
$this->modifiedColumns[] = BookPeer::TITLE;
}
return $this;
}
// instead of
/**
* Set the value of [title] column.
*
* @param string $v new value
* @return Table4 The current object (for fluent API support)
*/
public function setTitle($v)
{
if ($v !== null) {
$v = (string) $v;
}
if ($this->title !== $v) {
$this->title = $v;
$this->modifiedColumns[] = BookPeer::TITLE;
}
return $this;
} // setTitle()
}}}
The behavior replaces tabulations by whitespace (2 spaces by default), places opening brackets on newlines, removes closing brackets comments, and can even strip every comments in the generated classes if you wish.
== Parameters ==
Each of the new coding style rules has corresponding parameter in the behavior description. Here is the default configuration:
{{{
#!xml
<table name="book">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="title" type="VARCHAR" required="true" primaryString="true" />
<behavior name="alternative_coding_standards">
<parameter name="brackets_newline" value="true" />
<parameter name="remove_closing_comments" value="true" />
<parameter name="use_whitespace" value="true" />
<parameter name="tab_size" value="2" />
<parameter name="strip_comments" value="false" />
</behavior>
</table>
}}}
You can change these settings to better match your own coding styles.