示例#1
0
 /**
  * Checks if $value is an absolute URL.
  *
  * @param mixed $value
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_setValue($value);
     if (!is_string($value)) {
         $this->_error(self::FAILURE_INVALID, Mol_Util_Stringifier::stringify($value));
         return false;
     }
     if (!$this->isUrl($value)) {
         $this->_error(self::FAILURE_NO_URL);
         return false;
     }
     if (!$this->hasAllowedHostname($value)) {
         $this->_error(self::FAILURE_HOSTNAME_NOT_ALLOWED);
         return false;
     }
     return true;
 }
 /**
  * Creates the relation validator that belongs to the provided identifier.
  *
  * @param string $identifier
  * @return Zend_Validate_Interface
  * @throws InvalidArgumentException If an invalid identifier is provided.
  */
 protected function createRelationByIdentifier($identifier)
 {
     switch ($identifier) {
         case '==':
             return new Mol_Validate_Form_Relation_Equal();
         case '!=':
             return new Mol_Validate_Form_Relation_NotEqual();
         case '>':
             return new Mol_Validate_Form_Relation_GreaterThan();
         case '>=':
             return new Mol_Validate_Form_Relation_GreaterThanOrEqual();
         case '<':
             return new Mol_Validate_Form_Relation_LessThan();
         case '<=':
             return new Mol_Validate_Form_Relation_LessThanOrEqual();
     }
     $message = Mol_Util_Stringifier::stringify($identifier) . ' is not a valid relation identifier.';
     throw new InvalidArgumentException($message);
 }
 /**
  * Ensures that stringifyException() indents the second inner exception
  * correctly. Indention is indicated via ">>".
  */
 public function testStringifyExceptionIndentsSecondInnerException()
 {
     $secondLevelException = new BadMethodCallException('2nd level', 7);
     $firstLevelException = new RuntimeException('1st level', 0, $secondLevelException);
     $exception = new RuntimeException('An error occurred!', 42, $firstLevelException);
     $representation = Mol_Util_Stringifier::stringifyException($exception);
     $this->assertInternalType('string', $representation);
     $this->assertContains('>> ', $representation);
 }
示例#4
0
 /**
  * Converts the provided data to a string value.
  *
  * If a string object is provided then the charset will
  * be automatically converted if necessary.
  *
  * @param string|Mol_DataType_String|mixed $data
  * @return string The simple string value.
  * @throws InvalidArgumentException If the method cannot convert the data into a string.
  */
 protected function toValue($data)
 {
     if (is_string($data)) {
         return $data;
     }
     if ($data instanceof self) {
         return $data->convertTo($this->charset)->toString();
     }
     $received = Mol_Util_Stringifier::stringify($data);
     $message = 'Expected string or instance of ' . __CLASS__ . ', but ' . $received . ' provided.';
     throw new InvalidArgumentException($message);
 }
 /**
  * Asserts that the given value is a string.
  *
  * @param mixed $value
  * @throws InvalidArgumentException If $value is not a string.
  */
 protected function assertString($value)
 {
     if (is_string($value)) {
         return;
     }
     $format = 'String expected, but received: %s';
     $message = sprintf($format, Mol_Util_Stringifier::stringify($value));
     throw new InvalidArgumentException($message);
 }