protected function doClean($value)
 {
     set_time_limit(0);
     $uploads = new Doctrine_Collection($this->getOption('model'));
     $fileValidator = new sfValidatorFile(array('mime_types' => 'web_images'));
     $descriptionValidator = new sfValidatorString(array('max_length' => 255, 'required' => false, 'trim' => true));
     foreach ($value as $file) {
         $validatedDescription = $descriptionValidator->clean($file['description']);
         if (isset($file['file']) && is_array($file['file']) && $file['file']['tmp_name']) {
             $validatedFile = $fileValidator->clean($file['file']);
             try {
                 $uploadedFileRecord = tsUpload::create($validatedFile, $this->getOption('rule'))->process();
             } catch (tsUploadException $e) {
                 throw new sfValidatorError($this, $e->getMessage());
             }
             $uploadedFileRecord->name = $validatedFile->getOriginalName();
             $uploadedFileRecord->description = $validatedDescription;
             $uploads[] = $uploadedFileRecord;
         } elseif (isset($file['id'])) {
             $uploadedFileRecord = Doctrine::getTable($this->getOption('model'))->findOneById($file['id']);
             if ($uploadedFileRecord) {
                 $uploadedFileRecord->description = $validatedDescription;
                 $uploads[] = $uploadedFileRecord;
             }
         }
         if ($this->getOption('max_count') && count($uploads) > $this->getOption('max_count')) {
             throw new sfValidatorError($this, 'max_count', array('value' => $value, 'max_count' => $this->getOption('max_count')));
         }
     }
     return $uploads;
 }
 public function postValidator($validator, $values)
 {
     if (isset($values['categories_list_add']) && is_array($values['categories_list_add'])) {
         $stringValidator = new sfValidatorString();
         foreach ($values['categories_list_add'] as $key => $value) {
             $values['categories_list_add'][$key] = $stringValidator->clean($value);
         }
     }
     return $values;
 }
 public function init()
 {
     $passwordValidator = new sfValidatorString(array("required" => true, 'min_length' => 6));
     $passwordValidator->addMessage('min_length', "You password must be 6 characters or greater.");
     $passwordValidator->addMessage('required', "You must enter a password.");
     $existingPasswordValidator = new sfValidatorCallback(array('callback' => 'ChangePasswordForm::checkExistingPassword', 'arguments' => array('username' => sfContext::getInstance()->getUser()->getUsername())), array('invalid' => 'Wrong password.'));
     $this->addWidget('old_password', new sfWidgetFormInputPassword(), $existingPasswordValidator);
     $this->addWidget('new_password', new sfWidgetFormInputPassword(), $passwordValidator);
     $this->addWidget('confirm_new_password', new sfWidgetFormInputPassword(), new sfValidatorString(array("required" => true), array("required" => "Please confirm your password.")));
     $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'confirm_password'));
 }
 public function __construct()
 {
     $options = array('required' => true, 'trim' => true, 'min_length' => 6, 'max_length' => 128);
     // Don't print passwords when complaining about inadequate length
     $messages = array('min_length' => 'That password is too short. It must contain a minimum of %min_length% characters.');
     parent::__construct($options, $messages);
 }
 /**
  * @see sfValidatorUrl
  */
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     if ($value !== dmOs::sanitizeDirName($value)) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     return $value;
 }
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     if ($clean != long2ip(ip2long($clean))) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     return $clean;
 }
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     if (!preg_match($this->getPattern(), $value)) {
         throw new sfValidatorError($this, 'match', array('value' => $value));
     }
     return $value;
 }
 /**
  * @param mixed $value
  * @return mixed|string
  * @throws sfValidatorError
  */
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     if (!DecisionTable::getInstance()->verifyAvailableNameByUserId($this->getOption('user_id'), $clean, $this->getOption('decision_id'))) {
         throw new sfValidatorError($this, 'busy_name');
     }
     return $clean;
 }
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     if ($clean != htmlspecialchars($clean, ENT_NOQUOTES)) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     return $clean;
 }
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->setMessage('required', isset($messages['required']) ? $messages['required'] : 'Obrigatório.');
     $this->setMessage('invalid', isset($messages['invalid']) ? $messages['invalid'] : 'Preenchimento incorreto.');
     $this->setMessage('min_length', isset($messages['min_length']) ? $messages['min_length'] : 'Valor muito curto. Preencha pelo menos %min_length% caracteres.');
     $this->setMessage('max_length', isset($messages['max_length']) ? $messages['max_length'] : 'Valor muito longo. Preencha no máximo %max_length% caracteres.');
 }
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     if (isset($options['email'])) {
         $validatorEmail = new sfValidatorEmail();
         try {
             $options['email'] = $validatorEmail->clean($options['email']);
         } catch (Exception $e) {
             throw new sfCommandException('The email is invalid.');
         }
         $emails = array('sf_plop_messaging_from_email', 'sf_plop_messaging_to_email');
         foreach ($emails as $email) {
             sfPlopConfigPeer::addOrUpdate($email, $options['email'], $con);
         }
     }
     if (isset($options['email'])) {
         $validatorName = new sfValidatorString();
         try {
             $options['name'] = $validatorName->clean($options['name']);
         } catch (Exception $e) {
             throw new sfCommandException('The name is invalid.');
         }
         $names = array('sf_plop_messaging_from_name', 'sf_plop_messaging_to_name');
         foreach ($names as $name) {
             sfPlopConfigPeer::addOrUpdate($name, $options['name'], $con);
         }
     }
     if (isset($options['username'])) {
         $user = sfGuardUserQuery::create()->findOneByUsername($options['username']);
         if ($user) {
             if (isset($options['email'])) {
                 $user->getProfile()->setEmail($options['email']);
             }
             $names = explode(' ', $options['name']);
             $firstName = $names[0];
             unset($names[0]);
             $lastName = implode(' ', $names);
             $user->getProfile()->setFirstName($firstName);
             $user->getProfile()->setLastName($lastName);
             $user->getProfile()->save();
         } else {
             throw new sfCommandException('There is no user whith username "' . $options['username'] . '".');
         }
     }
 }
 /**
  * @see sfValidatorString
  */
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     if (!preg_match($this->getOption('pattern'), $clean)) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     return $clean;
 }
 /**
  * Checks that this is a valid class.
  */
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     $match = BarbaraClassTable::getInstance()->findOneByTitle($clean);
     if (!$match) {
         throw new sfValidatorError($this, 'class', array('value' => $value));
     }
     return $clean;
 }
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     $value = str_replace(array('-', '/', '\\', '_'), '', $value);
     if (!CuitVerifier::verify($value)) {
         throw new sfValidatorError($this, 'invalid');
     }
     return $value;
 }
 /**
  * @see sfValidatorString
  */
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     $pattern = $this->getPattern();
     if ($this->getOption('must_match') && !preg_match($pattern, $clean) || !$this->getOption('must_match') && preg_match($pattern, $clean)) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     return $clean;
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     $first = strtolower(trim(substr($clean, 0, strpos($clean, ' '))));
     if (!in_array($first, $this->getOption('words'))) {
         throw new sfValidatorError($this, 'not_a_question', array('first' => $first));
     }
     return $clean;
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = strtolower(trim($value));
     if (!Utils::validPermalink($clean)) {
         //any error code is satisfactory
         throw new sfValidatorError($this, 'invalid', array());
     }
     return parent::doClean($clean);
 }
 protected function doClean($value)
 {
     $clean = $value;
     if ($this->getOption('required') && (!$value['postcode'] || !$value['city'] || !$value['address'])) {
         throw new sfValidatorError($this, 'A teljes cím megadása kötelező', array('value' => $value));
     }
     $clean = $value['postcode'] . '|' . $value['city'] . '|' . $value['address'];
     parent::doClean($clean);
     return $clean;
 }
 function doClean($value)
 {
     $value = parent::doClean($value);
     foreach (explode('.', $value) as $num) {
         if (!is_numeric($num)) {
             throw new sfValidatorError($this, 'invalid', array('version' => $value));
         }
     }
     return $value;
 }
Exemple #20
0
 /**
  * @see sfValidatorUrl
  */
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     try {
         $array = sfYaml::load($value);
     } catch (InvalidArgumentException $e) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     return $value;
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = (string) $value;
     $clean = strtoupper($clean);
     if (!AdmorphousUtils::$usStates[$clean]) {
         //any error code is satisfactory
         throw new sfValidatorError($this, 'min_length', array());
     }
     return parent::doClean($value);
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = (string) $value;
     $clean = Utils::safeSimpleStr($clean);
     $clean = strtolower($clean);
     parent::doClean($clean);
     if (!Utils::validUsername($clean)) {
         throw new sfValidatorError($this, 'invalid', array('value' => $clean));
     }
     return $clean;
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = (string) $value;
     if ($this->getOption('strip')) {
         $clean = aHtml::simplify($clean, $this->getOptionOrFalse('allowed_tags'), $this->getOptionOrFalse('complete'), $this->getOptionOrFalse('allowed_attributes'), $this->getOptionOrFalse('allowed_styles'));
     } else {
         throw new sfException('That should not happen strip is set in configure in sfValidatorHtml');
     }
     $clean = parent::doClean($clean);
     return $clean;
 }
 /**
  * @see sfValidatorString
  */
 protected function doClean($value)
 {
     $clean = parent::doClean($value);
     if ($this->getOption('full_required') && !preg_match('/^(0[1-9]|[12]\\d|3[01])([04][1-9]|[15][0-2])\\d{7}$/', $clean)) {
         throw new sfValidatorError($this, 'invalid', array('value' => $value));
     }
     if (!$this->getOption('full_required') && !preg_match('/^(0[1-9]|[12]\\d|3[01])([04][1-9]|[15][0-2])\\d{2}(\\d{5})?$/', $clean)) {
         throw new sfValidatorError($this, 'invalid2', array('value' => $value));
     }
     return $clean;
 }
 public static function ValidateSearchRequest($request, $check_dates = false)
 {
     $date_from = $request->getParameter('date_from');
     $date_to = $request->getParameter('date_to');
     $city_name = $request->getParameter('city');
     $features = $request->getParameter('features');
     $errors = array();
     //  City______________
     $city = Doctrine_Core::getTable('City')->FindByNameLike($city_name);
     if (is_object($city) === false) {
         $error = 'City ' . $request->getParameter('city') . ' not found ... ';
         array_push($errors, $error);
     }
     $city_validator = new sfValidatorString(array('required' => true), array('required' => 'Please enter City to search'));
     try {
         $city_name = $city_validator->clean($city_name);
     } catch (sfValidatorError $e) {
         array_push($errors, $e);
     }
     //  Dates______________
     if ($check_dates) {
         if (strlen($date_from) > 1 === false) {
             array_push($errors, "Please enter date from.");
         }
         if (strlen($date_to) > 1 === false) {
             array_push($errors, "Please enter date to.");
         }
         if (strtotime($date_from) >= strtotime($date_to)) {
             array_push($errors, "Bad date range.");
         }
         if (LinkParser::CheckDate($date_from, '-', true) === false) {
             array_push($errors, "Invalid format for date from.");
         }
         if (LinkParser::CheckDate($date_to, '-', true) === false) {
             array_push($errors, "Invalid format for date to.");
         }
     }
     return $errors;
 }
 protected function doClean($value)
 {
     $validatedString = parent::doClean($value);
     if ($this->hasOption('id')) {
         $specified_pass = ModeratorManagement::asMd5WithPrefix($validatedString);
         $former_pass = ModeratorManagement::getPasswordAsMd5($this->getOption('id'));
         if ($specified_pass != $former_pass) {
             throw new sfValidatorError($this, 'You have specified an invalid former password.');
         }
     } else {
         throw new sfValidatorError($this, 'id');
     }
 }
Exemple #27
0
 /**
  * @see sfValidatorString
  */
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     if (!class_exists($value)) {
         throw new sfValidatorError($this, 'notfound', array('value' => $value));
     }
     if ($this->hasOption('implements') && $value != $this->getOption('implements')) {
         $class = new ReflectionClass($value);
         if (!$class->isSubclassOf($this->getOption('implements'))) {
             throw new sfValidatorError($this, 'notimplement', array('value' => $value, 'implements' => $this->getOption('implements')));
         }
     }
     return $value;
 }
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     $missing = array();
     foreach ((array) $this->getOption('keywords') as $keyword) {
         if (strpos($value, $keyword) === false) {
             $missing[] = $keyword;
         }
     }
     if ($missing) {
         throw new sfValidatorError($this, 'missing', array('keywords' => implode(', ', $missing)));
     }
     return $value;
 }
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     if (!preg_match('/[0-9]/', $value)) {
         throw new sfValidatorError($this, 'number');
     }
     if (!preg_match('/[a-z]/', $value)) {
         throw new sfValidatorError($this, 'lower');
     }
     if (!preg_match('/[A-Z]/', $value)) {
         throw new sfValidatorError($this, 'upper');
     }
     return $value;
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $clean = (string) parent::doClean($value);
     $clean = aTools::strtolower($clean);
     $slugified = aTools::slugify($clean, $this->getOption('allow_slashes'));
     if ($this->getOption('strict')) {
         if ($slugified !== $clean) {
             throw new sfValidatorError($this, 'invalid', array('value' => $value));
         }
     } else {
         $clean = $slugified;
     }
     return $clean;
 }