Example #1
0
 /**
  * Handles construction from a serialized representation
  *
  * @param string $serialized The serialized representation
  *
  * @return void
  */
 public function unserialize($serialized)
 {
     $data = unserialize($serialized);
     $this->aggregateId = $data['aggregate_id'];
     $this->aggregateType = $data['aggregate_type'];
     $this->committedSequence = $data['committed_sequence'];
     $this->lastSequence = $data['last_sequence'];
     $this->messages = ArrayList::of(EventMessage::class);
     foreach ($data['messages'] as $message) {
         $this->messages->add($message);
     }
 }
Example #2
0
 public function test_that_each_calls_callback_with_each_item()
 {
     $set = SortedSet::string();
     $set->add('foo');
     $set->add('bar');
     $set->add('baz');
     $output = ArrayList::of('string');
     $set->each(function ($item) use($output) {
         $output->add($item);
     });
     $this->assertCount(3, $output->toArray());
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function chunk(int $size = 1) : IndexedList
 {
     if ($size < 1) {
         $message = sprintf('Invalid chunk size: %d', $size);
         throw new DomainException($message);
     }
     $parts = str_split($this->value, $size);
     $list = ArrayList::of(static::class);
     foreach ($parts as $part) {
         $list->add(static::create($part));
     }
     return $list;
 }
Example #4
0
 /**
  * @expectedException \Novuso\System\Exception\UnderflowException
  */
 public function test_that_last_throws_exception_when_empty()
 {
     $list = ArrayList::of('string');
     $list->last();
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function chunk(int $size = 1) : IndexedList
 {
     $value = $this->value();
     if ($size < 1) {
         $message = sprintf('Invalid chunk size: %d', $size);
         throw new DomainException($message);
     }
     $list = ArrayList::of(static::class);
     if ($this->length <= $size) {
         $list->add(static::create($value));
     } else {
         while ($value !== '') {
             $list->add(static::create(mb_substr($value, 0, $size, static::ENCODING)));
             $value = mb_substr($value, $size, mb_strlen($value, static::ENCODING) - $size, static::ENCODING);
         }
     }
     return $list;
 }