From 2bed4670dee2b913fc0e35e03042855a3f7e11b0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 26 Aug 2013 13:25:37 -0400 Subject: [PATCH] Update Email to use the StaticConfigTrait. Fix an issue in the trait where errors would be generated by implementing classes lacking a $_registry property. --- lib/Cake/Core/StaticConfigTrait.php | 2 +- lib/Cake/Network/Email/Email.php | 51 +++++++---------------------- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/lib/Cake/Core/StaticConfigTrait.php b/lib/Cake/Core/StaticConfigTrait.php index 62c2d8ed0d8..0800d0a404a 100644 --- a/lib/Cake/Core/StaticConfigTrait.php +++ b/lib/Cake/Core/StaticConfigTrait.php @@ -102,7 +102,7 @@ public static function drop($config) { if (!isset(static::$_config[$config])) { return false; } - if (isset(static::$_registry->{$config})) { + if (isset(static::$_registry) && isset(static::$_registry->{$config})) { static::$_registry->unload($config); } unset(static::$_config[$config]); diff --git a/lib/Cake/Network/Email/Email.php b/lib/Cake/Network/Email/Email.php index 15526b697ad..318a59ca5ae 100644 --- a/lib/Cake/Network/Email/Email.php +++ b/lib/Cake/Network/Email/Email.php @@ -16,6 +16,7 @@ use Cake\Core\App; use Cake\Core\Configure; +use Cake\Core\StaticConfigTrait; use Cake\Error; use Cake\Log\Log; use Cake\Network\Http\FormData\Part; @@ -30,9 +31,19 @@ * * This class is used for sending Internet Message Format based * on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt + * + * ### Configuration + * + * Configuration for Email is managed by Email::config() and Email::configTransport(). + * Email::config() can be used to add or read a configuration profile for Email instances. + * Once made configuration profiles can be used to re-use across various email messages your + * application sends. + * */ class Email { + use StaticConfigTrait; + /** * Default X-Mailer * @@ -1132,46 +1143,6 @@ public static function dropTransport($key) { unset(static::$_transportConfig[$key]); } -/** - * Add or read a configuration profile for Email instances. - * - * This method is used to read or define configuration profiles for - * Email. Once made configuration profiles can be used to re-use the same - * sets of configuration across multiple email messages. - * - * @param string|array $key The name of the configuration profile to read/create - * or an array of multiple configuration profiles to set - * @param null|array $config Null to read config data, an array to set data. - * @return array|void - * @throws Cake\Error\Exception When modifying an existing configuration. - */ - public static function config($key, $config = null) { - // Read config. - if ($config === null && is_string($key)) { - return isset(static::$_config[$key]) ? static::$_config[$key] : null; - } - if ($config === null && is_array($key)) { - foreach ($key as $name => $settings) { - static::config($name, $settings); - } - return; - } - if (isset(static::$_config[$key])) { - throw new Error\Exception(__d('cake_dev', 'Cannot modify an existing config "%s"', $key)); - } - static::$_config[$key] = $config; - } - -/** - * Drop a configured profile. - * - * @param string $key The profile to drop. - * @return void - */ - public static function drop($key) { - unset(static::$_config[$key]); - } - /** * Get/Set the configuration profile to use for this instance. *