Created
February 21, 2023 06:10
-
-
Save Astikos/3ad05c81270e714b6158dcbe5611818c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Entity; | |
use App\Exception\InvalidRegularExpression; | |
class UrlPattern | |
{ | |
private ?int $id; | |
private string $regex; | |
/** @throws InvalidRegularExpression */ | |
public function __construct(?int $id, string $regex) | |
{ | |
$this->id = $id; | |
if (false === preg_match($regex, '')) { | |
throw new InvalidRegularExpression(); | |
} | |
$this->regex = $regex; | |
} | |
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 UrlPattern %s', $this->regex)); | |
} | |
return $this->id; | |
} | |
public function getRegex(): string | |
{ | |
return $this->regex; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment