|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the MIT license. |
|
18
|
|
|
*/ |
|
19
|
|
|
namespace LearnZF2Pagination\View\Helper; |
|
20
|
|
|
|
|
21
|
|
|
use LearnZF2Pagination\Exception; |
|
22
|
|
|
use Zend\Http\Request; |
|
23
|
|
|
use Zend\View\Helper\Url; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Similar to Zends's Url view helper but allows to inherit query params as well. |
|
27
|
|
|
*/ |
|
28
|
|
|
class QueryUrl extends Url |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var Request |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $request; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct(Request $request) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->request = $request; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function __invoke($name = null, $params = [], $options = [], $reuseMatchedParams = false) |
|
41
|
|
|
{ |
|
42
|
|
|
if (null === $this->router) { |
|
43
|
|
|
throw new Exception\RuntimeException('No RouteStackInterface instance provided'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (3 === func_num_args() && is_bool($options)) { |
|
47
|
|
|
$reuseMatchedParams = $options; |
|
48
|
|
|
$options = []; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// Inherit query parameters |
|
52
|
|
|
if ($reuseMatchedParams) { |
|
53
|
|
|
$providedQueryParams = isset($options['query']) ? $options['query'] : []; |
|
54
|
|
|
$currentQueryParams = $this->request->getQuery()->toArray(); |
|
55
|
|
|
$options['query'] = array_merge($currentQueryParams, $providedQueryParams); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return parent::__invoke($name, $params, $options, $reuseMatchedParams); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|