root/trunk/src/main/php/net/stubbles/websites/variantmanager/types/stubRequestParamVariant.php

Revision 1547, 2.6 kB (checked in by mikey, 3 months ago)

refactoring #139, part 6: moved net::stubbles::util::validators to net::stubbles::ipo::request::validators

Line 
1 <?php
2 /**
3  * RequestParamVariant
4  *
5  * Will be triggered, if the request contains a specified parameter
6  *
7  * @author      Stephan Schmidt <stephan.schmidt@schlund.de>
8  * @author      Frank Kleine <mikey@stubbles.net>
9  * @package     stubbles
10  * @subpackage  websites_variantmanager_types
11  */
12 stubClassLoader::load('net::stubbles::ipo::request::validator::stubEqualValidator',
13                       'net::stubbles::websites::variantmanager::types::stubAbstractVariant'
14 );
15 /**
16  * RequestParamVariant
17  *
18  * Will be triggered, if the request contains a specified parameter
19  *
20  * @package     stubbles
21  * @subpackage  websites_variantmanager_types
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 ?>
Note: See TracBrowser for help on using the browser.