From 9fdc819db075c7d1d69641ca4a290ec2d9a1c6d4 Mon Sep 17 00:00:00 2001 From: AD7six Date: Wed, 6 Nov 2013 17:02:39 +0000 Subject: [PATCH] use array_key_change_case and restructure cache by consistently changing key case, when asking a behavior for which methods it implements, a few strtolower calls can be avoided. Using static::$_cacheProperty gets confused as it is shared by all subclasses... so index the cache by class name. --- Cake/ORM/Behavior.php | 12 ++++++++---- Cake/ORM/BehaviorRegistry.php | 21 ++++----------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Cake/ORM/Behavior.php b/Cake/ORM/Behavior.php index 4eb96bfb99b..ba5d27a90e5 100644 --- a/Cake/ORM/Behavior.php +++ b/Cake/ORM/Behavior.php @@ -92,7 +92,10 @@ class Behavior implements EventListener { /** - * A cache of the methods provided by this class + * Method cache for behaviors. + * + * Stores the reflected method + finder methods per class. + * This prevents reflecting the same class multiple times in a single process. * * @var array */ @@ -228,8 +231,9 @@ public function implementedMethods() { * @return array */ protected function _reflectionMethods() { - if (isset(static::$_reflectionMethods)) { - return static::$_reflectionMethods; + $class = get_class($this); + if (isset(self::$_reflectionMethods[$class])) { + return self::$_reflectionMethods[$class]; } $events = $this->implementedEvents(); @@ -265,7 +269,7 @@ protected function _reflectionMethods() { } } - return static::$_reflectionMethods = $return; + return self::$_reflectionMethods[$class] = $return; } } diff --git a/Cake/ORM/BehaviorRegistry.php b/Cake/ORM/BehaviorRegistry.php index 7fc32eca902..fc2d0a8ef8a 100644 --- a/Cake/ORM/BehaviorRegistry.php +++ b/Cake/ORM/BehaviorRegistry.php @@ -58,16 +58,6 @@ class BehaviorRegistry extends ObjectRegistry { */ protected $_finderMap = []; -/** - * Method cache for behaviors. - * - * Stores the reflected method + finder methods per class. - * This prevents reflecting the same class multiple times in a single process. - * - * @var array - */ - protected static $_methodCache = []; - /** * Constructor * @@ -124,8 +114,8 @@ protected function _create($class, $alias, $settings) { $this->_eventManager->attach($instance); } $methods = $this->_getMethods($instance, $class, $alias); - $this->_methodMap = array_merge($this->_methodMap, $methods['methods']); - $this->_finderMap = array_merge($this->_finderMap, $methods['finders']); + $this->_methodMap += $methods['methods']; + $this->_finderMap += $methods['finders']; return $instance; } @@ -141,11 +131,10 @@ protected function _create($class, $alias, $settings) { * @throws Cake\Error\Exception when duplicate methods are connected. */ protected function _getMethods(Behavior $instance, $class, $alias) { - $finders = $instance->implementedFinders(); - $methods = $instance->implementedMethods(); + $finders = array_change_key_case($instance->implementedFinders()); + $methods = array_change_key_case($instance->implementedMethods()); foreach($finders as $finder => &$methodName) { - $finder = strtolower($finder); if (isset($this->_finderMap[$finder])) { $duplicate = $this->_finderMap[$finder]; $error = __d( @@ -161,8 +150,6 @@ protected function _getMethods(Behavior $instance, $class, $alias) { } foreach($methods as $method => &$methodName) { - $method = strtolower($method); - if (isset($this->_methodMap[$method])) { $duplicate = $this->_methodMap[$method]; $error = __d(