Skip to content

Commit

Permalink
Update Email to use the StaticConfigTrait.
Browse files Browse the repository at this point in the history
Fix an issue in the trait where errors would be generated by
implementing classes lacking a $_registry property.
  • Loading branch information
markstory committed Aug 26, 2013
1 parent 4a7ede1 commit 2bed467
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Core/StaticConfigTrait.php
Expand Up @@ -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]);
Expand Down
51 changes: 11 additions & 40 deletions lib/Cake/Network/Email/Email.php
Expand Up @@ -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;
Expand All @@ -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
*
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 2bed467

Please sign in to comment.