/**
  * @see        AgaviValidator::initialize
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 public function initialize(AgaviContext $context, array $parameters = array(), array $arguments = array(), array $errors = array())
 {
     if (!isset($parameters['source'])) {
         $parameters['source'] = AgaviWebRequestDataHolder::SOURCE_FILES;
     }
     parent::initialize($context, $parameters, $arguments, $errors);
 }
Ejemplo n.º 2
0
 /**
  * We need to return true here when this validator is required, because 
  * otherwise the is*ValueEmpty check would make empty but set fields not 
  * reach the validate method.
  *
  * @see        AgaviValidator::checkAllArgumentsSet
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 protected function checkAllArgumentsSet($throwError = true)
 {
     if ($this->getParameter('required', true)) {
         return true;
     } else {
         return parent::checkAllArgumentsSet($throwError);
     }
 }
Ejemplo n.º 3
0
 /**
  * @see        AgaviValidator::initialize
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 public function initialize(AgaviContext $context, array $parameters = array(), array $arguments = array(), array $errors = array())
 {
     if (!isset($parameters['source'])) {
         $parameters['source'] = AgaviWebRequestDataHolder::SOURCE_FILES;
     }
     parent::initialize($context, $parameters, $arguments, $errors);
     if ($this->hasParameter('mime_type') && !extension_loaded('fileinfo')) {
         throw new AgaviValidatorException('MIME type checks in file validators require the "fileinfo" PHP extension to be loaded.');
     }
 }
Ejemplo n.º 4
0
 /**
  * Executes the validator.
  * 
  * Executes the operators validate()-Method after checking the quantity
  * of child validators with checkValidSetup().
  * 
  * @param      AgaviParameterHolder The parameters which should be validated.
  *
  * @return     int The result of validation (SUCCESS, NONE, NOTICE, ERROR, CRITICAL).
  *
  * @author     Uwe Mesecke <*****@*****.**>
  * @since      0.11.0
  */
 public function execute(AgaviRequestDataHolder $parameters)
 {
     // check if we have a valid setup of validators
     $this->checkValidSetup();
     $result = parent::execute($parameters);
     if ($result != AgaviValidator::SUCCESS && !$this->getParameter('skip_errors') && $this->result == AgaviValidator::CRITICAL) {
         /*
          * one of the child validators resulted with CRITICAL
          * we change our operator's result to CRITICAL, too so the
          * surrounding validator container is aware of the critical
          * result and can abort further validation... 
          */
         $result = AgaviValidator::CRITICAL;
     }
     return $result;
 }
 /**
  * Adds a new child validator.
  *
  * @param      AgaviValidator The new child validator.
  *
  * @author     Uwe Mesecke <*****@*****.**>
  * @since      0.11.0
  */
 public function addChild(AgaviValidator $validator)
 {
     $name = $validator->getName();
     if (isset($this->children[$name])) {
         throw new InvalidArgumentException('A validator with the name "' . $name . '" already exists');
     }
     $this->children[$name] = $validator;
     $validator->setParentContainer($this);
 }
Ejemplo n.º 6
0
 public function testMapErrorCode()
 {
     $this->assertEquals(AgaviValidator::mapErrorCode('info'), AgaviValidator::INFO);
     $this->assertEquals(AgaviValidator::mapErrorCode('none'), AgaviValidator::NONE);
     $this->assertEquals(AgaviValidator::mapErrorCode('silent'), AgaviValidator::NONE);
     $this->assertEquals(AgaviValidator::mapErrorCode('notice'), AgaviValidator::NOTICE);
     $this->assertEquals(AgaviValidator::mapErrorCode('error'), AgaviValidator::ERROR);
     $this->assertEquals(AgaviValidator::mapErrorCode('critical'), AgaviValidator::CRITICAL);
     $this->assertEquals(AgaviValidator::mapErrorCode('cRiTiCaL'), AgaviValidator::CRITICAL);
     try {
         AgaviValidator::mapErrorCode('foo');
         $this->fail();
     } catch (AgaviValidatorException $e) {
         $this->assertEquals($e->getMessage(), 'unknown error code: foo');
     }
 }