blob: 3c74716d6927bfe50aee79a16f170cb090b875b1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<?php
namespace ParamProcessor\Definition;
use ParamProcessor\ParamDefinition;
use ParamProcessor\IParam;
/**
* Defines the string parameter type.
* Specifies the type specific validation and formatting logic.
*
* @deprecated since 1.7
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class StringParam extends ParamDefinition {
/**
* Indicates if the parameter should be lowercased post validation.
*
* @since 1.0
*
* @var boolean
*/
protected $toLower = false;
/**
* Formats the parameter value to it's final result.
* @see ParamDefinition::formatValue
*
* @since 1.0
*
* @param $value mixed
* @param $param IParam
* @param $definitions array of IParamDefinition
* @param $params array of IParam
*
* @return mixed
*/
protected function formatValue( $value, IParam $param, array &$definitions, array $params ) {
$value = (string)$value;
if ( $this->toLower ) {
$value = strtolower( $value );
}
return $value;
}
/**
* Sets the parameter definition values contained in the provided array.
* @see ParamDefinition::setArrayValues
*
* @since 1.0
*
* @param array $param
*/
public function setArrayValues( array $param ) {
parent::setArrayValues( $param );
if ( array_key_exists( 'tolower', $param ) ) {
$this->toLower = $param['tolower'];
}
}
/**
* Sets of the value should be lowercased.
*
* @since 1.0
*
* @param boolean $toLower
*/
public function setToLower( $toLower ) {
$this->toLower = $toLower;
}
}
|