Passed
Push — feature/multisite-poc ( f9befe )
by Erik
11:53
created

UrlAlias::setSite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Bundle\UrlBundle\Entity;
7
8
use Doctrine\ORM\Mapping as ORM;
9
10
/**
11
 * Entity representing log url translations, mapping public (SEO-friendly) url's to internal url's (routes).
12
 *
13
 * @ORM\Entity(repositoryClass="Zicht\Bundle\UrlBundle\Entity\Repository\UrlAliasRepository")
14
 * @ORM\Table(
15
 *  name = "url_alias",
16
 *  indexes={
17
 *      @ORM\Index(name="public_url_idx", columns={"public_url", "site"}),
18
 *      @ORM\Index(name="internal_url_idx", columns={"internal_url", "mode"})
19
 * })
20
 */
21
class UrlAlias
22
{
23
    /**
24
     * The alias is an internal rewrite, i.e. external url's are rewritten to internal on request,
25
     * and vice versa when composing an url.
26
     */
27
    const REWRITE   = 0;
28
29
    /**
30
     * The MOVE type yields a 301 response with the internal url if the public url is matched
31
     */
32
    const MOVE      = 301;
33
34
    /**
35
     * The ALIAS type yields a 302 response with the internal url if the public url is matched
36
     */
37
    const ALIAS     = 302;
38
39
    /**
40
     * @ORM\Id
41
     * @ORM\GeneratedValue(strategy="AUTO")
42
     * @ORM\Column(type = "integer")
43
     */
44
    protected $id;
45
46
    /**
47
     * @ORM\Column(type="string")
48
     */
49
    protected $public_url;
50
51
    /**
52
     * @ORM\Column(type="string")
53
     */
54
    protected $internal_url;
55
56
    /**
57
     * @ORM\Column(type="integer")
58
     */
59
    protected $mode = self::REWRITE;
60
61
    /**
62
     * @ORM\Column(type="string", nullable=true)
63
     */
64
    protected $site;
65
66
    /**
67
     * Create a new alias
68
     *
69
     * @param string $public_url
70
     * @param string $internal_url
71
     * @param int $mode
72
     */
73
    public function __construct($public_url = null, $internal_url = null, $mode = null)
74
    {
75
        $this->setPublicUrl($public_url);
76
        $this->setInternalUrl($internal_url);
77
        $this->setMode($mode);
78
    }
79
80
    /**
81
     * @return mixed
82
     */
83
    public function getId()
84
    {
85
        return $this->id;
86
    }
87
88
    /**
89
     * @param string $internal_url
90
     * @return void
91
     */
92
    public function setInternalUrl($internal_url)
93
    {
94
        $this->internal_url = $internal_url;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getInternalUrl()
101
    {
102
        return $this->internal_url;
103
    }
104
105
    /**
106
     * @param int $mode
107
     * @return void
108
     */
109
    public function setMode($mode)
110
    {
111
        $this->mode = $mode;
112
    }
113
114
    /**
115
     * @return int
116
     */
117
    public function getMode()
118
    {
119
        return $this->mode;
120
    }
121
122
    /**
123
     * @param string $public_url
124
     * @return void
125
     */
126
    public function setPublicUrl($public_url)
127
    {
128
        $this->public_url = $public_url;
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function getPublicUrl()
135
    {
136
        return $this->public_url;
137
    }
138
139
    /**
140
     * @return mixed
141
     */
142
    public function getSite()
143
    {
144
        return $this->site;
145
    }
146
147
    /**
148
     * @param mixed $site
149
     */
150
    public function setSite($site): void
151
    {
152
        $this->site = $site;
153
    }
154
155
    /**
156
     * @return string
157
     */
158
    public function __toString()
159
    {
160
        return (string)$this->id;
161
    }
162
}
163