Skip to content

Instantly share code, notes, and snippets.

@Astikos
Created February 21, 2023 06:05
Show Gist options
  • Save Astikos/14c7aeec38c12f9e57ef2941577f82f1 to your computer and use it in GitHub Desktop.
Save Astikos/14c7aeec38c12f9e57ef2941577f82f1 to your computer and use it in GitHub Desktop.
<?php
namespace App\Entity;
use App\Helper\StringUtils;
use Webmozart\Assert\Assert;
class Url
{
public const STATUS_SHORT_URL_FALSE = 'false';
public const STATUS_SHORT_URL_TO_EXPAND = 'expanding_to_do';
public const STATUS_SHORT_URL_EXPANDED = 'expanded';
public const STATUS_SHORT_URL_ERROR = 'expanding_error';
public const VALID_SHORT_URL_STATUSES = [
self::STATUS_SHORT_URL_FALSE,
self::STATUS_SHORT_URL_TO_EXPAND,
self::STATUS_SHORT_URL_EXPANDED,
self::STATUS_SHORT_URL_ERROR,
];
public const STATUS_URL_HUB_FALSE = 'false';
public const STATUS_URL_HUB_CAN_SCRAPE = 'scraping_to_do';
public const STATUS_URL_HUB_SCRAPED_OK = 'scraped';
public const STATUS_URL_HUB_SCRAPING_ERROR = 'scraping_error';
public const VALID_URL_HUB_STATUSES = [
self::STATUS_URL_HUB_FALSE,
self::STATUS_URL_HUB_CAN_SCRAPE,
self::STATUS_URL_HUB_SCRAPED_OK,
self::STATUS_URL_HUB_SCRAPING_ERROR,
];
private ?int $id;
private string $value;
private string $shortUrlStatus;
private bool $urlHubMarkingDone;
private string $urlHubStatus;
public function __construct(
?int $id,
string $value,
string $shortUrlStatus = self::STATUS_SHORT_URL_TO_EXPAND,
bool $urlHubMarkingDone = false,
string $urlHubStatus = self::STATUS_URL_HUB_FALSE
) {
Assert::inArray($shortUrlStatus, self::VALID_SHORT_URL_STATUSES);
Assert::inArray($urlHubStatus, self::VALID_URL_HUB_STATUSES);
$this->id = $id;
$this->value = StringUtils::lowercaseUrl($value);
$this->shortUrlStatus = $shortUrlStatus;
$this->urlHubMarkingDone = $urlHubMarkingDone;
$this->urlHubStatus = $urlHubStatus;
}
public function getId(): ?int
{
return $this->id;
}
public function returnNonNullId(): int
{
if (null === $this->id) {
throw new \LogicException(sprintf('id should not be null for Url %s', $this->value));
}
return $this->id;
}
public function getValue(): string
{
return $this->value;
}
public function getShortUrlStatus(): string
{
return $this->shortUrlStatus;
}
public function setShortUrlStatus(string $status): void
{
Assert::inArray($status, self::VALID_SHORT_URL_STATUSES);
$this->shortUrlStatus = $status;
}
public function isUrlHubMarkingDone(): bool
{
return $this->urlHubMarkingDone;
}
public function setUrlHubMarkingDone(bool $value): void
{
$this->urlHubMarkingDone = $value;
}
public function getUrlHubStatus(): string
{
return $this->urlHubStatus;
}
public function setUrlHubStatus(string $value): void
{
$this->urlHubStatus = $value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment