示例#1
0
 /**
  * You should override this if you want a custom exception or if you want to have a ZeroId.
  *
  * @param int $id
  *
  * @throws InvalidArgumentException
  */
 protected function setId($id)
 {
     if (!Validator::isRequiredPositiveInteger($id)) {
         throw InvalidArgumentException::notPositiveInteger('id', $id);
     }
     $this->id = $id;
 }
示例#2
0
 /**
  * This method is final on purpose isn't supposed to be override, instead add a add()
  *
  * @param Id $id
  *
  * @throws InvalidArgumentException
  */
 protected final function addInternal(Id $id)
 {
     $exists = method_exists($this, 'exists') ? $this->exists($id) : $this->existsInternal($id);
     if ($exists) {
         throw InvalidArgumentException::alreadyExists('ids', $id);
     }
     $this->items[$id->get()] = $id;
 }
 /**
  * @param IdSet $approved
  * @param IdSet $rejected
  *
  * @throws InvalidArgumentException
  */
 public function __construct(IdSet $approved, IdSet $rejected)
 {
     if ($approved->intersects($rejected)) {
         throw InvalidArgumentException::approvedRejectedCommonElements($approved->toArray(), $rejected->toArray());
     }
     $this->approved = $approved;
     $this->rejected = $rejected;
 }
示例#4
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);
 }