Skip to content

Commit da4b48b

Browse files
committed
Change the behavior of Email::config()
Squash and revert a number of changes as they were just a bad idea.
1 parent 39443e3 commit da4b48b

File tree

2 files changed

+118
-89
lines changed

2 files changed

+118
-89
lines changed

lib/Cake/Network/Email/Email.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
22
/**
3-
* Cake E-Mail
4-
*
5-
* PHP 5
6-
*
73
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
84
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
95
*
@@ -17,12 +13,15 @@
1713
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1814
*/
1915
namespace Cake\Network\Email;
16+
2017
use Cake\Core\App;
2118
use Cake\Core\Configure;
2219
use Cake\Error;
2320
use Cake\Log\Log;
21+
use Cake\Utility\Hash;
2422
use Cake\Utility\String;
2523
use Cake\Utility\Validation;
24+
use Cake\View\View;
2625

2726
/**
2827
* Cake e-mail class.
@@ -299,6 +298,14 @@ class Email {
299298
*/
300299
protected $_config = array();
301300

301+
/**
302+
* An array of preconfigured Email types.
303+
*
304+
* @var array
305+
* @see Email::config()
306+
*/
307+
protected static $_preConfig = array();
308+
302309
/**
303310
* 8Bit character sets
304311
*
@@ -331,7 +338,7 @@ public function __construct($config = null) {
331338
}
332339

333340
if ($config) {
334-
$this->config($config);
341+
$this->useConfig($config);
335342
}
336343
if (empty($this->headerCharset)) {
337344
$this->headerCharset = $this->charset;
@@ -1019,19 +1026,36 @@ public function message($type = null) {
10191026
}
10201027

10211028
/**
1022-
* Configuration to use when send email
1029+
* Set configuration to use when sending email later.
1030+
* Typically this is used during bootstrapping to configure
1031+
* presets for email.
10231032
*
1024-
* @param string|array $config String with configuration name (from email.php), array with config or null to return current config
1033+
* @param string $name The name of the config you want set.
1034+
* @param array $config Array of configuration data.
1035+
* @return void
1036+
*/
1037+
public static function config($name, array $config) {
1038+
static::$_preConfig[$name] = $config;
1039+
}
1040+
1041+
/**
1042+
* Sets the configuration for this Email instance.
1043+
*
1044+
* This can be used to load previously loaded configuration
1045+
* data added via Email::config(). Additionally it can be
1046+
* used to augment the existing configuration
1047+
*
1048+
* @param string|array $config String with configuration name, or
1049+
* an array with config or null to return current config.
10251050
* @return string|array|Cake\Network\Email\Email
10261051
*/
1027-
public function config($config = null) {
1052+
public function useConfig($config = null) {
10281053
if ($config === null) {
10291054
return $this->_config;
10301055
}
10311056
if (!is_array($config)) {
10321057
$config = (string)$config;
10331058
}
1034-
10351059
$this->_applyConfig($config);
10361060
return $this;
10371061
}
@@ -1041,7 +1065,7 @@ public function config($config = null) {
10411065
*
10421066
* @param string|array $content String with message or array with messages
10431067
* @return array
1044-
* @throws SocketException
1068+
* @throws Cake\Error\SocketException
10451069
*/
10461070
public function send($content = null) {
10471071
if (empty($this->_from)) {
@@ -1093,7 +1117,7 @@ public static function deliver($to = null, $subject = null, $message = null, $tr
10931117
if (is_array($message)) {
10941118
$instance->viewVars($message);
10951119
$message = null;
1096-
} elseif ($message === null && array_key_exists('message', $config = $instance->config())) {
1120+
} elseif ($message === null && array_key_exists('message', $config = $instance->useConfig())) {
10971121
$message = $config['message'];
10981122
}
10991123

@@ -1114,14 +1138,10 @@ public static function deliver($to = null, $subject = null, $message = null, $tr
11141138
*/
11151139
protected function _applyConfig($config) {
11161140
if (is_string($config)) {
1117-
if (!class_exists('EmailConfig') && !config('email')) {
1118-
throw new Error\ConfigureException(__d('cake_dev', '%s not found.', APP . 'Config' . DS . 'email.php'));
1119-
}
1120-
$configs = new EmailConfig();
1121-
if (!isset($configs->{$config})) {
1141+
if (!isset(static::$_preConfig[$config])) {
11221142
throw new Error\ConfigureException(__d('cake_dev', 'Unknown email configuration "%s".', $config));
11231143
}
1124-
$config = $configs->{$config};
1144+
$config = static::$_preConfig[$config];
11251145
}
11261146
$this->_config += $config;
11271147
if (!empty($config['charset'])) {
@@ -1534,6 +1554,7 @@ protected function _renderTemplates($content) {
15341554
} else {
15351555
$viewClass = App::classname($viewClass, 'View', 'View');
15361556
}
1557+
$viewClass = 'Cake\View\View';
15371558

15381559
$View = new $viewClass(null);
15391560
$View->viewVars = $this->_viewVars;

0 commit comments

Comments
 (0)