Ejemplo n.º 1
0
 /**
  * Add Server
  *
  * @param string $host
  * @param int $port
  * @return MemcachedOptions
  * @throws Exception\InvalidArgumentException
  */
 public function addServer($host, $port = 11211)
 {
     $hostNameValidator = new Hostname(array('allow' => Hostname::ALLOW_ALL));
     if (!$hostNameValidator->isValid($host)) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects a valid hostname: %s', __METHOD__, implode("\n", $hostNameValidator->getMessages())));
     }
     if (!is_numeric($port) || $port <= 0) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects a positive integer', __METHOD__));
     }
     $this->servers[] = array($host, $port);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Ensure that a trailing "." in a local hostname is permitted
  *
  * @group ZF-6363
  */
 public function testTrailingDot()
 {
     $valuesExpected = array(array(Hostname::ALLOW_ALL, true, array('example.', 'example.com.', '~ex%20ample.')), array(Hostname::ALLOW_ALL, false, array('example..')), array(Hostname::ALLOW_ALL, true, array('1.2.3.4.')), array(Hostname::ALLOW_DNS, false, array('example..', '~ex%20ample..')), array(Hostname::ALLOW_LOCAL, true, array('example.', 'example.com.')));
     foreach ($valuesExpected as $element) {
         $validator = new Hostname($element[0]);
         foreach ($element[2] as $input) {
             $this->assertEquals($element[1], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Set session.cookie_domain
  * 
  * @param  string $cookieDomain 
  * @return StandardConfiguration
  * @throws SessionException
  */
 public function setCookieDomain($cookieDomain)
 {
     if (!is_string($cookieDomain)) {
         throw new Exception\InvalidArgumentException('Invalid cookie domain: must be a string');
     }
     $validator = new HostnameValidator(HostnameValidator::ALLOW_ALL);
     if (!empty($cookieDomain) && !$validator->isValid($cookieDomain)) {
         throw new Exception\InvalidArgumentException('Invalid cookie domain: ' . implode('; ', $validator->getMessages()));
     }
     $this->_cookieDomain = $cookieDomain;
     $this->setStorageOption('cookie_domain', $cookieDomain);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * @see ZF-7277
  */
 public function testDifferentIconvEncoding()
 {
     iconv_set_encoding('internal_encoding', 'ISO8859-1');
     $validator = new Hostname();
     $valuesExpected = array(array(true, array('bürger.com', 'hãllo.com', 'hållo.com')), array(true, array('bÜrger.com', 'hÃllo.com', 'hÅllo.com')), array(false, array('hãllo.lt', 'bürger.lt', 'hãllo.lt')));
     foreach ($valuesExpected as $element) {
         foreach ($element[1] as $input) {
             $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @group ZF-10267
  */
 public function testURI()
 {
     $valuesExpected = array(array(Hostname::ALLOW_URI, true, array('localhost', 'example.com', '~ex%20ample')), array(Hostname::ALLOW_URI, false, array('§bad', 'don?t.know', 'thisisaverylonghostnamewhichextendstwohundredfiftysixcharactersandthereforshouldnotbeallowedbythisvalidatorbecauserfc3986limitstheallowedcharacterstoalimitoftwohunderedfiftysixcharactersinsumbutifthistestwouldfailthenitshouldreturntruewhichthrowsanexceptionbytheunittest')));
     foreach ($valuesExpected as $element) {
         $validator = new Hostname($element[0]);
         foreach ($element[2] as $input) {
             $this->assertEquals($element[1], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input);
         }
     }
 }
Ejemplo n.º 6
0
 public function testAdditionalUTF8TLDs()
 {
     $validator = new Hostname(Hostname::ALLOW_ALL);
     // Check UTF-8 TLD matching
     $valuesExpected = array(array(true, array('test123.δοκιμή', 'тест.рф', 'туршилтын.мон')), array(false, array('சோதனை3.இலங்கை', 'رات.мон')));
     foreach ($valuesExpected as $element) {
         foreach ($element[1] as $input) {
             $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . ' - ' . $input);
         }
     }
 }