Example #1
0
 /**
  * Creates MbString instance
  *
  * @param mixed $value The string value
  *
  * @return MbString
  *
  * @throws DomainException When the value is not valid
  */
 function mbString($value) : MbString
 {
     if (!Validate::isStringCastable($value)) {
         $message = sprintf('Invalid string value: %s', VarPrinter::toString($value));
         throw new DomainException($message);
     }
     if ($value instanceof MbString) {
         return $value;
     }
     /** @var MbString $string */
     $string = MbString::create((string) $value);
     return $string;
 }
Example #2
0
 /**
  * Converts a value from its database representation to its PHP representation
  *
  * @param mixed            $value    The value to convert
  * @param AbstractPlatform $platform The currently used database platform
  *
  * @return mixed
  *
  * @throws ConversionException When the conversion fails
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof MbString) {
         return $value;
     }
     try {
         $mbString = MbString::create($value);
     } catch (Exception $exception) {
         throw ConversionException::conversionFailed($value, static::TYPE_NAME);
     }
     return $mbString;
 }
Example #3
0
 /**
  * @expectedException \AssertionError
  */
 public function test_that_compare_to_throws_exception_for_invalid_argument()
 {
     $string = MbString::create('hello');
     $string->compareTo('hello');
 }