1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Phalcon Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Phalcon Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Phalcon\Html\Link; |
15
|
|
|
|
16
|
|
|
use Psr\Link\EvolvableLinkProviderInterface; |
17
|
|
|
use Psr\Link\LinkInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class LinkProvider |
21
|
|
|
* |
22
|
|
|
* @package Phalcon\Link |
23
|
|
|
* |
24
|
|
|
* @property LinkInterface[] $links |
25
|
|
|
*/ |
26
|
|
|
class EvolvableLinkProvider extends LinkProvider implements EvolvableLinkProviderInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Returns an instance with the specified link included. |
30
|
|
|
* |
31
|
|
|
* If the specified link is already present, this method MUST return |
32
|
|
|
* normally without errors. The link is present if $link is === identical |
33
|
|
|
* to a link object already in the collection. |
34
|
|
|
* |
35
|
|
|
* @param LinkInterface $link |
36
|
|
|
* A link object that should be included in this collection. |
37
|
|
|
* |
38
|
|
|
* @return static |
39
|
|
|
*/ |
40
|
|
|
public function withLink(LinkInterface $link) |
41
|
|
|
{ |
42
|
|
|
$key = $this->getKey($link); |
43
|
|
|
$newInstance = clone $this; |
44
|
|
|
|
45
|
|
|
$newInstance->links[$key] = $link; |
46
|
|
|
|
47
|
|
|
return $newInstance; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns an instance with the specified link removed. |
52
|
|
|
* |
53
|
|
|
* If the specified link is not present, this method MUST return normally |
54
|
|
|
* without errors. The link is present if $link is === identical to a link |
55
|
|
|
* object already in the collection. |
56
|
|
|
* |
57
|
|
|
* @param LinkInterface $link |
58
|
|
|
* The link to remove. |
59
|
|
|
* |
60
|
|
|
* @return static |
61
|
|
|
*/ |
62
|
|
|
public function withoutLink(LinkInterface $link) |
63
|
|
|
{ |
64
|
|
|
$key = $this->getKey($link); |
65
|
|
|
$newInstance = clone $this; |
66
|
|
|
|
67
|
|
|
unset($newInstance->links[$key]); |
68
|
|
|
|
69
|
|
|
return $newInstance; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|