<?php
namespace App\Entity;
use AllowDynamicProperties;
use App\Attribute\Searchable;
use App\Repository\DomainRepository;
use App\Traits\DateTimeTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Overblog\GraphQLBundle\Annotation\Field;
#[AllowDynamicProperties]
#[ORM\Entity(repositoryClass: DomainRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Domain extends BasicEntity
{
use DateTimeTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
#[Field(name: "id", type: "int")]
private $id;
#[ORM\Column(type: "string", length: 255)]
#[Field(name: "url", type: "string")]
#[Searchable(name: 'url')]
private $url;
#[ORM\ManyToOne(targetEntity: Organisation::class, inversedBy: "domains")]
#[ORM\JoinColumn(nullable: false)]
private $organisation;
#[ORM\Column(type: "boolean")]
#[Field(name: "is_enabled", type: "boolean")]
private $isEnabled;
#[ORM\OneToMany(mappedBy: "domain", targetEntity: ExposedSubDomain::class, cascade: ["remove"])]
private $exposedSubDomains;
#[ORM\OneToMany(mappedBy: "domain", targetEntity: Vulnerability::class, cascade: ["remove"])]
private $vulnerabilities;
#[ORM\OneToMany(mappedBy: "domain", targetEntity: DarkOwl::class, cascade: ["remove"])]
private $darkOwls;
#[ORM\OneToMany(mappedBy: "domain", targetEntity: DomainScore::class, cascade: ["remove"])]
private $domainScores;
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: Recommendation::class)]
private Collection $recommendations;
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: LeakedPassword::class)]
private Collection $leakedPasswords;
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: Score::class)]
private Collection $scores;
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: ExposedIp::class)]
private Collection $exposedIps;
#[ORM\ManyToMany(targetEntity: GenericRecommendation::class, inversedBy: 'domains')]
private Collection $implementedGenericRecommendations;
#[ORM\OneToMany(mappedBy: 'domaine', targetEntity: Notification::class)]
private Collection $notifications;
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: Ransomware::class)]
private Collection $ransomwares;
public function __construct()
{
$this->exposedSubDomains = new ArrayCollection();
$this->vulnerabilities = new ArrayCollection();
$this->darkOwls = new ArrayCollection();
$this->domainScores = new ArrayCollection();
$this->recommendations = new ArrayCollection();
$this->leakedPasswords = new ArrayCollection();
$this->scores = new ArrayCollection();
$this->exposedIps = new ArrayCollection();
$this->implementedGenericRecommendations = new ArrayCollection();
$this->notifications = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): self
{
$this->url = $url;
return $this;
}
public function getOrganisation(): ?Organisation
{
return $this->organisation;
}
public function setOrganisation(?Organisation $organisation): self
{
$this->organisation = $organisation;
return $this;
}
public function getIsEnabled(): ?bool
{
return $this->isEnabled;
}
public function setIsEnabled(bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
/**
* @return Collection|ExposedSubDomain[]
*/
public function getExposedSubDomains(): Collection
{
return $this->exposedSubDomains->filter(function($exposedSubdomain) {
return !$exposedSubdomain->getIsDeleted();
});
}
// Optionally add a method for getting all subdomains, including deleted ones
public function getAllExposedSubdomains(): Collection
{
return $this->exposedSubDomains;
}
public function addExposedSubDomain(ExposedSubDomain $exposedSubDomain): self
{
if (!$this->exposedSubDomains->contains($exposedSubDomain)) {
$this->exposedSubDomains[] = $exposedSubDomain;
$exposedSubDomain->setDomain($this);
}
return $this;
}
public function removeExposedSubDomain(ExposedSubDomain $exposedSubDomain): self
{
if ($this->exposedSubDomains->removeElement($exposedSubDomain)) {
// set the owning side to null (unless already changed)
if ($exposedSubDomain->getDomain() === $this) {
$exposedSubDomain->setDomain(null);
}
}
return $this;
}
/**
* @return Collection|Vulnerability[]
*/
public function getVulnerabilities(): Collection
{
return $this->vulnerabilities;
}
public function addVulnerability(Vulnerability $vulnerability): self
{
if (!$this->vulnerabilities->contains($vulnerability)) {
$this->vulnerabilities[] = $vulnerability;
$vulnerability->setDomain($this);
}
return $this;
}
public function removeVulnerability(Vulnerability $vulnerability): self
{
if ($this->vulnerabilities->removeElement($vulnerability)) {
// set the owning side to null (unless already changed)
if ($vulnerability->getDomain() === $this) {
$vulnerability->setDomain(null);
}
}
return $this;
}
/**
* @return Collection<int, DarkOwl>
*/
public function getDarkOwls(): Collection
{
return $this->darkOwls;
}
public function addDarkOwl(DarkOwl $darkOwl): self
{
if (!$this->darkOwls->contains($darkOwl)) {
$this->darkOwls[] = $darkOwl;
$darkOwl->setDomain($this);
}
return $this;
}
public function removeDarkOwl(DarkOwl $darkOwl): self
{
if ($this->darkOwls->removeElement($darkOwl)) {
// set the owning side to null (unless already changed)
if ($darkOwl->getDomain() === $this) {
$darkOwl->setDomain(null);
}
}
return $this;
}
/**
* @return Collection<int, DomainScore>
*/
public function getDomainScores(): Collection
{
return $this->domainScores;
}
public function addDomainScore(DomainScore $domainScore): self
{
if (!$this->domainScores->contains($domainScore)) {
$this->domainScores[] = $domainScore;
$domainScore->setDomain($this);
}
return $this;
}
public function removeDomainScore(DomainScore $domainScore): self
{
if ($this->domainScores->removeElement($domainScore)) {
// set the owning side to null (unless already changed)
if ($domainScore->getDomain() === $this) {
$domainScore->setDomain(null);
}
}
return $this;
}
public function getLastScore(): ?DomainScore
{
$score = null;
foreach ($this->getDomainScores() as $key => $value) {
$score = $value;
}
return $score;
}
/**
* @return Collection<int, Recommendation>
*/
public function getRecommendations(): Collection
{
return $this->recommendations;
}
public function addRecommendation(Recommendation $recommendation): static
{
if (!$this->recommendations->contains($recommendation)) {
$this->recommendations->add($recommendation);
$recommendation->setDomain($this);
}
return $this;
}
public function removeRecommendation(Recommendation $recommendation): static
{
if ($this->recommendations->removeElement($recommendation)) {
// set the owning side to null (unless already changed)
if ($recommendation->getDomain() === $this) {
$recommendation->setDomain(null);
}
}
return $this;
}
/**
* @return Collection<int, LeakedPassword>
*/
public function getLeakedPasswords(): Collection
{
return $this->leakedPasswords;
}
public function addLeakedPassword(LeakedPassword $leakedPassword): static
{
if (!$this->leakedPasswords->contains($leakedPassword)) {
$this->leakedPasswords->add($leakedPassword);
$leakedPassword->setDomain($this);
}
return $this;
}
public function removeLeakedPassword(LeakedPassword $leakedPassword): static
{
if ($this->leakedPasswords->removeElement($leakedPassword)) {
// set the owning side to null (unless already changed)
if ($leakedPassword->getDomain() === $this) {
$leakedPassword->setDomain(null);
}
}
return $this;
}
/**
* @return Collection<int, Score>
*/
public function getScores(): Collection
{
return $this->scores;
}
public function addScore(Score $score): static
{
if (!$this->scores->contains($score)) {
$this->scores->add($score);
$score->setDomain($this);
}
return $this;
}
public function removeScore(Score $score): static
{
if ($this->scores->removeElement($score)) {
// set the owning side to null (unless already changed)
if ($score->getDomain() === $this) {
$score->setDomain(null);
}
}
return $this;
}
/**
* @return Collection<int, ExposedIp>
*/
public function getExposedIps(): Collection
{
return $this->exposedIps;
}
public function addExposedIp(ExposedIp $exposedIp): static
{
if (!$this->exposedIps->contains($exposedIp)) {
$this->exposedIps->add($exposedIp);
$exposedIp->setDomain($this);
}
return $this;
}
public function removeExposedIp(ExposedIp $exposedIp): static
{
if ($this->exposedIps->removeElement($exposedIp)) {
// set the owning side to null (unless already changed)
if ($exposedIp->getDomain() === $this) {
$exposedIp->setDomain(null);
}
}
return $this;
}
/**
* @return Collection<int, GenericRecommendation>
*/
public function getImplementedGenericRecommendations(): Collection
{
return $this->implementedGenericRecommendations;
}
public function addImplementedGenericRecommendation(GenericRecommendation $implementedGenericRecommendation): static
{
if (!$this->implementedGenericRecommendations->contains($implementedGenericRecommendation)) {
$this->implementedGenericRecommendations->add($implementedGenericRecommendation);
}
return $this;
}
public function removeImplementedGenericRecommendation(GenericRecommendation $implementedGenericRecommendation): static
{
$this->implementedGenericRecommendations->removeElement($implementedGenericRecommendation);
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): static
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setDomain($this);
}
return $this;
}
public function removeNotification(Notification $notification): static
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getDomain() === $this) {
$notification->setDomain(null);
}
}
return $this;
}
}