File size: 1,869 Bytes
cf14c12 | 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 | <?php
declare(strict_types=1);
namespace Billing\Domain\Entities;
use Billing\Domain\ValueObjects\PlanConfig;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Shared\Domain\ValueObjects\Id;
#[ORM\Entity]
#[ORM\Table(name: 'plan_snapshot')]
class PlanSnapshotEntity extends AbstractPlanSuperclass
{
#[ORM\ManyToOne(targetEntity: PlanEntity::class, inversedBy: 'snapshopts')]
#[ORM\JoinColumn(onDelete: 'SET NULL')]
private ?PlanEntity $plan = null;
public function __construct(
PlanEntity $plan
) {
$this->id = new Id();
$this->title = $plan->getTitle();
$this->description = $plan->getDescription();
$this->icon = $plan->getIcon();
$this->featureList = $plan->getFeatureList();
$this->price = $plan->getPrice();
$this->billingCycle = $plan->getBillingCycle();
$this->creditCount = $plan->getCreditCount();
$this->createdAt = new DateTimeImmutable();
$this->config = $plan->getConfig();
$this->plan = $plan;
}
public function getPlan(): ?PlanEntity
{
return $this->plan;
}
public function getConfig(): PlanConfig
{
if (!$this->config instanceof PlanConfig) {
$this->config = new PlanConfig(
array_merge(
$this->plan ? $this->plan->getConfig()->toArray() : [],
$this->config ?: []
)
);
}
return $this->config;
}
public function resync()
{
$this->title = $this->plan->getTitle();
$this->description = $this->plan->getDescription();
$this->icon = $this->plan->getIcon();
$this->featureList = $this->plan->getFeatureList();
$this->creditCount = $this->plan->getCreditCount();
$this->config = $this->plan->getConfig();
}
}
|