1
1
<?php
2
2
/**
3
- * Cake E-Mail
4
- *
5
- * PHP 5
6
- *
7
3
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8
4
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
9
5
*
17
13
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
18
14
*/
19
15
namespace Cake \Network \Email ;
16
+
20
17
use Cake \Core \App ;
21
18
use Cake \Core \Configure ;
22
19
use Cake \Error ;
23
20
use Cake \Log \Log ;
21
+ use Cake \Utility \Hash ;
24
22
use Cake \Utility \String ;
25
23
use Cake \Utility \Validation ;
24
+ use Cake \View \View ;
26
25
27
26
/**
28
27
* Cake e-mail class.
@@ -299,6 +298,14 @@ class Email {
299
298
*/
300
299
protected $ _config = array ();
301
300
301
+ /**
302
+ * An array of preconfigured Email types.
303
+ *
304
+ * @var array
305
+ * @see Email::config()
306
+ */
307
+ protected static $ _preConfig = array ();
308
+
302
309
/**
303
310
* 8Bit character sets
304
311
*
@@ -331,7 +338,7 @@ public function __construct($config = null) {
331
338
}
332
339
333
340
if ($ config ) {
334
- $ this ->config ($ config );
341
+ $ this ->useConfig ($ config );
335
342
}
336
343
if (empty ($ this ->headerCharset )) {
337
344
$ this ->headerCharset = $ this ->charset ;
@@ -1019,19 +1026,36 @@ public function message($type = null) {
1019
1026
}
1020
1027
1021
1028
/**
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.
1023
1032
*
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.
1025
1050
* @return string|array|Cake\Network\Email\Email
1026
1051
*/
1027
- public function config ($ config = null ) {
1052
+ public function useConfig ($ config = null ) {
1028
1053
if ($ config === null ) {
1029
1054
return $ this ->_config ;
1030
1055
}
1031
1056
if (!is_array ($ config )) {
1032
1057
$ config = (string )$ config ;
1033
1058
}
1034
-
1035
1059
$ this ->_applyConfig ($ config );
1036
1060
return $ this ;
1037
1061
}
@@ -1041,7 +1065,7 @@ public function config($config = null) {
1041
1065
*
1042
1066
* @param string|array $content String with message or array with messages
1043
1067
* @return array
1044
- * @throws SocketException
1068
+ * @throws Cake\Error\ SocketException
1045
1069
*/
1046
1070
public function send ($ content = null ) {
1047
1071
if (empty ($ this ->_from )) {
@@ -1093,7 +1117,7 @@ public static function deliver($to = null, $subject = null, $message = null, $tr
1093
1117
if (is_array ($ message )) {
1094
1118
$ instance ->viewVars ($ message );
1095
1119
$ message = null ;
1096
- } elseif ($ message === null && array_key_exists ('message ' , $ config = $ instance ->config ())) {
1120
+ } elseif ($ message === null && array_key_exists ('message ' , $ config = $ instance ->useConfig ())) {
1097
1121
$ message = $ config ['message ' ];
1098
1122
}
1099
1123
@@ -1114,14 +1138,10 @@ public static function deliver($to = null, $subject = null, $message = null, $tr
1114
1138
*/
1115
1139
protected function _applyConfig ($ config ) {
1116
1140
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 ])) {
1122
1142
throw new Error \ConfigureException (__d ('cake_dev ' , 'Unknown email configuration "%s". ' , $ config ));
1123
1143
}
1124
- $ config = $ configs ->{ $ config} ;
1144
+ $ config = static :: $ _preConfig [ $ config] ;
1125
1145
}
1126
1146
$ this ->_config += $ config ;
1127
1147
if (!empty ($ config ['charset ' ])) {
@@ -1534,6 +1554,7 @@ protected function _renderTemplates($content) {
1534
1554
} else {
1535
1555
$ viewClass = App::classname ($ viewClass , 'View ' , 'View ' );
1536
1556
}
1557
+ $ viewClass = 'Cake\View\View ' ;
1537
1558
1538
1559
$ View = new $ viewClass (null );
1539
1560
$ View ->viewVars = $ this ->_viewVars ;
0 commit comments