Changeset 969
- Timestamp:
- 10/21/07 19:41:28 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotation.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubTextFilterAnnotation.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubAbstractStringFilter.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotationTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubTextFilterAnnotationTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotation.php
r736 r969 10 10 'net.stubbles.ipo.request.filters.stubStringFilter', 11 11 'net.stubbles.ipo.request.broker.annotations.stubAbstractFilterAnnotation', 12 'net.stubbles.php.string.stubStringEncoder', 12 13 'net.stubbles.util.validators.stubMaxLengthValidator', 13 14 'net.stubbles.util.validators.stubMinLengthValidator', … … 39 40 * @var string 40 41 */ 41 protected $regex = null; 42 protected $regex = null; 43 /** 44 * the encoder class to be used 45 * 46 * @var stubReflectionClass 47 */ 48 protected $encoderClass = null; 49 /** 50 * the encoding mode to be applied 51 * 52 * @var int 53 */ 54 protected $encoderMode = stubStringEncoder::MODE_DECODE; 42 55 43 56 /** 44 * checks if the regex property is set 57 * checks if the regex property is set and if the encoder mode is correct 45 58 * 46 59 * @throws ReflectionException … … 50 63 if (null === $this->regex) { 51 64 throw new ReflectionException('Can not use ' . $this->getClassName() . ' without setting the regular expression via regex property.'); 65 } 66 67 if (null !== $this->encoderClass && in_array($this->encoderMode, array(stubStringEncoder::MODE_DECODE, stubStringEncoder::MODE_ENCODE)) === false) { 68 throw new ReflectionException('Can not use ' . $this->getClassName() . ' with wrong encoder mode ' . $this->encoderMode); 52 69 } 53 70 } … … 84 101 85 102 /** 103 * sets the encoder class to be used 104 * 105 * @param stubReflectionClass $encoder 106 */ 107 public function setEncoder(stubReflectionClass $encoderClass) 108 { 109 $this->encoderClass = $encoderClass; 110 } 111 112 /** 113 * sets the encoder mode to be used 114 * 115 * @param int $mode 116 */ 117 public function setEncoderMode($mode) 118 { 119 $this->encoderMode = $mode; 120 } 121 122 /** 86 123 * returns the filter defined by the annotation 87 124 * … … 100 137 } 101 138 139 if (null !== $this->encoderClass) { 140 $stringFilter->setEncoder($this->encoderClass->newInstance(), $this->encoderMode); 141 } 142 102 143 return $stringFilter; 103 144 } trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubTextFilterAnnotation.php
r731 r969 10 10 'net.stubbles.ipo.request.filters.stubTextFilter', 11 11 'net.stubbles.ipo.request.broker.annotations.stubAbstractFilterAnnotation', 12 'net.stubbles.php.string.stubStringEncoder', 12 13 'net.stubbles.util.validators.stubMaxLengthValidator', 13 14 'net.stubbles.util.validators.stubMinLengthValidator', … … 40 41 */ 41 42 protected $allowedTags = array(); 43 /** 44 * the encoder class to be used 45 * 46 * @var stubReflectionClass 47 */ 48 protected $encoderClass = null; 49 /** 50 * the encoding mode to be applied 51 * 52 * @var int 53 */ 54 protected $encoderMode = stubStringEncoder::MODE_DECODE; 55 56 /** 57 * checks if the encoder mode is correct 58 * 59 * @throws ReflectionException 60 */ 61 public function finish() 62 { 63 if (null !== $this->encoderClass && in_array($this->encoderMode, array(stubStringEncoder::MODE_DECODE, stubStringEncoder::MODE_ENCODE)) === false) { 64 throw new ReflectionException('Can not use ' . $this->getClassName() . ' with wrong encoder mode ' . $this->encoderMode); 65 } 66 } 42 67 43 68 /** … … 75 100 76 101 /** 102 * sets the encoder class to be used 103 * 104 * @param stubReflectionClass $encoder 105 */ 106 public function setEncoder(stubReflectionClass $encoderClass) 107 { 108 $this->encoderClass = $encoderClass; 109 } 110 111 /** 112 * sets the encoder mode to be used 113 * 114 * @param int $mode 115 */ 116 public function setEncoderMode($mode) 117 { 118 $this->encoderMode = $mode; 119 } 120 121 /** 77 122 * returns the filter defined by the annotation 78 123 * … … 91 136 } 92 137 138 if (null !== $this->encoderClass) { 139 $textFilter->setEncoder($this->encoderClass->newInstance(), $this->encoderMode); 140 } 141 93 142 $textFilter->setAllowedTags($this->allowedTags); 94 143 return $textFilter; trunk/src/main/php/net/stubbles/ipo/request/filters/stubAbstractStringFilter.php
r968 r969 99 99 100 100 /** 101 * returns the encoder to be applied onto the value to filter 102 * 103 * @return stubStringEncoder 104 */ 105 public function getEncoder() 106 { 107 return $this->encoder; 108 } 109 110 /** 111 * returns the encoder mode to be applied onto the value to filter 112 * 113 * @return int 114 */ 115 public function getEncoderMode() 116 { 117 return $this->encoderMode; 118 } 119 120 /** 101 121 * filter strings 102 122 * trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotationTestCase.php
r964 r969 63 63 64 64 /** 65 * assert that the encoder is set correct 66 */ 67 public function testWithEncoder() 68 { 69 $this->stringFilterAnnotation->setEncoder(new stubReflectionClass('net.stubbles.php.string.stubMd5Encoder')); 70 $stringFilter = $this->stringFilterAnnotation->getFilter(); 71 $this->assertIsA($stringFilter->getEncoder(), 'stubMd5Encoder'); 72 $this->assertEqual($stringFilter->getEncoderMode(), stubStringEncoder::MODE_DECODE); 73 $this->stringFilterAnnotation->setEncoderMode(stubStringEncoder::MODE_ENCODE); 74 $stringFilter = $this->stringFilterAnnotation->getFilter(); 75 $this->assertIsA($stringFilter->getEncoder(), 'stubMd5Encoder'); 76 $this->assertEqual($stringFilter->getEncoderMode(), stubStringEncoder::MODE_ENCODE); 77 } 78 79 /** 65 80 * test that finish() works as expected 66 81 */ 67 public function testFinish ()82 public function testFinishWithoutRegex() 68 83 { 69 84 $this->stringFilterAnnotation->setRegex(); … … 71 86 $this->stringFilterAnnotation->finish(); 72 87 } 88 89 /** 90 * test that finish() works as expected 91 */ 92 public function testFinishWithWrongEncoderMode() 93 { 94 $this->stringFilterAnnotation->setEncoder(new stubReflectionClass('net.stubbles.php.string.stubMd5Encoder')); 95 $this->stringFilterAnnotation->setEncoderMode('invalid'); 96 $this->expectException('ReflectionException'); 97 $this->stringFilterAnnotation->finish(); 98 } 73 99 } 74 100 ?> trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubTextFilterAnnotationTestCase.php
r731 r969 59 59 $this->assertEqual($textFilter->getAllowedTags(), array('foo', 'bar', 'baz')); 60 60 } 61 62 /** 63 * assert that the encoder is set correct 64 */ 65 public function testWithEncoder() 66 { 67 $this->textFilterAnnotation->setEncoder(new stubReflectionClass('net.stubbles.php.string.stubMd5Encoder')); 68 $textFilter = $this->textFilterAnnotation->getFilter(); 69 $this->assertIsA($textFilter->getEncoder(), 'stubMd5Encoder'); 70 $this->assertEqual($textFilter->getEncoderMode(), stubStringEncoder::MODE_DECODE); 71 $this->textFilterAnnotation->setEncoderMode(stubStringEncoder::MODE_ENCODE); 72 $textFilter = $this->textFilterAnnotation->getFilter(); 73 $this->assertIsA($textFilter->getEncoder(), 'stubMd5Encoder'); 74 $this->assertEqual($textFilter->getEncoderMode(), stubStringEncoder::MODE_ENCODE); 75 } 76 77 /** 78 * test that finish() works as expected 79 */ 80 public function testFinishWithWrongEncoderMode() 81 { 82 $this->textFilterAnnotation->setEncoder(new stubReflectionClass('net.stubbles.php.string.stubMd5Encoder')); 83 $this->textFilterAnnotation->setEncoderMode('invalid'); 84 $this->expectException('ReflectionException'); 85 $this->textFilterAnnotation->finish(); 86 } 61 87 } 62 88 ?>
