|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Vperyod Method Override Handler |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (C) 2016 Jake Johns |
|
8
|
|
|
* |
|
9
|
|
|
* This software may be modified and distributed under the terms |
|
10
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
11
|
|
|
* |
|
12
|
|
|
* @category ViewHelper |
|
13
|
|
|
* @package Vperyod\MethodHandler |
|
14
|
|
|
* @author Jake Johns <[email protected]> |
|
15
|
|
|
* @copyright 2016 Jake Johns |
|
16
|
|
|
* @license http://jnj.mit-license.org/2016 MIT License |
|
17
|
|
|
* @link http://github.com/vperyod/vperyod.method-handler |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Vperyod\MethodHandler; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Method Override Helper |
|
24
|
|
|
* |
|
25
|
|
|
* Simple view helper to assist in creating a hidden form field to override the |
|
26
|
|
|
* method of the post request |
|
27
|
|
|
* |
|
28
|
|
|
* @category ViewHelper |
|
29
|
|
|
* @package Vperyod\MethodHandler |
|
30
|
|
|
* @author Jake Johns <[email protected]> |
|
31
|
|
|
* @license http://jnj.mit-license.org/ MIT License |
|
32
|
|
|
* @link http://github.com/vperyod/vperyod.method-handler |
|
33
|
|
|
*/ |
|
34
|
|
|
class MethodOverrideHelper |
|
35
|
|
|
{ |
|
36
|
|
|
use MethodOverrideTrait; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Value with which to override method |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
* |
|
43
|
|
|
* @access protected |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $method; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* __invoke |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $method value to overide method |
|
51
|
|
|
* |
|
52
|
|
|
* @return $this |
|
53
|
|
|
* |
|
54
|
|
|
* @access public |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function __invoke($method = null) |
|
57
|
|
|
{ |
|
58
|
1 |
|
if ($method !== null) { |
|
59
|
1 |
|
$this->setMethod($method); |
|
60
|
|
|
} |
|
61
|
1 |
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Set Method |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $method value to override method |
|
68
|
|
|
* |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
* |
|
71
|
|
|
* @access public |
|
72
|
|
|
*/ |
|
73
|
3 |
|
public function setMethod($method) |
|
74
|
|
|
{ |
|
75
|
3 |
|
$this->method = $method; |
|
76
|
3 |
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get Method |
|
81
|
|
|
* |
|
82
|
|
|
* @return null|string |
|
83
|
|
|
* |
|
84
|
|
|
* @access public |
|
85
|
|
|
*/ |
|
86
|
3 |
|
public function getMethod() |
|
87
|
|
|
{ |
|
88
|
3 |
|
return $this->method; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get Form Params |
|
93
|
|
|
* |
|
94
|
|
|
* Get array suitable for Aura\Html form input helper |
|
95
|
|
|
* |
|
96
|
|
|
* @return array |
|
97
|
|
|
* |
|
98
|
|
|
* @access public |
|
99
|
|
|
*/ |
|
100
|
2 |
|
public function getFormParams() |
|
101
|
|
|
{ |
|
102
|
|
|
return [ |
|
103
|
2 |
|
'type' => 'hidden', |
|
104
|
2 |
|
'name' => $this->getMethodOverrideParam(), |
|
105
|
2 |
|
'value' => $this->getMethod() |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* __toString |
|
111
|
|
|
* |
|
112
|
|
|
* Get HTML string representing a hidden form input |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
* |
|
116
|
|
|
* @access public |
|
117
|
|
|
*/ |
|
118
|
2 |
|
public function __toString() |
|
119
|
|
|
{ |
|
120
|
2 |
|
if (!$this->method) { |
|
121
|
1 |
|
return ''; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
1 |
|
$out = '<input'; |
|
125
|
|
|
|
|
126
|
1 |
|
foreach ($this->getFormParams() as $key => $value) { |
|
127
|
1 |
|
$out .= ' ' . $key . '="' . $value . '"'; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
1 |
|
$out .= ' />'; |
|
131
|
|
|
|
|
132
|
1 |
|
return $out; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|