Example #1
0
 /**
  * Constructs a new address
  * @param string $address The email address in one of the supported formats
  * @return null
  * @throws zibo\library\mail\exception\MailException when the provided address is empty or invalid
  */
 public function __construct($address)
 {
     try {
         if (String::isEmpty($address)) {
             throw new MailException('address is empty');
         }
     } catch (ZiboException $exception) {
         throw new MailException('Invalid address provided', 0, $exception);
     }
     $validator = ValidationFactory::getInstance()->createValidator('email');
     $address = trim($address);
     $address = str_replace(array("\n", "\r"), '', $address);
     $matches = array();
     if (preg_match(self::REGEX_ADDRESS, $address, $matches)) {
         $this->displayName = trim($matches[1]);
         $address = $matches[3];
     }
     if ($validator->isValid($address)) {
         $this->emailAddress = $address;
         if (empty($this->displayName) && strpos($address, '@') !== false) {
             list($this->displayName, $null) = explode('@', $address);
         }
         return;
     }
     throw new MailException('Provided address ' . $address . ' is invalid');
 }
Example #2
0
 protected function setUp()
 {
     $path = new File(__DIR__ . '/../../../../');
     $this->setUpApplication($path->getPath());
     $browser = new GenericBrowser(new File(getcwd()));
     $configIO = new IniConfigIO(Environment::getInstance(), $browser);
     Zibo::getInstance($browser, $configIO);
     $validationFactory = ValidationFactory::getInstance();
     $validationFactory->registerValidator('email', 'zibo\\library\\mail\\AddressValidator');
 }
 /**
  * Constructs a new subscribe form
  * @param string $action URL where this form will point to
  * @return null
  */
 public function __construct($action)
 {
     parent::__construct($action, self::NAME);
     $this->appendToClass('data');
     $fieldFactory = FieldFactory::getInstance();
     $emailField = $fieldFactory->createField(FieldFactory::TYPE_EMAIL, self::FIELD_EMAIL);
     $subscribeButton = $fieldFactory->createSubmitField(self::BUTTON_SUBSCRIBE, self::TRANSLATION_SUBSCRIBE);
     $this->addField($emailField);
     $this->addField($subscribeButton);
     $validatorFactory = ValidationFactory::getInstance();
     $this->addValidator(self::FIELD_EMAIL, $validatorFactory->createValidator('required'));
 }
 /**
  * Constructs a new connection form
  * @param string $formAction URL where this form will point to
  * @param string $name Name of the connection
  * @param string $dsn DSN string
  * @param string $oldName Old name of the connection
  * @return null
  */
 public function __construct($formAction, $name = null, $dsn = null, $oldName = null)
 {
     parent::__construct($formAction, self::NAME, self::TRANSLATION_SAVE);
     $fieldFactory = FieldFactory::getInstance();
     $nameField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_NAME, $name);
     $dsnField = $fieldFactory->createField(FieldFactory::TYPE_STRING, self::FIELD_DSN, $dsn);
     $oldNameField = $fieldFactory->createField(FieldFactory::TYPE_HIDDEN, self::FIELD_OLD_NAME, $oldName);
     $this->addField($nameField);
     $this->addField($dsnField);
     $this->addField($oldNameField);
     $validationFactory = ValidationFactory::getInstance();
     $nameField->addValidator($validationFactory->createValidator('required'));
     $nameField->addValidator($validationFactory->createValidator('regex', array('regex' => self::VALIDATION_NAME_REGEX, 'message' => self::TRANSLATION_VALIDATION_NAME)));
     $dsnField->addValidator($validationFactory->createValidator('dsn'));
 }
 /**
  * Load the needed validators for this model to this object
  * @param zibo\library\orm\model\meta\ModelMeta $meta the meta of the model
  * @return null
  */
 private function initializeValidators(ModelMeta $meta)
 {
     $validationFactory = ValidationFactory::getInstance();
     $fields = $meta->getFields();
     foreach ($fields as $fieldName => $field) {
         $fieldValidators = $field->getValidators();
         if (!$fieldValidators) {
             continue;
         }
         $this->validators[$fieldName] = array();
         foreach ($fieldValidators as $fieldValidator) {
             $validator = $validationFactory->createValidator($fieldValidator->getName(), $fieldValidator->getOptions());
             $this->validators[$fieldName][] = $validator;
         }
     }
 }
 /**
  * Constructs a new properties form for a AdvertisementWidget
  * @param string $action URL where this form will point to
  * @param joppa\advertising\model\data\AdvertisementBlockData $block
  * @param int $width
  * @param int $height
  * @return null
  */
 public function __construct($action, AdvertisementBlockData $block = null, $width = 0, $height = 0)
 {
     parent::__construct($action, self::NAME, self::TRANSLATION_SAVE);
     $factory = FieldFactory::getInstance();
     $id = null;
     $name = null;
     $version = null;
     if ($block) {
         $id = $block->id;
         $name = $block->name;
         $version = $block->version;
     }
     $this->addField($factory->createField(FieldFactory::TYPE_HIDDEN, self::FIELD_ID, $id));
     $this->addField($factory->createField(FieldFactory::TYPE_HIDDEN, self::FIELD_VERSION, $version));
     $this->addField($factory->createField(FieldFactory::TYPE_STRING, self::FIELD_NAME, $name));
     $this->addField($factory->createField(FieldFactory::TYPE_STRING, self::FIELD_WIDTH, $width));
     $this->addField($factory->createField(FieldFactory::TYPE_STRING, self::FIELD_HEIGHT, $height));
     $validationFactory = ValidationFactory::getInstance();
     $requiredValidator = $validationFactory->createValidator('required');
     $dimensionValidator = $validationFactory->createValidator('minmax', array('minimum' => 0, 'maximum' => 1000));
     $this->addValidator(self::FIELD_NAME, $requiredValidator);
     $this->addValidator(self::FIELD_WIDTH, $dimensionValidator);
     $this->addValidator(self::FIELD_HEIGHT, $dimensionValidator);
 }
 /**
  * Validates this form
  * @return null
  */
 public function validate()
 {
     if ($this->getRedirectType() == self::REDIRECT_TYPE_URL) {
         $validationFactory = ValidationFactory::getInstance();
         $this->addValidator(self::FIELD_URL, $validationFactory->createValidator('required'));
         $this->addValidator(self::FIELD_URL, $validationFactory->createValidator('website'));
     }
     parent::validate();
 }
 protected function tearDown()
 {
     Reflection::setProperty(ValidationFactory::getInstance(), 'instance', null);
     Reflection::setProperty(Zibo::getInstance(), 'instance', null);
 }