| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
stubClassLoader::load('net::stubbles::ipo::request::validator::stubEqualValidator', |
|---|
| 13 |
'net::stubbles::websites::variantmanager::types::stubAbstractVariant' |
|---|
| 14 |
); |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
class stubRequestParamVariant extends stubAbstractVariant |
|---|
| 24 |
{ |
|---|
| 25 |
|
|---|
| 26 |
* the name of the request parameter |
|---|
| 27 |
* |
|---|
| 28 |
* @var string |
|---|
| 29 |
*/ |
|---|
| 30 |
private $paramName = null; |
|---|
| 31 |
|
|---|
| 32 |
* the value of the request parameter |
|---|
| 33 |
* |
|---|
| 34 |
* @var string |
|---|
| 35 |
*/ |
|---|
| 36 |
private $paramValue = null; |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
* check whether the variant is an enforcing variant |
|---|
| 40 |
* |
|---|
| 41 |
* @param stubSession $session access to session |
|---|
| 42 |
* @param stubRequest $request access to request parameters |
|---|
| 43 |
* @return bool |
|---|
| 44 |
* @throws stubVariantConfigurationException |
|---|
| 45 |
*/ |
|---|
| 46 |
public function isEnforcing(stubSession $session, stubRequest $request) |
|---|
| 47 |
{ |
|---|
| 48 |
return $this->isValid($session, $request); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
* check whether the variant is valid |
|---|
| 53 |
* |
|---|
| 54 |
* @param stubSession $session access to session |
|---|
| 55 |
* @param stubRequest $request access to request parameters |
|---|
| 56 |
* @return bool |
|---|
| 57 |
* @throws stubVariantConfigurationException |
|---|
| 58 |
*/ |
|---|
| 59 |
public function isValid(stubSession $session, stubRequest $request) |
|---|
| 60 |
{ |
|---|
| 61 |
if (null == $this->paramName) { |
|---|
| 62 |
throw new stubVariantConfigurationException('RequestParamVariant requires the param name to be set.'); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
if ($request->hasValue($this->paramName) == false) { |
|---|
| 66 |
return false; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
if (null == $this->paramValue) { |
|---|
| 70 |
return true; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
return $request->validateValue(new stubEqualValidator($this->paramValue), $this->paramName); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
* Set the name of the request parameter |
|---|
| 78 |
* |
|---|
| 79 |
* @param string $paramName the paramName to set |
|---|
| 80 |
*/ |
|---|
| 81 |
public function setParamName($paramName) |
|---|
| 82 |
{ |
|---|
| 83 |
$this->paramName = $paramName; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
* Set the desired value of the request parameter |
|---|
| 88 |
* |
|---|
| 89 |
* @param string $paramValue the paramValue to set |
|---|
| 90 |
*/ |
|---|
| 91 |
public function setParamValue($paramValue) |
|---|
| 92 |
{ |
|---|
| 93 |
$this->paramValue = $paramValue; |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
?> |
|---|