Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
b0c5981d
Commit
b0c5981d
authored
Nov 06, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Method names "yii\mail\MessageInterface" simplified.
parent
28b03273
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
48 deletions
+69
-48
Message.php
extensions/swiftmailer/yii/swiftmailer/Message.php
+4
-12
BaseMailer.php
framework/yii/mail/BaseMailer.php
+2
-0
BaseMessage.php
framework/yii/mail/BaseMessage.php
+17
-1
MessageInterface.php
framework/yii/mail/MessageInterface.php
+12
-12
MessageTest.php
tests/unit/extensions/swiftmailer/MessageTest.php
+5
-5
BaseMailerTest.php
tests/unit/framework/mail/BaseMailerTest.php
+25
-14
BaseMessageTest.php
tests/unit/framework/mail/BaseMessageTest.php
+4
-4
No files found.
extensions/swiftmailer/yii/swiftmailer/Message.php
View file @
b0c5981d
...
@@ -42,21 +42,13 @@ class Message extends BaseMessage
...
@@ -42,21 +42,13 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
setC
harset
(
$charset
)
public
function
c
harset
(
$charset
)
{
{
$this
->
getSwiftMessage
()
->
setCharset
(
$charset
);
$this
->
getSwiftMessage
()
->
setCharset
(
$charset
);
return
$this
;
return
$this
;
}
}
/**
/**
* @return string the character set of this message.
*/
public
function
getCharset
()
{
return
$this
->
getSwiftMessage
()
->
getCharset
();
}
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
from
(
$from
)
public
function
from
(
$from
)
...
@@ -167,7 +159,7 @@ class Message extends BaseMessage
...
@@ -167,7 +159,7 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
attach
File
(
$fileName
,
array
$options
=
[])
public
function
attach
(
$fileName
,
array
$options
=
[])
{
{
$attachment
=
\Swift_Attachment
::
fromPath
(
$fileName
);
$attachment
=
\Swift_Attachment
::
fromPath
(
$fileName
);
if
(
!
empty
(
$options
[
'fileName'
]))
{
if
(
!
empty
(
$options
[
'fileName'
]))
{
...
@@ -199,7 +191,7 @@ class Message extends BaseMessage
...
@@ -199,7 +191,7 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
embed
File
(
$fileName
,
array
$options
=
[])
public
function
embed
(
$fileName
,
array
$options
=
[])
{
{
$embedFile
=
\Swift_EmbeddedFile
::
fromPath
(
$fileName
);
$embedFile
=
\Swift_EmbeddedFile
::
fromPath
(
$fileName
);
if
(
!
empty
(
$options
[
'fileName'
]))
{
if
(
!
empty
(
$options
[
'fileName'
]))
{
...
@@ -229,7 +221,7 @@ class Message extends BaseMessage
...
@@ -229,7 +221,7 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
__
toString
()
public
function
toString
()
{
{
return
$this
->
getSwiftMessage
()
->
toString
();
return
$this
->
getSwiftMessage
()
->
toString
();
}
}
...
...
framework/yii/mail/BaseMailer.php
View file @
b0c5981d
...
@@ -46,6 +46,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -46,6 +46,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
* @var array configuration, which should be applied by default to any new created
* @var array configuration, which should be applied by default to any new created
* email message instance.
* email message instance.
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available:
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available:
* - 'charset' argument for [[MessageInterface::charset()]]
* - 'from' argument for [[MessageInterface::from()]]
* - 'from' argument for [[MessageInterface::from()]]
* - 'to' argument for [[MessageInterface::to()]]
* - 'to' argument for [[MessageInterface::to()]]
* - 'cc' argument for [[MessageInterface::cc()]]
* - 'cc' argument for [[MessageInterface::cc()]]
...
@@ -123,6 +124,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -123,6 +124,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
$config
[
'class'
]
=
$this
->
messageClass
;
$config
[
'class'
]
=
$this
->
messageClass
;
}
}
$directSetterNames
=
[
$directSetterNames
=
[
'charset'
,
'from'
,
'from'
,
'to'
,
'to'
,
'cc'
,
'cc'
,
...
...
framework/yii/mail/BaseMessage.php
View file @
b0c5981d
...
@@ -21,7 +21,6 @@ use Yii;
...
@@ -21,7 +21,6 @@ use Yii;
* @see BaseMailer
* @see BaseMailer
*
*
* @property \yii\mail\BaseMailer $mailer mailer component instance. This property is read-only.
* @property \yii\mail\BaseMailer $mailer mailer component instance. This property is read-only.
* @property string $charset the character set of this message.
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
...
@@ -77,4 +76,20 @@ abstract class BaseMessage extends Object implements MessageInterface
...
@@ -77,4 +76,20 @@ abstract class BaseMessage extends Object implements MessageInterface
}
}
return
$this
;
return
$this
;
}
}
/**
* PHP magic method that returns the string representation of this object.
* @return string the string representation of this object.
*/
public
function
__toString
()
{
// __toString cannot throw exception
// use trigger_error to bypass this limitation
try
{
return
$this
->
toString
();
}
catch
(
\Exception
$e
)
{
trigger_error
(
$e
->
getMessage
());
return
''
;
}
}
}
}
\ No newline at end of file
framework/yii/mail/MessageInterface.php
View file @
b0c5981d
...
@@ -33,7 +33,7 @@ interface MessageInterface
...
@@ -33,7 +33,7 @@ interface MessageInterface
* @param string $charset character set name.
* @param string $charset character set name.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
setC
harset
(
$charset
);
public
function
c
harset
(
$charset
);
/**
/**
* Sets message sender.
* Sets message sender.
...
@@ -97,24 +97,24 @@ interface MessageInterface
...
@@ -97,24 +97,24 @@ interface MessageInterface
public
function
html
(
$html
);
public
function
html
(
$html
);
/**
/**
* Attach
specified content as file for
the email message.
* Attach
es existing file to
the email message.
* @param string $
content attachment file content.
* @param string $
fileName full file name
* @param array $options options for embed file. Valid options are:
* @param array $options options for embed file. Valid options are:
* - fileName: name, which should be used to attach file.
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
* - contentType: attached file MIME type.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
attach
Content
(
$content
,
array
$options
=
[]);
public
function
attach
(
$fileName
,
array
$options
=
[]);
/**
/**
* Attach
es existing file to
the email message.
* Attach
specified content as file for
the email message.
* @param string $
fileName full file name
* @param string $
content attachment file content.
* @param array $options options for embed file. Valid options are:
* @param array $options options for embed file. Valid options are:
* - fileName: name, which should be used to attach file.
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
* - contentType: attached file MIME type.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
attach
File
(
$fileName
,
array
$options
=
[]);
public
function
attach
Content
(
$content
,
array
$options
=
[]);
/**
/**
* Attach a file and return it's CID source.
* Attach a file and return it's CID source.
...
@@ -125,7 +125,7 @@ interface MessageInterface
...
@@ -125,7 +125,7 @@ interface MessageInterface
* - contentType: attached file MIME type.
* - contentType: attached file MIME type.
* @return string attachment CID.
* @return string attachment CID.
*/
*/
public
function
embed
File
(
$fileName
,
array
$options
=
[]);
public
function
embed
(
$fileName
,
array
$options
=
[]);
/**
/**
* Attach a content as file and return it's CID source.
* Attach a content as file and return it's CID source.
...
@@ -178,9 +178,8 @@ interface MessageInterface
...
@@ -178,9 +178,8 @@ interface MessageInterface
public
function
body
(
$view
,
$params
=
[]);
public
function
body
(
$view
,
$params
=
[]);
/**
/**
* String output.
* Returns string representation of this message.
* This is PHP magic method that returns string representation of an object.
* @return string the string representation of this message.
* @return string the string representation of the object
*/
*/
public
function
__
toString
();
public
function
toString
();
}
}
\ No newline at end of file
tests/unit/extensions/swiftmailer/MessageTest.php
View file @
b0c5981d
...
@@ -124,12 +124,12 @@ class MessageTest extends VendorTestCase
...
@@ -124,12 +124,12 @@ class MessageTest extends VendorTestCase
$bcc
=
'bccuser@somedomain.com'
;
$bcc
=
'bccuser@somedomain.com'
;
$messageString
=
$this
->
createTestMessage
()
$messageString
=
$this
->
createTestMessage
()
->
setC
harset
(
$charset
)
->
c
harset
(
$charset
)
->
subject
(
$subject
)
->
subject
(
$subject
)
->
to
(
$to
)
->
to
(
$to
)
->
cc
(
$cc
)
->
cc
(
$cc
)
->
bcc
(
$bcc
)
->
bcc
(
$bcc
)
->
__
toString
();
->
toString
();
$this
->
assertContains
(
'charset='
.
$charset
,
$messageString
,
'Incorrect charset!'
);
$this
->
assertContains
(
'charset='
.
$charset
,
$messageString
,
'Incorrect charset!'
);
$this
->
assertContains
(
'Subject: '
.
$subject
,
$messageString
,
'Incorrect "Subject" header!'
);
$this
->
assertContains
(
'Subject: '
.
$subject
,
$messageString
,
'Incorrect "Subject" header!'
);
...
@@ -146,7 +146,7 @@ class MessageTest extends VendorTestCase
...
@@ -146,7 +146,7 @@ class MessageTest extends VendorTestCase
$from
=
'someuser@somedomain.com'
;
$from
=
'someuser@somedomain.com'
;
$messageString
=
$this
->
createTestMessage
()
$messageString
=
$this
->
createTestMessage
()
->
from
(
$from
)
->
from
(
$from
)
->
__
toString
();
->
toString
();
$this
->
assertContains
(
'From: '
.
$from
,
$messageString
,
'Incorrect "From" header!'
);
$this
->
assertContains
(
'From: '
.
$from
,
$messageString
,
'Incorrect "From" header!'
);
$this
->
assertContains
(
'Reply-To: '
.
$from
,
$messageString
,
'Incorrect "Reply-To" header!'
);
$this
->
assertContains
(
'Reply-To: '
.
$from
,
$messageString
,
'Incorrect "Reply-To" header!'
);
}
}
...
@@ -176,7 +176,7 @@ class MessageTest extends VendorTestCase
...
@@ -176,7 +176,7 @@ class MessageTest extends VendorTestCase
$message
->
subject
(
'Yii Swift Attach File Test'
);
$message
->
subject
(
'Yii Swift Attach File Test'
);
$message
->
text
(
'Yii Swift Attach File Test body'
);
$message
->
text
(
'Yii Swift Attach File Test body'
);
$fileName
=
__FILE__
;
$fileName
=
__FILE__
;
$message
->
attach
File
(
$fileName
);
$message
->
attach
(
$fileName
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
...
@@ -216,7 +216,7 @@ class MessageTest extends VendorTestCase
...
@@ -216,7 +216,7 @@ class MessageTest extends VendorTestCase
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$cid
=
$message
->
embed
File
(
$fileName
);
$cid
=
$message
->
embed
(
$fileName
);
$message
->
to
(
$this
->
testEmailReceiver
);
$message
->
to
(
$this
->
testEmailReceiver
);
$message
->
from
(
'someuser@somedomain.com'
);
$message
->
from
(
'someuser@somedomain.com'
);
...
...
tests/unit/framework/mail/BaseMailerTest.php
View file @
b0c5981d
...
@@ -119,6 +119,7 @@ class BaseMailerTest extends TestCase
...
@@ -119,6 +119,7 @@ class BaseMailerTest extends TestCase
$mailer
=
new
Mailer
();
$mailer
=
new
Mailer
();
$notPropertyConfig
=
[
$notPropertyConfig
=
[
'charset'
=>
'utf-16'
,
'from'
=>
'from@domain.com'
,
'from'
=>
'from@domain.com'
,
'to'
=>
'to@domain.com'
,
'to'
=>
'to@domain.com'
,
'cc'
=>
'cc@domain.com'
,
'cc'
=>
'cc@domain.com'
,
...
@@ -144,8 +145,6 @@ class BaseMailerTest extends TestCase
...
@@ -144,8 +145,6 @@ class BaseMailerTest extends TestCase
}
}
}
}
/**
/**
* @depends testGetDefaultView
* @depends testGetDefaultView
*/
*/
...
@@ -217,7 +216,7 @@ class BaseMailerTest extends TestCase
...
@@ -217,7 +216,7 @@ class BaseMailerTest extends TestCase
class
Mailer
extends
BaseMailer
class
Mailer
extends
BaseMailer
{
{
public
$messageClass
=
'yiiunit\framework\mail\Message'
;
public
$messageClass
=
'yiiunit\framework\mail\Message'
;
public
$sentMessages
=
array
()
;
public
$sentMessages
=
[]
;
public
function
send
(
$message
)
public
function
send
(
$message
)
{
{
...
@@ -232,6 +231,7 @@ class Message extends BaseMessage
...
@@ -232,6 +231,7 @@ class Message extends BaseMessage
{
{
public
$id
;
public
$id
;
public
$encoding
;
public
$encoding
;
public
$_charset
;
public
$_from
;
public
$_from
;
public
$_to
;
public
$_to
;
public
$_cc
;
public
$_cc
;
...
@@ -240,52 +240,63 @@ class Message extends BaseMessage
...
@@ -240,52 +240,63 @@ class Message extends BaseMessage
public
$_text
;
public
$_text
;
public
$_html
;
public
$_html
;
public
function
setCharset
(
$charset
)
{}
public
function
charset
(
$charset
)
{
$this
->
_charset
=
$charset
;
return
$this
;
}
public
function
from
(
$from
)
{
public
function
from
(
$from
)
{
$this
->
_from
=
$from
;
$this
->
_from
=
$from
;
return
$this
;
return
$this
;
}
}
public
function
to
(
$to
)
{
public
function
to
(
$to
)
{
$this
->
_to
=
$to
;
$this
->
_to
=
$to
;
return
$this
;
return
$this
;
}
}
public
function
cc
(
$cc
)
{
public
function
cc
(
$cc
)
{
$this
->
_cc
=
$cc
;
$this
->
_cc
=
$cc
;
return
$this
;
return
$this
;
}
}
public
function
bcc
(
$bcc
)
{
public
function
bcc
(
$bcc
)
{
$this
->
_bcc
=
$bcc
;
$this
->
_bcc
=
$bcc
;
return
$this
;
return
$this
;
}
}
public
function
subject
(
$subject
)
{
public
function
subject
(
$subject
)
{
$this
->
_subject
=
$subject
;
$this
->
_subject
=
$subject
;
return
$this
;
return
$this
;
}
}
public
function
text
(
$text
)
{
public
function
text
(
$text
)
{
$this
->
_text
=
$text
;
$this
->
_text
=
$text
;
return
$this
;
return
$this
;
}
}
public
function
html
(
$html
)
{
public
function
html
(
$html
)
{
$this
->
_html
=
$html
;
$this
->
_html
=
$html
;
return
$this
;
return
$this
;
}
}
public
function
attachContent
(
$content
,
array
$options
=
[])
{}
public
function
attachContent
(
$content
,
array
$options
=
[])
{}
public
function
attach
File
(
$fileName
,
array
$options
=
[])
{}
public
function
attach
(
$fileName
,
array
$options
=
[])
{}
public
function
embed
File
(
$fileName
,
array
$options
=
[])
{}
public
function
embed
(
$fileName
,
array
$options
=
[])
{}
public
function
embedContent
(
$content
,
array
$options
=
[])
{}
public
function
embedContent
(
$content
,
array
$options
=
[])
{}
public
function
__
toString
()
public
function
toString
()
{
{
return
get_class
(
$this
);
return
get_class
(
$this
);
}
}
...
...
tests/unit/framework/mail/BaseMessageTest.php
View file @
b0c5981d
...
@@ -116,7 +116,7 @@ class TestMessage extends BaseMessage
...
@@ -116,7 +116,7 @@ class TestMessage extends BaseMessage
public
$text
;
public
$text
;
public
$html
;
public
$html
;
public
function
setC
harset
(
$charset
)
{}
public
function
c
harset
(
$charset
)
{}
public
function
from
(
$from
)
{}
public
function
from
(
$from
)
{}
...
@@ -138,13 +138,13 @@ class TestMessage extends BaseMessage
...
@@ -138,13 +138,13 @@ class TestMessage extends BaseMessage
public
function
attachContent
(
$content
,
array
$options
=
[])
{}
public
function
attachContent
(
$content
,
array
$options
=
[])
{}
public
function
attach
File
(
$fileName
,
array
$options
=
[])
{}
public
function
attach
(
$fileName
,
array
$options
=
[])
{}
public
function
embed
File
(
$fileName
,
array
$options
=
[])
{}
public
function
embed
(
$fileName
,
array
$options
=
[])
{}
public
function
embedContent
(
$content
,
array
$options
=
[])
{}
public
function
embedContent
(
$content
,
array
$options
=
[])
{}
public
function
__
toString
()
public
function
toString
()
{
{
return
get_class
(
$this
);
return
get_class
(
$this
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment