1. Go to this page and download the library: Download sympress/orm 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/ */
sympress / orm example snippets
declare(strict_types=1);
namespace App\Mailer\Entity;
use App\Mailer\Repository\EmailLogRepository;
use SymPress\Orm\Mapping\Column;
use SymPress\Orm\Mapping\Entity;
use SymPress\Orm\Mapping\Id;
use SymPress\Orm\Mapping\Index;
#[Entity(table: 'sympress_mailer_logs', repositoryClass: EmailLogRepository::class)]
#[Index(name: 'status_created', columns: ['status', 'createdAt'])]
final class EmailLog
{
public function __construct(
#[Id]
#[Column(type: 'string', length: 32)]
public string $id,
#[Column(type: 'datetime')]
public \DateTimeImmutable $createdAt,
#[Column(type: 'string', length: 20)]
public string $status,
#[Column(type: 'json', nullable: true)]
public array $payload = [],
) {
}
}
use App\Mailer\Entity\EmailLog;
use SymPress\Orm\EntityManager;
final readonly class MailerService
{
public function __construct(private EntityManager $entities)
{
}
public function logQueuedMail(string $id, array $payload): void
{
$log = new EmailLog(
$id,
new \DateTimeImmutable(),
'queued',
$payload,
);
$this->entities->persist($log);
$this->entities->flush();
}
}
$query = $entityManager->createQuery(
'SELECT l FROM EmailLog l WHERE l.status = :status ORDER BY l.createdAt DESC',
['status' => 'queued'],
);
$logs = $query->getResult();
$entityManager
->createQuery(
'UPDATE EmailLog l SET l.status = :status WHERE l.id = ?1',
['status' => 'sent', 1 => 'log_123'],
)
->execute();