Skip to content

Commit

Permalink
move defaultSettings to Behavior
Browse files Browse the repository at this point in the history
Default settings should _probably_ be defined in all classes which
accept partial config, such as components, helpers and behaviors.
  • Loading branch information
AD7six committed Nov 10, 2013
1 parent 2b4eb46 commit 3663cc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 0 additions & 12 deletions Cake/Model/Behavior/TimestampBehavior.php
Expand Up @@ -55,18 +55,6 @@ class TimestampBehavior extends Behavior {
*/
protected $_ts;

/**
* Constructor
*
* Merge settings with the default and store in the settings property
*
* @param Table $table The table this behavior is attached to.
* @param array $settings The settings for this behavior.
*/
public function __construct(Table $table, array $settings = []) {
$this->_settings = $settings + $this->_defaultSettings;
}

/**
* handleEvent
*
Expand Down
14 changes: 13 additions & 1 deletion Cake/ORM/Behavior.php
Expand Up @@ -101,6 +101,15 @@ class Behavior implements EventListener {
*/
protected static $_reflectionMethods = [];

/**
* Default settings
*
* These are merged with user-provided settings when the behavior is used.
*
* @var array
*/
protected $_defaultSettings = [];

/**
* Contains configuration settings.
*
Expand All @@ -111,14 +120,17 @@ class Behavior implements EventListener {
/**
* Constructor
*
* Merge settings with the default and store in the settings property
*
* Does not retain a reference to the Table object. If you need this
* you should override the constructor.
*
*
* @param Table $table The table this behavior is attached to.
* @param array $settings The settings for this behavior.
*/
public function __construct(Table $table, array $settings = []) {
$this->_settings = $settings;
$this->_settings = $settings + $this->_defaultSettings;
}

/**
Expand Down

0 comments on commit 3663cc9

Please sign in to comment.