1
|
|
|
<?php |
2
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed'); |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Allows client code to pass in a format string used as the first argument for |
7
|
|
|
* `vsprintf` and that will be included in vsprintf to include all the subsections |
8
|
|
|
* for the layout. |
9
|
|
|
* |
10
|
|
|
* @package ${PluginName} |
11
|
|
|
* @subpackage ${context} |
12
|
|
|
* @author Darren Ethier |
13
|
|
|
* @since ${version} |
14
|
|
|
*/ |
15
|
|
|
class EE_Vsprintf_Layout extends EE_No_Layout |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Will hold the incoming format string to be used for the vsprintf first argument. |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $_v_format = ''; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* EE_Vsprintf_Layout constructor. |
28
|
|
|
* |
29
|
|
|
* @param array $options Expects an array with 'vsprintf_format' as a key to represent the format argument that |
30
|
|
|
* will be passed to the vsprintf function. Make sure the number of placeholders matches |
31
|
|
|
* the number of subsections in your form. |
32
|
|
|
*/ |
33
|
|
|
public function __construct($options = array()) |
34
|
|
|
{ |
35
|
|
|
$this->_v_format = isset($options['vsprintf_format']) |
36
|
|
|
? (string) $options['vsprintf_format'] |
37
|
|
|
: ''; |
38
|
|
|
parent::__construct($options); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function layout_form_loop() |
44
|
|
|
{ |
45
|
|
|
$vsprintf_args = array(); |
46
|
|
|
foreach ($this->_form_section->subsections() as $name => $subsection) { |
47
|
|
|
if ($subsection instanceof EE_Form_Input_Base) { |
48
|
|
|
$vsprintf_args[$name] = apply_filters( |
49
|
|
|
'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' . $name . '__in_' . $this->_form_section->name(), |
50
|
|
|
$this->layout_input($subsection), |
51
|
|
|
$this->_form_section, |
52
|
|
|
$subsection |
53
|
|
|
); |
54
|
|
View Code Duplication |
} elseif ($subsection instanceof EE_Form_Section_Base) { |
55
|
|
|
$vsprintf_args[$name] = apply_filters( |
56
|
|
|
'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' . $name . '__in_' . $this->_form_section->name(), |
57
|
|
|
$this->layout_subsection($subsection), |
|
|
|
|
58
|
|
|
$this->_form_section, |
59
|
|
|
$subsection |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
return vsprintf($this->_v_format, $vsprintf_args); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.