feat: Implement SMS sending functionality with KavehNegar and Rangineh providers
- Add SendSmsMessage class for encapsulating SMS message data. - Create KavehNegarProvider and RanginehProvider classes implementing SmsProviderInterface for sending SMS. - Implement SmsLogRepository and SmsTemplateRepository for managing SMS logs and templates. - Develop SendSmsHandler for handling SMS sending messages. - Create SmsService to manage SMS dispatching and logging. - Add UserProfileController for managing user profiles with CRUD operations. - Implement UserProfile entity and repository for user profile data management. - Update symfony.lock and bootstrap.php for project dependencies and environment setup.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Sms\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'sms_logs')]
|
||||
#[ORM\Index(columns: ['mobile', 'created_at'], name: 'idx_sms_logs_mobile')]
|
||||
class SmsLog
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
||||
private string $uuid;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 20)]
|
||||
private string $mobile;
|
||||
|
||||
#[ORM\Column(type: 'text')]
|
||||
private string $message;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 20)]
|
||||
private string $provider;
|
||||
|
||||
#[ORM\Column(type: 'boolean')]
|
||||
private bool $success;
|
||||
|
||||
#[ORM\Column(name: 'template_uuid', type: 'string', length: 36, nullable: true)]
|
||||
private ?string $templateUuid = null;
|
||||
|
||||
#[ORM\Column(name: 'created_at', type: 'integer')]
|
||||
private int $createdAt;
|
||||
|
||||
public function __construct(string $mobile, string $message, string $provider, bool $success)
|
||||
{
|
||||
$this->uuid = Uuid::v4()->toRfc4122();
|
||||
$this->mobile = $mobile;
|
||||
$this->message = $message;
|
||||
$this->provider = $provider;
|
||||
$this->success = $success;
|
||||
$this->createdAt = time();
|
||||
}
|
||||
|
||||
public function setTemplateUuid(?string $v): self { $this->templateUuid = $v; return $this; }
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'mobile' => $this->mobile,
|
||||
'message' => $this->message,
|
||||
'provider' => $this->provider,
|
||||
'success' => $this->success,
|
||||
'template_uuid' => $this->templateUuid,
|
||||
'created_at' => $this->createdAt,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Sms\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'sms_templates')]
|
||||
class SmsTemplate
|
||||
{
|
||||
public const STATUS_DRAFT = 'draft';
|
||||
public const STATUS_PENDING = 'pending';
|
||||
public const STATUS_APPROVED = 'approved';
|
||||
public const STATUS_REJECTED = 'rejected';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
||||
private string $uuid;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 100)]
|
||||
private string $name;
|
||||
|
||||
#[ORM\Column(type: 'text')]
|
||||
private string $body;
|
||||
|
||||
#[ORM\Column(name: 'provider_code', type: 'string', length: 100, nullable: true)]
|
||||
private ?string $providerCode = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 20)]
|
||||
private string $status = self::STATUS_DRAFT;
|
||||
|
||||
#[ORM\Column(name: 'variables', type: 'json')]
|
||||
private array $variables = [];
|
||||
|
||||
#[ORM\Column(name: 'admin_note', type: 'string', length: 500, nullable: true)]
|
||||
private ?string $adminNote = null;
|
||||
|
||||
#[ORM\Column(name: 'created_at', type: 'integer')]
|
||||
private int $createdAt;
|
||||
|
||||
#[ORM\Column(name: 'updated_at', type: 'integer')]
|
||||
private int $updatedAt;
|
||||
|
||||
public function __construct(string $name, string $body, array $variables = [])
|
||||
{
|
||||
$this->uuid = Uuid::v4()->toRfc4122();
|
||||
$this->name = $name;
|
||||
$this->body = $body;
|
||||
$this->variables = $variables;
|
||||
$this->createdAt = time();
|
||||
$this->updatedAt = time();
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getUuid(): string { return $this->uuid; }
|
||||
public function getName(): string { return $this->name; }
|
||||
public function getBody(): string { return $this->body; }
|
||||
public function getProviderCode(): ?string { return $this->providerCode; }
|
||||
public function getStatus(): string { return $this->status; }
|
||||
public function getVariables(): array { return $this->variables; }
|
||||
public function getAdminNote(): ?string { return $this->adminNote; }
|
||||
|
||||
public function setName(string $v): self { $this->name = $v; $this->touch(); return $this; }
|
||||
public function setBody(string $v): self { $this->body = $v; $this->touch(); return $this; }
|
||||
public function setProviderCode(?string $v): self { $this->providerCode = $v; $this->touch(); return $this; }
|
||||
public function setVariables(array $v): self { $this->variables = $v; $this->touch(); return $this; }
|
||||
|
||||
public function submitForReview(): self { $this->status = self::STATUS_PENDING; $this->touch(); return $this; }
|
||||
|
||||
public function approve(?string $note = null): self
|
||||
{
|
||||
$this->status = self::STATUS_APPROVED;
|
||||
$this->adminNote = $note;
|
||||
$this->touch();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function reject(string $note): self
|
||||
{
|
||||
$this->status = self::STATUS_REJECTED;
|
||||
$this->adminNote = $note;
|
||||
$this->touch();
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function touch(): void { $this->updatedAt = time(); }
|
||||
|
||||
public function renderBody(array $vars): string
|
||||
{
|
||||
$body = $this->body;
|
||||
foreach ($vars as $key => $value) {
|
||||
$body = str_replace('{{' . $key . '}}', $value, $body);
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'name' => $this->name,
|
||||
'body' => $this->body,
|
||||
'provider_code' => $this->providerCode,
|
||||
'variables' => $this->variables,
|
||||
'status' => $this->status,
|
||||
'admin_note' => $this->adminNote,
|
||||
'created_at' => $this->createdAt,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user