Changeset 1412

Show
Ignore:
Timestamp:
12/08/06 04:35:31 (2 years ago)
Author:
dominik
Message:

add a method which allows the validator to provide the keys for the current base
refs #361

Location:
branches/0.11/src/validator
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/src/validator/AgaviBaseFileValidator.class.php

    r1389 r1412  
    109109    return true; 
    110110  } 
     111 
     112  /** 
     113   * Returns all available keys in the currently set base. 
     114   * 
     115   * @return     array The available keys. 
     116   * 
     117   * @author     Dominik del Bondio <ddb@bitxtender.com 
     118   * @since      0.11.0 
     119   */ 
     120  protected function getKeysInCurrentBase() 
     121  { 
     122    $files = $this->getContext()->getRequest()->getFiles(); 
     123    $array = array(); 
     124    foreach($files as $name => $file) { 
     125      $array[$name] = $file['name']; 
     126    } 
     127 
     128    $names = $this->curBase->getValue($array, array()); 
     129    return array_keys($names); 
     130  } 
     131 
    111132} 
    112133 
  • branches/0.11/src/validator/AgaviValidator.class.php

    r1397 r1412  
    576576       * names 
    577577       */ 
    578       $array = $this->validationParameters->getParameters(); 
    579       $names = $this->curBase->getValue($array, array()); 
     578      $names = $this->getKeysInCurrentBase(); 
     579 
     580      // if the names array is empty this means we need to throw an error since 
     581      // this means the input doesn't exist 
     582      if(count($names) == 0) { 
     583        if($this->getParameter('required', true)) { 
     584          $this->throwError(); 
     585          return self::mapErrorCode($this->getParameter('severity', 'error')); 
     586        } else { 
     587          // no reason to throw any error since it wouldn't be included anyways 
     588          return self::NONE; 
     589        } 
     590      } 
    580591 
    581592      // throw the wildcard away 
     
    585596 
    586597      // validate in every name defined in the request 
    587       foreach(array_keys($names) as $name) { 
     598      foreach($names as $name) { 
    588599        $t = $this->validateInBase($base->pushRetNew($name)); 
    589600 
     
    654665  } 
    655666 
     667 
     668  /** 
     669   * Returns all available keys in the currently set base. 
     670   * 
     671   * @return     array The available keys. 
     672   * 
     673   * @author     Dominik del Bondio <ddb@bitxtender.com 
     674   * @since      0.11.0 
     675   */ 
     676  protected function getKeysInCurrentBase() 
     677  { 
     678    $array = $this->validationParameters->getParameters(); 
     679    $names = $this->curBase->getValue($array, array()); 
     680 
     681    return array_keys($names); 
     682  } 
     683 
    656684} 
    657685