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