Browse Source

Fixed `Mailer` does not check if property is public, while configuring 'Swift' object

tags/2.0.5
Klimov Paul 10 years ago
parent
commit
fffcd50b35
  1. 1
      CHANGELOG.md
  2. 7
      Mailer.php

1
CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 swiftmailer extension Change Log
2.0.5 under development
-----------------------
- Bug #9: Fixed `Mailer` does not check if property is public, while configuring 'Swift' object (brandonkelly, klimov-paul)
2.0.4 May 10, 2015

7
Mailer.php

@ -212,6 +212,7 @@ class Mailer extends BaseMailer
} else {
throw new InvalidConfigException('Object configuration must be an array containing a "class" element.');
}
if (isset($config['constructArgs'])) {
$args = [];
foreach ($config['constructArgs'] as $arg) {
@ -226,13 +227,15 @@ class Mailer extends BaseMailer
} else {
$object = Yii::createObject($className);
}
if (!empty($config)) {
$reflection = new \ReflectionObject($object);
foreach ($config as $name => $value) {
if (property_exists($object, $name)) {
if ($reflection->hasProperty($name) && $reflection->getProperty($name)->isPublic()) {
$object->$name = $value;
} else {
$setter = 'set' . $name;
if (method_exists($object, $setter) || method_exists($object, '__call')) {
if ($reflection->hasMethod($setter) || $reflection->hasMethod('__call')) {
$object->$setter($value);
} else {
throw new InvalidConfigException('Setting unknown property: ' . $className . '::' . $name);

Loading…
Cancel
Save