1<?php
2
3namespace ComboStrap;
4
5class RouterRedirectionBuilder
6{
7
8    private string $origin;
9
10    /**
11     * The target is null when the origin is `GO_TO_EDIT_MODE`
12     */
13    private string $type;
14    private ?MarkupPath $targetMarkupPath = null;
15    private ?Web\Url $targetUrl = null;
16
17
18    private function __construct(string $origin)
19    {
20        $this->origin = $origin;
21    }
22
23    /**
24     * @param string $origin - the origin of the redirection
25     * @return RouterRedirectionBuilder
26     */
27    public static function createFromOrigin(string $origin): RouterRedirectionBuilder
28    {
29        return new RouterRedirectionBuilder($origin);
30    }
31
32
33    /**
34     * @param string $type - the type (permanent, ...))
35     * @return $this
36     */
37    public function setType(string $type): RouterRedirectionBuilder
38    {
39        $this->type = $type;
40        return $this;
41    }
42
43
44    public function build(): RouterRedirection
45    {
46        return new RouterRedirection($this);
47    }
48
49    /**
50     * @param MarkupPath $path - the path to redirect
51     * @return $this
52     */
53    public function setTargetMarkupPath(MarkupPath $path): RouterRedirectionBuilder
54    {
55        // ->getCanonicalUrl()->toAbsoluteUrlString()
56        $this->targetMarkupPath = $path;
57        return $this;
58    }
59
60    /**
61     * @param Web\Url $url - the URL to redirect
62     * @return $this
63     */
64    public function setTargetUrl(Web\Url $url): RouterRedirectionBuilder
65    {
66        $this->targetUrl = $url;
67        return $this;
68    }
69
70    public function getOrigin(): string
71    {
72        return $this->origin;
73    }
74
75    public function getType(): string
76    {
77        return $this->type;
78    }
79
80    public function getTargetMarkupPath(): ?MarkupPath
81    {
82        return $this->targetMarkupPath;
83    }
84
85    public function getTargetUrl(): ?Web\Url
86    {
87        return $this->targetUrl;
88    }
89
90
91}
92