1 | <?php |
||
17 | abstract class AbstractFormatterProvider implements FormatterProvider |
||
18 | { |
||
19 | protected $defaultFormatter; |
||
20 | /** |
||
21 | * method prefix |
||
22 | */ |
||
23 | const METHOD_PATTERN_MATCH = '/^as([A-Z]\w+)$/'; |
||
24 | |||
25 | public $nullValue = '<span>Not Set</span>'; |
||
26 | |||
27 | /** |
||
28 | * Provide a list of formatters this that are available from this provider |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | public function formats() |
||
47 | |||
48 | /** |
||
49 | * Get the name of the formatter method |
||
50 | * |
||
51 | * @param ReflectionMethod $method |
||
52 | * @return string |
||
53 | */ |
||
54 | private function getFormatterName(ReflectionMethod $method) |
||
61 | |||
62 | /** |
||
63 | * Combine the value & params |
||
64 | * @param mixed $value the value (first argument of the format method) |
||
65 | * @param string|array $format the name of the formatter, or an array of |
||
66 | * the formatter and its addtional params |
||
67 | * @return array of two elements, format and the params for the formatter |
||
68 | * method |
||
69 | * @throws InvalidArgumentException if the format is incorrect |
||
70 | */ |
||
71 | protected function extractFormatAndParams($value, $format) |
||
88 | |||
89 | /** |
||
90 | * Format the supplied value, based on the desired format + configuration |
||
91 | * |
||
92 | * @param mixed $value The value to format |
||
93 | * @param string|array|null $format either the formatter name, or the formatter |
||
94 | * config as an array. If it's an array, the |
||
95 | * first item must be the same of the formatter |
||
96 | * @return mixed |
||
97 | * @throws InvalidArgumentException if the format is incorrect |
||
98 | */ |
||
99 | public function format($value, $format = null) |
||
117 | |||
118 | /** |
||
119 | * Check if the requested format exists in this provider |
||
120 | * |
||
121 | * @param string $format The formatter name you want to check for |
||
122 | * @return boolean |
||
123 | */ |
||
124 | public function hasFormat($format) |
||
135 | } |
||
136 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.