/**
  * Validate the emailadress
  *
  * This validate methods use the validator from zend framework.
  * This validator allows dns.
  */
 public function validate()
 {
     $result = StaticValidator::execute($this->email, 'EmailAddress', array('allow' => Hostname::ALLOW_DNS));
     if ($result === false) {
         $this->email = 'No valid email';
     }
 }
Example #2
0
 /**
  * @internal
  */
 public function onBootstrap(\Zend\EventManager\EventInterface $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     // Register form element view helpers
     $formElementHelper = $serviceManager->get('ViewHelperManager')->get('formElement');
     $formElementHelper->addClass('Library\\Form\\Element\\SelectSimple', 'FormSelectSimple');
     $formElementHelper->addType('select_untranslated', 'FormSelectUntranslated');
     \Zend\Filter\StaticFilter::setPluginManager($serviceManager->get('FilterManager'));
     \Zend\Validator\StaticValidator::setPluginManager($serviceManager->get('ValidatorManager'));
 }
Example #3
0
 /**
  * @internal
  */
 public function onRoute(\Zend\EventManager\EventInterface $e)
 {
     // Validate loglevel value. Invalid content will cause the route to fail
     // and trigger the usage message.
     $logLevel = $e->getRouteMatch()->getParam('loglevel');
     if ($logLevel != '' and !\Zend\Validator\StaticValidator::execute($logLevel, 'Library\\LogLevel')) {
         $e->setError(\Zend\Mvc\Application::ERROR_ROUTER_NO_MATCH);
         $e->setName(\Zend\Mvc\MvcEvent::EVENT_DISPATCH_ERROR);
         $e->getTarget()->getEventManager()->triggerEvent($e);
     }
 }
Example #4
0
 public function onBootstrap(EventInterface $e)
 {
     // get managers
     $eventManager = $e->getApplication()->getEventManager();
     /*
     $eventManager->attach(
     		'render', array($this, 'registerJsonStrategy'), 100
     );
     */
     $serviceManager = $e->getApplication()->getServiceManager();
     // attach module listener
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // add application listener
     /*
     if ($e->getRequest())
     {
     	$uri = $e->getRequest()->getUri();
     	if (false === strpos($uri, 'json')) {
     		$eventManager->attachAggregate(new ApplicationListener());
     	}				
     }
     */
     $eventManager->attachAggregate(new ApplicationListener());
     // get config
     $config = $serviceManager->get('config');
     // configure session
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     // get filter and validator manager
     $filterManager = $serviceManager->get('FilterManager');
     $validatorManager = $serviceManager->get('ValidatorManager');
     // add custom filters and validators
     StaticFilter::setPluginManager($filterManager);
     StaticValidator::setPluginManager($validatorManager);
 }
Example #5
0
 public function testIsValidWithParameters()
 {
     $this->assertTrue(Validator\StaticValidator::execute(5, 'Between', array(1, 10)));
     $this->assertTrue(Validator\StaticValidator::execute(5, 'Between', array('min' => 1, 'max' => 10)));
 }
Example #6
0
 /**
  * Convert localized string representations to integer, float or date values
  *
  * Subclasses can support localized input formats by calling this method
  * from a filter.
  *
  * Non-string values get trimmed and converted to integer, float or
  * \DateTime, depending on $type. Invalid values are returned as string. The
  * input filter should validate filtered data by checking the datatype via
  * validateType().
  *
  * @param string $value Localized input string
  * @param string $type Data type (integer, float, date). Any other value will be ignored.
  * @return mixed Normalized value or input string
  */
 public function normalize($value, $type)
 {
     // Integers and floats are validated first to prevent successful parsing
     // of strings containing invalid characters with the invalid part simply
     // cut off.
     switch ($type) {
         case 'integer':
             $value = trim($value);
             if (\Zend\Validator\StaticValidator::execute($value, 'Zend\\I18n\\Validator\\IsInt')) {
                 $value = \Zend\Filter\StaticFilter::execute($value, 'Zend\\I18n\\Filter\\NumberParse', array('type' => \NumberFormatter::TYPE_INT32));
             }
             break;
         case 'float':
             $value = trim($value);
             if (\Zend\Validator\StaticValidator::execute($value, 'Zend\\I18n\\Validator\\IsFloat')) {
                 $value = \Zend\Filter\StaticFilter::execute($value, 'Zend\\I18n\\Filter\\NumberParse', array('type' => \NumberFormatter::TYPE_DOUBLE));
             }
             break;
         case 'date':
             $value = trim($value);
             $validator = new \Zend\I18n\Validator\DateTime();
             $validator->setDateType(\IntlDateFormatter::SHORT);
             if ($validator->isValid($value)) {
                 // Some systems accept invalid date separators, like '/'
                 // with a de_DE locale which should accept only '.'.
                 // An extra comparision of the locale-specific pattern and
                 // the input string is necessary.
                 // This also enforces 4-digit years to avoid any confusion
                 // with 2-digit year input.
                 $pattern = preg_quote($validator->getPattern(), '#');
                 // Get the year part out of the way first.
                 $pattern = preg_replace('/y+/', '§', $pattern);
                 // Remaining letters are placeholders for digits.
                 $pattern = preg_replace('/[a-zA-Z]+/', '\\d+', $pattern);
                 // Set the year pattern.
                 $pattern = str_replace('§', '\\d{4}', $pattern);
                 if (preg_match("#^{$pattern}\$#", $value)) {
                     $formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, 'UTC');
                     $value = \DateTime::createFromFormat('U', $formatter->parse($value));
                 }
             }
             break;
     }
     return $value;
 }
Example #7
0
 /**
  * Check if the value for a namespace configuration key is true or false
  *
  * @param $paramKey
  * @param $paramValue
  *
  * @return bool
  *
  * @todo Regex needs to be refactored to match namespaces better
  */
 protected function checkValueForNamespaceKey($paramKey, $paramValue)
 {
     if (substr($paramKey, 0, 9) != 'namespace') {
         return true;
     }
     $isValid = StaticValidator::execute($paramValue, 'Regex', ['pattern' => '=^[A-Z]{1}[a-zA-Z0-9\\\\]*$=']);
     if ($isValid) {
         return true;
     }
     $this->console->writeFailLine('task_tool_configuration_allowed_namespace_config_keys', [$this->console->colorize($paramKey, Color::GREEN)]);
     return false;
 }