/** * Validate element value * * @param array $value * @return boolean */ public function isValid($value, $context = null, $removeNotPresentFields = false) { if (!($value instanceof $this->_model || $this->_acceptArrayAsModel && is_array($value))) { $this->_error(self::NOT_MODEL); return false; } if ($value instanceof ModelAbstract) { $valueKeys = array_keys($value->exportData()); } else { $valueKeys = array_keys($value); } $keyValidator = new \App_Validate_Array($this->_keysSpec); if (!$keyValidator->isValid($valueKeys)) { $this->_messages = $keyValidator->getMessages(); return false; } $chContext = $context; $limit = 5; while (isset($chContext['__parent'])) { $chContext = $chContext['__parent']; $limit--; } if ($limit < 0) { $this->_error(self::TOO_MUCH_DEPTH); return false; } if (!empty($value)) { $itemValidator = $this->_getValidator($value[0]); if (!$itemValidator) { $this->_error(self::INVALID_ITEM_TYPE); return false; } $countVal = new \App_Validate_ArrayCount(); $countVal->setMax($this->_maxFields); // if ($itemValidator instanceof ModelAbstractValidate) { // $countVal->setMax(10); // } if (!$countVal->isValid($value)) { $this->_messages = $countVal->getMessages(); return false; } foreach ($value as $item) { if (!$itemValidator->isValid($item, $context, $removeNotPresentFields)) { $this->_error(self::NOT_HOMOGENUOUS_ARRAY); return false; } } } return true; }
/** * Validate element value * * @param array $data * @param mixed $context * @return boolean */ public function isValid($value, $context = array()) { $countValidator = new App_Validate_ArrayCount(array('min' => 0, 'max' => 10)); if (!$countValidator->isValid($value)) { $this->_messages = $countValidator->getMessages(); return false; } $arrayValidator = new App_Validate_Array(array('distinct' => true, 'ignoreEmpties' => true, 'validators' => array('Apn' => array('breakChainOnFailure' => true, 'optional' => true)))); if (!$arrayValidator->isValid($value, $context)) { $this->_messages = $arrayValidator->getMessages(); return false; } return true; }
/** * Validate element value * * @param array $data * @param mixed $context * @return boolean */ public function isValid($value, $context = array()) { $arrayValidator = new App_Validate_Array(array('validators' => array('SimApn' => array('breakChainOnFailure' => true)))); if (!$arrayValidator->isValid($value, $context)) { $this->_messages = $arrayValidator->getMessages(); return false; } $sim = new Application\Model\SimModel($context); $apns = $sim->getCustomer()->getApnList(); $staticApns = array_keys($apns, true); $commonApns = array_intersect($value, $staticApns); if (count($commonApns) > 1) { $this->_error(self::TOO_MANY_STATIC_ADDRESSIN_APNS); return false; } return true; }
/** * Validate element value * * @param array $value * @return boolean */ public function isValid($value, $context = null, $removeNotPresentFields = false) { if (!($value instanceof $this->_model || $this->_acceptArrayAsModel && is_array($value))) { $this->_error(self::NOT_MODEL); return false; } if ($value instanceof ModelAbstract) { $valueKeys = array_keys($value->exportData()); } else { $valueKeys = array_keys($value); } $keyValidator = new \App_Validate_Array($this->_keysSpec); if (!$keyValidator->isValid($valueKeys)) { $this->_messages = $keyValidator->getMessages(); return false; } $validator = new \App_Validate_ArrayCount(array('max' => $this->_maxFields)); if (!$validator->isValid($value, $context, $removeNotPresentFields)) { $this->_messages = $validator->getMessages(); return false; } $validator = new \App_Validate_Array($this->_spec); if (!$validator->isValid($value, $context, $removeNotPresentFields)) { $this->_messages = $validator->getMessages(); return false; } $chContext = $context; $limit = 5; while (isset($chContext['__parent'])) { $chContext = $chContext['__parent']; $limit--; } if ($limit < 0) { $this->_error(self::TOO_MUCH_DEPTH); return false; } return true; }
public function __construct($spec, $options = null) { parent::__construct($spec, $options); $this->addValidators(array('regex' => array('pattern' => '/^[0-9]*\\*?[0-9]*$/', 'breakChainOnFailure' => true), 'StringLength' => array('max' => 32, 'encoding' => "UTF-8", 'breakChainOnFailure' => true))); }
public function testNonArray() { $this->assertFalse($this->_validator->isValid(1)); $messages = $this->_validator->getMessages(); $this->assertArrayHasKey(App_Validate_Array::NOT_ARRAY, $messages); }