1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97:
<?php
declare(strict_types=1);
namespace App\ConfigModule\Forms;
use App\ConfigModule\Model\InstanceManager;
use App\ConfigModule\Presenters\MqttPresenter;
use App\Forms\FormFactory;
use Nette;
use Nette\Application\UI\Form;
class ConfigMqttFormFactory {
use Nette\SmartObject;
private $manager;
private $factory;
public function __construct(InstanceManager $manager, FormFactory $factory) {
$this->manager = $manager;
$this->factory = $factory;
}
public function create(MqttPresenter $presenter) {
$id = intval($presenter->getParameter('id'));
$form = $this->factory->create();
$fileName = 'MqttMessaging';
$this->manager->setFileName($fileName);
$qos = ['QoS 0 - At most once', 'QoS 1 - At least once', 'QoS 2 - Exactly once'];
$form->addText('Name', 'Name')->setRequired();
$form->addCheckbox('Enabled', 'Enabled');
$form->addText('BrokerAddr', 'BrokerAddr')->setRequired();
$form->addText('ClientId', 'ClientId')->setRequired();
$form->addInteger('Persistence', 'Persistence');
$form->addSelect('Qos', 'QoS', $qos);
$form->addText('TopicRequest', 'TopicRequest')->setRequired();
$form->addText('TopicResponse', 'TopicResponse')->setRequired();
$form->addText('User', 'User');
$form->addText('Password', 'Password');
$form->addCheckbox('EnabledSSL', 'EnabledSSL');
$form->addInteger('KeepAliveInterval', 'KeepAliveInterval');
$form->addInteger('ConnectTimeout', 'ConnectTimeout');
$form->addInteger('MinReconnect', 'MinReconnect');
$form->addInteger('MaxReconnect', 'MaxReconnect');
$form->addText('TrustStore', 'TrustStore');
$form->addText('KeyStore', 'KeyStore');
$form->addText('PrivateKey', 'PrivateKey');
$form->addText('PrivateKeyPassword', 'PrivateKeyPassword');
$form->addText('EnabledCipherSuites', 'EnabledCipherSuites');
$form->addCheckbox('EnableServerCertAuth', 'EnableServerCertAuth');
$form->addSubmit('save', 'Save');
$form->setDefaults($this->manager->load($id));
$form->addProtection('Timeout expired, resubmit the form.');
$form->onSuccess[] = function (Form $form, $values) use ($presenter, $id) {
$this->manager->save($values, $id);
$presenter->redirect('Mqtt:default');
};
return $form;
}
}