Skip to content

Commit

Permalink
Save table instance reference as behavior property.
Browse files Browse the repository at this point in the history
Many userland behaviors too would need a table reference so better
to save it in core Behavior's constructor itself and avoid overriding constructor.
  • Loading branch information
ADmad committed Nov 2, 2014
1 parent 2db808b commit 06b0e13
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 45 deletions.
19 changes: 0 additions & 19 deletions src/Model/Behavior/CounterCacheBehavior.php
Expand Up @@ -79,25 +79,6 @@
*/
class CounterCacheBehavior extends Behavior {

/**
* Keeping a reference to the table in order to,
* be able to retrieve associations and fetch records for counting.
*
* @var \Cake\ORM\Table
*/
protected $_table;

/**
* Constructor
*
* @param \Cake\ORM\Table $table The table this behavior is attached to.
* @param array $config The config for this behavior.
*/
public function __construct(Table $table, array $config = []) {
parent::__construct($table, $config);
$this->_table = $table;
}

/**
* afterSave callback.
*
Expand Down
8 changes: 0 additions & 8 deletions src/Model/Behavior/TranslateBehavior.php
Expand Up @@ -38,13 +38,6 @@
*/
class TranslateBehavior extends Behavior {

/**
* Table instance
*
* @var \Cake\ORM\Table
*/
protected $_table;

/**
* The locale name that will be used to override fields in the bound table
* from the translations table
Expand Down Expand Up @@ -78,7 +71,6 @@ public function __construct(Table $table, array $config = []) {
$config += ['defaultLocale' => I18n::defaultLocale()];
parent::__construct($table, $config);

$this->_table = $table;
$config = $this->_config;
$this->setupFieldAssociations($config['fields'], $config['translationTable']);
}
Expand Down
18 changes: 0 additions & 18 deletions src/Model/Behavior/TreeBehavior.php
Expand Up @@ -35,13 +35,6 @@
*/
class TreeBehavior extends Behavior {

/**
* Table instance
*
* @var \Cake\ORM\Table
*/
protected $_table;

/**
* Cached copy of the first column in a table's primary key.
*
Expand Down Expand Up @@ -75,17 +68,6 @@ class TreeBehavior extends Behavior {
'scope' => null
];

/**
* Constructor
*
* @param \Cake\ORM\Table $table The table this behavior is attached to.
* @param array $config The config for this behavior.
*/
public function __construct(Table $table, array $config = []) {
parent::__construct($table, $config);
$this->_table = $table;
}

/**
* Before save listener.
* Transparently manages setting the lft and rght fields if the parent field is
Expand Down
8 changes: 8 additions & 0 deletions src/ORM/Behavior.php
Expand Up @@ -103,6 +103,13 @@ class Behavior implements EventListenerInterface {

use InstanceConfigTrait;

/**
* Table instance.
*
* @var \Cake\ORM\Table
*/
protected $_table;

/**
* Reflection method cache for behaviors.
*
Expand Down Expand Up @@ -145,6 +152,7 @@ public function __construct(Table $table, array $config = []) {
$config
);
$this->config($config);
$this->_table = $table;
}

/**
Expand Down

0 comments on commit 06b0e13

Please sign in to comment.