1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Menu; |
4
|
|
|
|
5
|
|
|
use Spatie\Menu\Html\Attributes; |
6
|
|
|
use Spatie\Menu\Traits\Activatable as ActivatableTrait; |
7
|
|
|
use Spatie\Menu\Traits\Conditions as ConditionsTrait; |
8
|
|
|
use Spatie\Menu\Traits\HasHtmlAttributes as HasHtmlAttributesTrait; |
9
|
|
|
use Spatie\Menu\Traits\HasParentAttributes as HasParentAttributesTrait; |
10
|
|
|
use Spatie\Menu\Traits\HasTextAttributes as HasAttributesTrait; |
11
|
|
|
|
12
|
|
|
class Link implements Item, HasHtmlAttributes, HasParentAttributes, Activatable |
13
|
|
|
{ |
14
|
|
|
use ActivatableTrait, HasHtmlAttributesTrait, HasParentAttributesTrait, ConditionsTrait, HasAttributesTrait; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $text; |
18
|
|
|
|
19
|
|
|
/** @var string|null */ |
20
|
|
|
protected $url = null; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $prepend, $append = ''; |
24
|
|
|
|
25
|
|
|
/** @var bool */ |
26
|
|
|
protected $active = false; |
27
|
|
|
|
28
|
|
|
/** @var \Spatie\Menu\Html\Attributes */ |
29
|
|
|
protected $htmlAttributes, $parentAttributes; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $url |
33
|
|
|
* @param string $text |
34
|
|
|
*/ |
35
|
|
|
protected function __construct(string $url, string $text) |
36
|
|
|
{ |
37
|
|
|
$this->url = $url; |
38
|
|
|
$this->text = $text; |
39
|
|
|
$this->htmlAttributes = new Attributes(); |
40
|
|
|
$this->parentAttributes = new Attributes(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $url |
45
|
|
|
* @param string $text |
46
|
|
|
* |
47
|
|
|
* @return static |
48
|
|
|
*/ |
49
|
|
|
public static function to(string $url, string $text) |
50
|
|
|
{ |
51
|
|
|
return new static($url, $text); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function text(): string |
58
|
|
|
{ |
59
|
|
|
return $this->text; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function render(): string |
66
|
|
|
{ |
67
|
|
|
$attributes = new Attributes(['href' => $this->url]); |
68
|
|
|
$attributes->mergeWith($this->htmlAttributes); |
|
|
|
|
69
|
|
|
|
70
|
|
|
return $this->prepend."<a {$attributes}>{$this->text}</a>".$this->append; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function __toString(): string |
77
|
|
|
{ |
78
|
|
|
return $this->render(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: