'email', 'reply_to_address' => 'email', 'email_count' => 'int', 'sms_count' => 'int', 'apikey' => 'string', 'custom_smtp' => '?bool', 'smtp_address' => '?domain', 'smtp_port' => '?int', 'smtp_user' => '?string', 'smtp_password' => '?string' ]; } public function get_site_template_name() : string { return 'config_panel'; } private function validate_result() : ?string { if (!$this->is_validated('source_address')) { return 'Source E-Mail address is not valid.'; } if (!$this->is_validated('reply_to_address')) { return 'Reply to E-Mail address it not valid.'; } if (!$this->is_validated('email_count')) { return 'Count of the E-Mails is not valid.'; } if (!$this->is_validated('sms_count')) { return 'Count of the SMS-es is not valid.'; } if (!$this->is_validated('apikey')) { return 'Api Key is not valid.'; } if (strlen($this->get_validated('apikey')) < 16) { return 'Api Key must has minimum 16 characters.'; } if ($this->use_custom_smtp('true', null) !== null) { return $this->smtp_section_validate(); } return null; } private function smtp_section_validate() : ?string { if (!$this->is_validated('smtp_address')) { return 'SMTP address is not property set.'; } if (empty($this->get_validated('smtp_address'))) { return 'SMTP address can not be blank.'; } if (!$this->is_validated('smtp_port')) { return 'SMTP port is not property set.'; } if (empty($this->get_validated('smtp_port'))) { return 'SMTP port is not set.'; } if (empty($this->get_validated('smtp_user'))) { return 'SMTP user can not be blank.'; } if (!$this->is_validated('smtp_password')) { return 'SMTP password is not property set.'; } if (empty($this->get_validated('smtp_password'))) { return 'SMTP password can not be blank'; } return null; } private function use_custom_smtp( string $true = 'true', ?string $false = 'false' ) : ?string { if (!empty($this->get_received('custom_smtp'))) { return $true; } return $false; } private function save() { $validate = $this->validate_result(); if ($validate !== null) { $this->error_toast($validate); return; } $settings = $this->get_settings(); $settings ->save('source_address', $this->get_validated('source_address')) ->save('reply_to_address', $this->get_validated('reply_to_address')) ->save('email_count', $this->get_validated('email_count')) ->save('sms_count', $this->get_validated('sms_count')) ->save('apikey', $this->get_validated('apikey')) ->save('custom_smtp', $this->use_custom_smtp()) ->save('smtp_address', $this->get_validated('smtp_address')) ->save('smtp_port', strval($this->get_validated('smtp_port'))) ->save('smtp_user', $this->get_validated('smtp_user')) ->save('smtp_password', $this->get_validated('smtp_password')); $this->success_toast('Settings had been saved.'); } public function process() : self { if ($this->is_received('save')) { $this->save(); } $this->set('source_address', $this->get_settings()->get('source_address')); $this->set('reply_to_address', $this->get_settings()->get('reply_to_address')); $this->set('email_count', $this->get_settings()->get('email_count')); $this->set('sms_count', $this->get_settings()->get('sms_count')); $this->set('apikey', $this->get_settings()->get('apikey')); $this->set('smtp_address', $this->get_settings()->get('smtp_address')); $this->set('smtp_port', $this->get_settings()->get('smtp_port')); $this->set('smtp_user', $this->get_settings()->get('smtp_user')); $this->set('smtp_password', $this->get_settings()->get('smtp_password')); if ($this->get_settings()->use_custom_smtp()) { $this->set('custom_smtp_checked', 'checked'); } else { $this->set('custom_smtp_checked', ''); } return $this; } }