Changeset 1171

Show
Ignore:
Timestamp:
12/20/07 16:56:37 (1 year ago)
Author:
richi
Message:

refactored stubRegexFilterDecorator

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubRegexFilterDecorator.php

    r1166 r1171  
    7777    public function execute($value) 
    7878    { 
    79         if ($value != null) { 
     79        if ($value != null) {    
    8080            switch ($this->strategy) { 
    8181                case self::STRATEGY_BEFORE: 
    82                     $checked = @preg_match($this->regex, $value, $matches); 
    83                     if ($checked == false) { 
     82                    $matchAmount = @preg_match($this->regex, $value, $matches); 
     83                    if ($matchAmount === false) { 
    8484                        throw new stubRuntimeException('Invalid regular expression ' . $this->regex); 
     85                    } else { 
     86                        $result = ($matchAmount !== 0)? $this->getDecoratedFilter()->execute($matches[0]): null; 
    8587                    } 
    86                     $result = $this->getDecoratedFilter()->execute($matches[0]); 
    8788                    break; 
    8889 
    8990                case self::STRATEGY_AFTER: 
    9091                    $filtered = $this->getDecoratedFilter()->execute($value); 
    91                     $checked = @preg_match($this->regex, $filtered, $matches); 
    92                     if ($checked == false) { 
     92                    $matchAmount = @preg_match($this->regex, $filtered, $matches); 
     93                    if ($matchAmount === false) { 
    9394                        throw new stubRuntimeException('Invalid regular expression ' . $this->regex); 
     95                    } else { 
     96                        $result = $matches[0]; 
    9497                    } 
    95                     $result = $matches[0]; 
    9698                    break; 
    9799 
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubStringFilter.php

    r1166 r1171  
    77 * @subpackage  ipo_request_filters 
    88 */ 
    9 stubClassLoader::load('net.stubbles.ipo.request.filters.stubAbstractStringFilter'); 
    10 stubClassLoader::load('net.stubbles.ipo.request.filters.stubSimpleStringFilter'); 
     9stubClassLoader::load('net.stubbles.ipo.request.filters.stubAbstractStringFilter', 
     10                      'net.stubbles.ipo.request.filters.stubSimpleStringFilter' 
     11); 
    1112/** 
    1213 * Class for filtering strings (singe line). 
     
    1920 * @uses        net.stubbles.util.validators 
    2021 */ 
    21 class stubStringFilter extends stubAbstractStringFilter 
     22class stubStringFilter extends stubSimpleStringFilter 
    2223{ 
    2324    /** 
     
    6061    { 
    6162        if (null != $value) { 
    62             $simpleStringFilter = new stubSimpleStringFilter($this->rveFactory); 
    63             $value = $simpleStringFilter->execute($value); 
     63            $value = parent::doExecute($value); 
    6464 
    6565            if ($this->regex->validate($value) == false) { 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubRegexFilterDecoratorTestCase.php

    r1166 r1171  
    8282     
    8383    /** 
    84      * assure regex functionality (with valid & invalid) regex and filtering of values 
     84     * assure regex functionality and filtering of values  
     85     *  - with matching & nonmatching values 
     86     *  - with valid & invalid regex 
    8587     */ 
    8688    public function testBeforeDecoratorRegex()  
     
    8991        $this->assertEqual('start_middle', $result); 
    9092         
     93        $result = $this->beforeDecorator->execute('start_middle'); 
     94        $this->assertNull($result); 
     95         
    9196        $this->expectException('stubRuntimeException'); 
    92         $result = $this->beforeDecorator->execute('start_middle'); 
     97        $invalidRegexDecorator = new stubRegexFilterDecorator($this->ssFilter, 'noRegexSlashes', stubRegexFilterDecorator::STRATEGY_BEFORE); 
     98        $invalidRegexDecorator->execute('irrelevant for this test'); 
    9399    } 
    94100     
    95101    /** 
    96      * assure regex functionality (with valid & invalid) and filtering of values 
     102     * assure regex functionality and filtering of values  
     103     *  - with matching & nonmatching values 
     104     *  - with valid & invalid regex 
    97105     */ 
    98106    public function testAfterDecoratorRegex()  
     
    100108        $result = $this->afterDecorator->execute('start_middle_end'); 
    101109        $this->assertEqual('start_middle', $result); 
     110 
     111        $result = $this->afterDecorator->execute('start_middle'); 
     112        $this->assertNull($result); 
    102113         
    103114        $this->expectException('stubRuntimeException'); 
    104         $result = $this->afterDecorator->execute('start_middle'); 
     115        $invalidRegexDecorator = new stubRegexFilterDecorator($this->ssFilter, 'noRegexSlashes', stubRegexFilterDecorator::STRATEGY_AFTER); 
     116        $invalidRegexDecorator->execute('irrelevant for this test'); 
    105117    } 
    106118     
     
    112124        $invalidStrategyDecorator = new stubRegexFilterDecorator($this->ssFilter, $this->regex, -23); 
    113125        $this->expectException('stubIllegalArgumentException'); 
    114         $invalidStrategyDecorator->execute('not important'); 
    115         $invalidStrategyDecorator->execute('not important'); 
     126        $invalidStrategyDecorator->execute('irrelevant for this test'); 
     127        $invalidStrategyDecorator->execute('irrelevant for this test'); 
    116128    } 
    117129}