Пример #1
0
 /**
  * @param string $idsStr Eg: '1, 3,  5, 10'
  *
  * @return IdSet
  *
  * @throws InvalidArgumentException
  */
 public static function fromString($idsStr)
 {
     if (!Validator::isOptionalString($idsStr)) {
         throw InvalidArgumentException::notString('ids', $idsStr);
     }
     $idsStr = preg_replace('/\\s+/', '', $idsStr);
     $idsArr = $idsStr == '' ? array() : explode(IdSet::DELIMITER, $idsStr);
     return static::fromArray($idsArr);
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function isOptionalString($value, $suppressException = true)
 {
     /* Clear the last error. */
     $this->lastError = null;
     /* If valid just return true. */
     if (Validator::isOptionalString($value)) {
         return true;
     }
     /* Set the error message. */
     $this->lastError = sprintf('Expected null or string, \'%s\' given.', gettype($value));
     return $this->validationFailed($suppressException);
 }