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