root/trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubIntegerFilterAnnotation.php @ 1547

Revision 1547, 2.9 kB (checked in by mikey, 2 years ago)

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

Line 
1<?php
2/**
3 * Filter annotation for integers.
4 *
5 * @author      Frank Kleine <mikey@stubbles.net>
6 * @package     stubbles
7 * @subpackage  ipo_request_broker_annotations
8 */
9stubClassLoader::load('net::stubbles::reflection::annotations::stubAnnotation',
10                      'net::stubbles::ipo::request::broker::annotations::stubAbstractFilterAnnotation',
11                      'net::stubbles::ipo::request::filter::stubIntegerFilter',
12                      'net::stubbles::ipo::request::filter::stubRangeFilterDecorator',
13                      'net::stubbles::ipo::request::validator::stubMaxNumberValidator',
14                      'net::stubbles::ipo::request::validator::stubMinNumberValidator'
15);
16/**
17 * Filter annotation for integers.
18 *
19 * @package     stubbles
20 * @subpackage  ipo_request_broker_annotations
21 */
22class stubIntegerFilterAnnotation extends stubAbstractFilterAnnotation implements stubAnnotation
23{
24    /**
25     * minimum value of the integer
26     *
27     * @var  int
28     */
29    protected $minValue;
30    /**
31     * the error id to use in case min validation fails
32     *
33     * @var  string
34     */
35    protected $minErrorId;
36    /**
37     * maximum value of the integer
38     *
39     * @var  int
40     */
41    protected $maxValue;
42    /**
43     * the error id to use in case max validation fails
44     *
45     * @var  string
46     */
47    protected $maxErrorId;
48
49    /**
50     * sets the minimum value of the integer
51     *
52     * @param  int  $minValue
53     */
54    public function setMinValue($minValue)
55    {
56        $this->minValue = $minValue;
57    }
58
59    /**
60     * sets the error id to use in case max validation fails
61     *
62     * @param  string  $minErrorId
63     */
64    public function setMinErrorId($minErrorId)
65    {
66        $this->minErrorId = $minErrorId;
67    }
68
69    /**
70     * sets the maximum value of the integer
71     *
72     * @param  int  $maxValue
73     */
74    public function setMaxValue($maxValue)
75    {
76        $this->maxValue = $maxValue;
77    }
78
79    /**
80     * sets the error id to use in case max validation fails
81     *
82     * @param  string  $maxErrorId
83     */
84    public function setMaxErrorId($maxErrorId)
85    {
86        $this->maxErrorId = $maxErrorId;
87    }
88
89    /**
90     * returns the filter defined by the annotation
91     *
92     * @return  stubFilter
93     */
94    protected function doGetFilter()
95    {
96        $filter = new stubIntegerFilter();
97        if (null !== $this->minValue || null !== $this->maxValue) {
98            $filter = new stubRangeFilterDecorator($filter, $this->createRVEFactory());
99            if (null !== $this->minValue) {
100                $filter->setMinValidator(new stubMinNumberValidator($this->minValue), $this->minErrorId);
101            }
102           
103            if (null !== $this->maxValue) {
104                $filter->setMaxValidator(new stubMaxNumberValidator($this->maxValue), $this->maxErrorId);
105            }
106        }
107       
108        return $filter;
109    }
110}
111?>
Note: See TracBrowser for help on using the browser.