|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Joomla! Content Management System |
| 5 | + * |
| 6 | + * @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> |
| 7 | + * @license GNU General Public License version 2 or later; see LICENSE.txt |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Joomla\CMS\Event\Mail; |
| 11 | + |
| 12 | +use Joomla\CMS\Event\AbstractImmutableEvent; |
| 13 | +use Joomla\CMS\Event\ReshapeArgumentsAware; |
| 14 | +use Joomla\CMS\Mail\MailTemplate; |
| 15 | + |
| 16 | +// phpcs:disable PSR1.Files.SideEffects |
| 17 | +\defined('_JEXEC') or die; |
| 18 | +// phpcs:enable PSR1.Files.SideEffects |
| 19 | + |
| 20 | +/** |
| 21 | + * Base class for MailTemplate events |
| 22 | + * |
| 23 | + * @since __DEPLOY_VERSION__ |
| 24 | + */ |
| 25 | +abstract class MailTemplateEvent extends AbstractImmutableEvent |
| 26 | +{ |
| 27 | + use ReshapeArgumentsAware; |
| 28 | + |
| 29 | + /** |
| 30 | + * The argument names, in order expected by legacy plugins. |
| 31 | + * |
| 32 | + * @var array |
| 33 | + * |
| 34 | + * @since __DEPLOY_VERSION__ |
| 35 | + * @deprecated __DEPLOY_VERSION__ will be removed in 6.0 |
| 36 | + */ |
| 37 | + protected $legacyArgumentsOrder = []; |
| 38 | + |
| 39 | + /** |
| 40 | + * Constructor. |
| 41 | + * |
| 42 | + * @param string $name The event name. |
| 43 | + * @param array $arguments The event arguments. |
| 44 | + * |
| 45 | + * @throws \BadMethodCallException |
| 46 | + * |
| 47 | + * @since __DEPLOY_VERSION__ |
| 48 | + */ |
| 49 | + public function __construct($name, array $arguments = []) |
| 50 | + { |
| 51 | + // Reshape the arguments array to preserve b/c with legacy listeners |
| 52 | + if ($this->legacyArgumentsOrder) { |
| 53 | + $arguments = $this->reshapeArguments($arguments, $this->legacyArgumentsOrder); |
| 54 | + } |
| 55 | + |
| 56 | + parent::__construct($name, $arguments); |
| 57 | + |
| 58 | + if (!\array_key_exists('subject', $this->arguments)) { |
| 59 | + throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided"); |
| 60 | + } |
| 61 | + |
| 62 | + if (!\array_key_exists('templateId', $this->arguments)) { |
| 63 | + throw new \BadMethodCallException("Argument 'templateId' of event {$name} is required but has not been provided"); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Pre-Setter for the subject argument. |
| 69 | + * |
| 70 | + * @param MailTemplate $value The value to set |
| 71 | + * |
| 72 | + * @return MailTemplate |
| 73 | + * |
| 74 | + * @since __DEPLOY_VERSION__ |
| 75 | + */ |
| 76 | + protected function onSetSubject(MailTemplate $value): MailTemplate |
| 77 | + { |
| 78 | + return $value; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Pre-getter for the subject argument. |
| 83 | + * |
| 84 | + * @param MailTemplate $value The value to set |
| 85 | + * |
| 86 | + * @return MailTemplate |
| 87 | + * |
| 88 | + * @since __DEPLOY_VERSION__ |
| 89 | + */ |
| 90 | + protected function onGetSubject(MailTemplate $value): MailTemplate |
| 91 | + { |
| 92 | + return $value; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Pre-setter for the templateId argument. |
| 97 | + * |
| 98 | + * @param string $value The value to set |
| 99 | + * |
| 100 | + * @return string |
| 101 | + * |
| 102 | + * @since __DEPLOY_VERSION__ |
| 103 | + */ |
| 104 | + protected function onSetTemplateId(string $value): string |
| 105 | + { |
| 106 | + return $value; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Pre-getter for the templateId argument. |
| 111 | + * |
| 112 | + * @param string $value The value to set |
| 113 | + * |
| 114 | + * @return string |
| 115 | + * |
| 116 | + * @since __DEPLOY_VERSION__ |
| 117 | + */ |
| 118 | + protected function onGetTemplateId(string $value): string |
| 119 | + { |
| 120 | + return $value; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Getter for the subject argument. |
| 125 | + * |
| 126 | + * @return MailTemplate |
| 127 | + * |
| 128 | + * @since __DEPLOY_VERSION__ |
| 129 | + */ |
| 130 | + public function getTemplate(): MailTemplate |
| 131 | + { |
| 132 | + return $this->getArgument('subject'); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Getter for the templateId argument. |
| 137 | + * |
| 138 | + * @return string |
| 139 | + * |
| 140 | + * @since __DEPLOY_VERSION__ |
| 141 | + */ |
| 142 | + public function getTemplateId(): string |
| 143 | + { |
| 144 | + return $this->getArgument('templateId'); |
| 145 | + } |
| 146 | +} |
0 commit comments