1. Go to this page and download the library: Download lexal/form-submitter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lexal / form-submitter example snippets
use Lexal\FormSubmitter\FormSubmitterInterface;
final class CustomerFormSubmitter implements FormSubmitterInterface
{
public function supportsSubmitting(mixed $entity): bool
{
return $entity instanceof Customer;
}
public function submit(mixed $entity): mixed
{
// save entity to the database
return $entity;
}
}
$entity = new Customer();
$formSubmitter = new CustomerFormSubmitter();
if ($formSubmitter->supportsSubmitting($entity)) {
$formSubmitter->submit($entity);
}
use Lexal\FormSubmitter\FormSubmitter;
$formSubmitter = new FormSubmitter(
new CustomerFormSubmitter(),
);
$formSubmitter->submit(new Customer());
use Lexal\FormSubmitter\FormSubmitter;
use Lexal\FormSubmitter\Transaction\TransactionInterface;
use Lexal\FormSubmitter\TransactionalFormSubmitter;
final class DatabaseTransaction implements TransactionInterface
{
public function start(): void
{
// start transaction
}
public function commit(): void
{
// commit transaction
}
public function rollback(): void
{
// rollback transaction
}
}
$submitter = new TransactionalFormSubmitter(
new FormSubmitter(new CustomerFormSubmitter()),
new DatabaseTransaction(),
);
$submitter->submit(new Customer());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.