1: <?php
2:
3: class Link {
4:
5: /**
6: * Hyperlink's text
7: *
8: * @var string
9: */
10: public $text;
11:
12: /**
13: * Hyperlink's URL
14: *
15: * @var string
16: */
17: public $url;
18:
19: /**
20: * Hyperlink's attributes
21: *
22: * @var array
23: */
24: public $attributes;
25:
26: /**
27: * Creates a hyperlink
28: *
29: * @param string $title
30: * @param string $url
31: * @param array $attributes
32: * @return void
33: */
34: public function __construct($text, $url, $attributes = array())
35: {
36: $this->text = $text;
37:
38: $this->url = $url;
39:
40: $this->attributes = $attributes;
41: }
42:
43:
44: /**
45: * Return hyperlink's URL
46: *
47: * @return string $url
48: */
49: public function get_url()
50: {
51: return $this->url;
52: }
53:
54: /**
55: * Return hyperlink's title
56: *
57: * @return string $title
58: */
59: public function get_text()
60: {
61: return $this->text;
62: }
63:
64:
65: /**
66: * Append content at the end of hyperlink's text
67: *
68: * @return Menu
69: */
70: public function append($content)
71: {
72: $this->text .= $content;
73:
74: return $this;
75: }
76:
77: /**
78: * Add content at the beginning of hyperlink's text
79: *
80: * @return Menu
81: */
82: public function prepend($content)
83: {
84: $this->text = $content . $this->text;
85:
86: return $this;
87: }
88:
89:
90: /**
91: * Add attributes to the hyperlink
92: *
93: * @param mixed $attributes
94: * @return Menu
95: */
96: public function attributes()
97: {
98: $args = func_get_args();
99:
100: if(is_array($args[0])) {
101: $this->attributes = array_merge($this->attributes, $args[0]);
102: return $this;
103: }
104:
105: elseif(isset($args[0]) && isset($args[1])) {
106: $this->attributes[$args[0]] = $args[1];
107: return $this;
108: }
109:
110: elseif(isset($args[0])) {
111: return isset($this->attributes[$args[0]]) ? $this->attributes[$args[0]] : null;
112: }
113:
114: return $this->attributes;
115: }
116:
117: }