Skip to content

Commit

Permalink
Applying optimization from 'michaelc' to reduce number of strtolower(…
Browse files Browse the repository at this point in the history
…) calls in AclBehavior. Fixes #972
  • Loading branch information
markstory committed Jul 30, 2010
1 parent 3bda2ce commit 2b1efaf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cake/libs/model/behaviors/acl.php
Expand Up @@ -49,6 +49,7 @@ function setup(&$model, $config = array()) {
$config = array('type' => $config);
}
$this->settings[$model->name] = array_merge(array('type' => 'requester'), (array)$config);
$this->settings[$model->name]['type'] = strtolower($this->settings[$model->name]['type']);

$type = $this->__typeMaps[$this->settings[$model->name]['type']];
if (!class_exists('AclNode')) {
Expand All @@ -73,7 +74,7 @@ function setup(&$model, $config = array()) {
* @link http://book.cakephp.org/view/1322/node
*/
function node(&$model, $ref = null) {
$type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])];
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
if (empty($ref)) {
$ref = array('model' => $model->name, 'foreign_key' => $model->id);
}
Expand All @@ -88,7 +89,7 @@ function node(&$model, $ref = null) {
* @access public
*/
function afterSave(&$model, $created) {
$type = $this->__typeMaps[strtolower($this->settings[$model->alias]['type'])];
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
$parent = $model->parentNode();
if (!empty($parent)) {
$parent = $this->node($model, $parent);
Expand All @@ -113,7 +114,7 @@ function afterSave(&$model, $created) {
* @access public
*/
function afterDelete(&$model) {
$type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])];
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
$node = Set::extract($this->node($model), "0.{$type}.id");
if (!empty($node)) {
$model->{$type}->delete($node);
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/model/behaviors/acl.test.php
Expand Up @@ -174,7 +174,7 @@ class AclPost extends CakeTestModel {
* @var array
* @access public
*/
var $actsAs = array('Acl' => 'controlled');
var $actsAs = array('Acl' => 'Controlled');

/**
* parentNode
Expand Down

0 comments on commit 2b1efaf

Please sign in to comment.