CampaignParameters.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Views; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class CampaignParameters |
| 7 | { |
| 8 | private string $utm_source; |
| 9 | private string $utm_medium; |
| 10 | private string $utm_campaign; |
| 11 | private ?string $utm_term; |
| 12 | private ?string $utm_content; |
| 13 | private static array $required_parameters = ['utm_source', 'utm_medium', 'utm_campaign']; |
| 14 | private function __construct(string $utm_source, string $utm_medium, string $utm_campaign, ?string $utm_term = null, ?string $utm_content = null) |
| 15 | { |
| 16 | $this->utm_source = $utm_source; |
| 17 | $this->utm_medium = $utm_medium; |
| 18 | $this->utm_campaign = $utm_campaign; |
| 19 | $this->utm_term = $utm_term; |
| 20 | $this->utm_content = $utm_content; |
| 21 | } |
| 22 | public function utm_source() : string |
| 23 | { |
| 24 | return $this->utm_source; |
| 25 | } |
| 26 | public function utm_medium() : string |
| 27 | { |
| 28 | return $this->utm_medium; |
| 29 | } |
| 30 | public function utm_campaign() : string |
| 31 | { |
| 32 | return $this->utm_campaign; |
| 33 | } |
| 34 | public function utm_term() : ?string |
| 35 | { |
| 36 | return $this->utm_term; |
| 37 | } |
| 38 | public function utm_content() : ?string |
| 39 | { |
| 40 | return $this->utm_content; |
| 41 | } |
| 42 | public static function make(?string $utm_source = null, ?string $utm_medium = null, ?string $utm_campaign = null, ?string $utm_term = null, ?string $utm_content = null) : ?self |
| 43 | { |
| 44 | foreach (self::$required_parameters as $parameter) { |
| 45 | if (!isset(${$parameter}) || !\is_string(${$parameter})) { |
| 46 | return null; |
| 47 | } |
| 48 | } |
| 49 | return new \IAWP\Views\CampaignParameters($utm_source, $utm_medium, $utm_campaign, $utm_term, $utm_content); |
| 50 | } |
| 51 | } |
| 52 |