Example #1
0
 public static function reconstitute(EventStream $events) : AggregateRoot
 {
     $instance = new self($events->aggregateId());
     foreach ($events as $event) {
         $instance->apply($event);
     }
     return $instance;
 }
 public static function fromEvents(array $events)
 {
     $productReturn = new self();
     array_walk($events, function ($event) use($productReturn) {
         $productReturn->apply($event);
     });
     $productReturn->events = $events;
     return $productReturn;
 }
Example #3
0
 /**
  * Creates a new poll
  *
  * @param PollId $id
  * @param string $poll_title
  * @return Poll
  * @throws InvalidPollTitle
  */
 public static function create(PollId $id, $poll_title)
 {
     $validator = new PollTitleValidator();
     if (!$validator->isSatisfiedBy($poll_title)) {
         throw new InvalidPollTitle($poll_title);
     }
     $poll = new self();
     $poll->apply(new PollCreatedEvent($id, $poll_title));
     return $poll;
 }
Example #4
0
 /**
  * Create a new Multiline object from a string.
  *
  * First the input string is split into lines by the detected end-of-line
  * character. Afterwards any extra EOL chars will be trimmed.
  *
  * @see \nochso\Omni\EOL
  *
  * @param string $input      A string to split into a Multiline object
  * @param string $defaultEol Default end-of-line type to split the input by. This is a fallback in case it could
  *                           not be detected from the input string. Optional, defaults to `EOL::EOL_LF` i.e. "\n".
  *                           See the `EOL::EOL_*` class constants.
  *
  * @return \nochso\Omni\Multiline
  */
 public static function create($input, $defaultEol = \nochso\Omni\EOL::EOL_LF)
 {
     $eol = EOL::detectDefault($input, $defaultEol);
     $lines = explode($eol, $input);
     $multiline = new self($lines);
     // Remove left-over line feeds
     $multiline->apply(function ($line) {
         return trim($line, "\r\n");
     });
     $multiline->setEol($eol);
     return $multiline;
 }
Example #5
0
 /**
  * Запустить типограф со стандартными параметрами
  *
  * @param string $text
  * @param array $options
  * @return string
  */
 public static function fast_apply($text, $options = null)
 {
     $obj = new self();
     if (is_array($options)) {
         $obj->setup($options);
     }
     $obj->set_text($text);
     return $obj->apply();
 }