Example #1
0
 public static function create()
 {
     $id = DocumentId::generate();
     $document = new self($id);
     $document->recordThat(new DocumentCreated($id));
     return $document;
 }
Example #2
0
 public static function write(PostId $id, PostContent $content, $author = '')
 {
     $post = new self();
     $post->id = $id;
     $post->recordThat(new Events\NewPostWasWritten($id->getId(), $content->getTitle(), $content->getBody(), $author));
     return $post;
 }
Example #3
0
 /**
  * @param UserId $userId
  * @param string $name
  * @param EmailAddress $emailAddress
  * @return User
  */
 public static function registerWithData(UserId $userId, $name, EmailAddress $emailAddress)
 {
     $self = new self();
     $self->assertName($name);
     $self->recordThat(UserWasRegistered::withData($userId, $name, $emailAddress));
     return $self;
 }
 public static function nameNew($name)
 {
     $id = Uuid::uuid4()->toString();
     $instance = new self();
     $instance->recordThat(UserCreated::occur($id, ['id' => $id, 'name' => $name]));
     return $instance;
 }
Example #5
0
 /**
  * @param string $text
  * @param UserId $assigneeId
  * @param TodoId $todoId
  * @return Todo
  */
 public static function post($text, UserId $assigneeId, TodoId $todoId)
 {
     $self = new self();
     $self->assertText($text);
     $self->recordThat(TodoWasPosted::byUser($assigneeId, $text, $todoId, TodoStatus::open()));
     return $self;
 }
Example #6
0
 public static function register($name)
 {
     $id = PersonId::generate();
     $person = new self($id, $name);
     $person->recordThat(new PersonRegistered($id, $name));
     return $person;
 }
Example #7
0
 public static function create($description)
 {
     $id = TaskId::generate();
     $task = new self($id, $description);
     $task->recordThat(new TaskCreatedEvent($id, $description));
     return $task;
 }
Example #8
0
 public static function create($name)
 {
     $id = MenuId::generate();
     $name = MenuName::fromString($name);
     $menu = new self($id);
     $menu->recordThat(new MenuCreated($id, $name));
     return $menu;
 }
 /**
  * @param SqliteDbFile $sqliteDbFile
  * @param ConfigLocation $configLocation
  * @param ConfigWriter $configWriter
  * @return EventStoreConfig
  */
 public static function initializeWithSqliteDb(SqliteDbFile $sqliteDbFile, ConfigLocation $configLocation, ConfigWriter $configWriter)
 {
     $config = ['proophessor' => ['event_store' => ['adapter' => ['type' => 'Prooph\\EventStore\\Adapter\\Doctrine\\DoctrineEventStoreAdapter', 'options' => ['connection' => ['driver' => 'pdo_sqlite', 'path' => $sqliteDbFile->toString()], 'serializer_adapter' => 'json']]]]];
     $instance = new self($config, $configLocation);
     $configWriter->writeNewConfigToDirectory($config, $configLocation->toString() . DIRECTORY_SEPARATOR . $instance->configFileName());
     $instance->recordThat(EventStoreWasInitialized::withSqliteDb($sqliteDbFile, $configLocation, $instance->configFileName()));
     return $instance;
 }
Example #10
0
 /**
  * ARs should be created via static factory methods
  *
  * @param string $username
  * @return User
  */
 public static function nameNew($username)
 {
     //Perform assertions before raising a event
     \Assert\that($username)->notEmpty()->string();
     $uuid = Uuid::uuid4();
     //AggregateRoot::__construct is defined as protected so it can be called in a static factory of
     //an extending class
     $instance = new self();
     //Use AggregateRoot::recordThat method to apply a new Event
     $instance->recordThat(UserWasCreated::occur($uuid->toString(), ['name' => $username]));
     return $instance;
 }
Example #11
0
 /**
  * Uses Prooph\Processing\Environment to initialize with its defaults
  */
 public static function initializeWithDefaultsIn(ConfigLocation $configLocation, ConfigWriter $configWriter)
 {
     $env = Environment::setUp();
     $instance = new self(['processing' => array_merge($env->getConfig()->toArray(), ["connectors" => [], "js_ticker" => ['enabled' => false, 'interval' => 3]])], $configLocation);
     $configFilePath = $configLocation->toString() . DIRECTORY_SEPARATOR . self::$configFileName;
     if (file_exists($configFilePath)) {
         throw new \RuntimeException("Processing config already exists: " . $configFilePath);
     }
     $configWriter->writeNewConfigToDirectory($instance->toArray(), $configFilePath);
     $instance->recordThat(ProcessingConfigFileWasCreated::in($configLocation, self::$configFileName));
     return $instance;
 }
Example #12
0
 /**
  * @param StoryName $storyName
  * @param Message $startMessage
  * @param ChapterTemplate[] $chapterTemplates
  * @param MessageConverter $messageConverter
  * @throws Exception\Story
  * @return Story
  */
 public static function start(StoryName $storyName, Message $startMessage, array $chapterTemplates, MessageConverter $messageConverter)
 {
     self::assertChapterTemplates($chapterTemplates, $storyName);
     $storyId = StoryId::fromString($startMessage->uuid()->toString());
     $self = new self();
     $self->recordThat(StoryWasStarted::withStoryIdAndName($storyId, $storyName));
     $nextCommands = $self->startNextChapters($storyName, $startMessage, $chapterTemplates, $storyId, $messageConverter);
     if (empty($nextCommands)) {
         throw Exception\Story::cannotBeStartedForMessage($startMessage);
     }
     $self->nextCommands = $nextCommands;
     return $self;
 }
Example #13
0
 /**
  * @param MessageHandler $messageHandler
  * @param TaskType $taskType
  * @param Prototype $processingType
  * @param ProcessingMetadata $metadata
  * @return Task
  */
 public static function setUp(MessageHandler $messageHandler, TaskType $taskType, Prototype $processingType, ProcessingMetadata $metadata)
 {
     $instance = new self();
     $instance->recordThat(TaskWasSetUp::with(TaskId::generate(), $taskType, $messageHandler, $processingType, $metadata));
     return $instance;
 }
Example #14
0
 /**
  * @param NodeName $nodeName
  * @param WorkflowId $workflowId
  * @param string $workflowName
  * @return Workflow
  */
 public static function locatedOn(NodeName $nodeName, WorkflowId $workflowId, $workflowName)
 {
     Assertion::string($workflowName);
     Assertion::notEmpty($workflowName);
     $instance = new self();
     $instance->recordThat(WorkflowWasCreated::on($nodeName, $workflowId, $workflowName));
     return $instance;
 }
Example #15
0
 /**
  * @param string $name
  * @param string $email
  * @return User
  */
 public static function create($name, $email)
 {
     $self = new self();
     $self->recordThat(UserCreated::with(['user_id' => Uuid::uuid4()->toString(), 'name' => $name, 'email' => $email], $self->nextVersion()));
     return $self;
 }
 /**
  * @param MessageHandlerId $id
  * @param string $name
  * @param NodeName $nodeName
  * @param MessageHandler\HandlerType $handlerType
  * @param MessageHandler\DataDirection $dataDirection
  * @param MessageHandler\ProcessingTypes $supportedProcessingTypes
  * @param ProcessingMetadata $metadata
  * @param string $metadataRiotTag
  * @param string $icon
  * @param string $iconType
  * @param null|Prototype $preferredProcessingType
  * @param null|MessageHandler\ProcessingId $processingId
  * @param array $additionalData
  * @return MessageHandler
  */
 public static function fromDefinition(MessageHandlerId $id, $name, NodeName $nodeName, HandlerType $handlerType, DataDirection $dataDirection, ProcessingTypes $supportedProcessingTypes, ProcessingMetadata $metadata, $metadataRiotTag, $icon, $iconType, Prototype $preferredProcessingType = null, ProcessingId $processingId = null, array $additionalData = [])
 {
     Assertion::string($name);
     Assertion::notEmpty($name);
     Assertion::string($metadataRiotTag);
     Assertion::notEmpty($metadataRiotTag);
     Assertion::string($icon);
     Assertion::notEmpty($icon);
     Assertion::string($iconType);
     Assertion::notEmpty($iconType);
     $instance = new self();
     $instance->recordThat(MessageHandlerWasInstalled::record($id, $name, $nodeName, $handlerType, $dataDirection, $supportedProcessingTypes, $metadata, $metadataRiotTag, $icon, $iconType, $preferredProcessingType, $processingId, $additionalData));
     return $instance;
 }
Example #17
0
 /**
  * @param string $text
  * @param string $email
  * @return Post
  */
 public static function create($text, $email)
 {
     $self = new self();
     $self->recordThat(PostCreated::with(['post_id' => Uuid::uuid4()->toString(), 'text' => $text, 'email' => $email], $self->nextVersion()));
     return $self;
 }
Example #18
0
 /**
  * @param string $title
  * @param string $content
  * @return Post
  */
 public static function create($title, $content)
 {
     $post = new self($postId = PostId::generate());
     $post->setTitle($title);
     $post->setContent($content);
     $post->setPublishingDate($publishingDate = new \DateTime());
     $post->recordThat(new PostWasPublished($postId, $title, $content, $publishingDate));
     return $post;
 }
Example #19
0
 /**
  * @param PostId $postId
  * @param string $author
  * @param string $content
  * @return Comment
  */
 public static function create(PostId $postId, $author, $content)
 {
     $comment = new self($commentId = CommentId::generate());
     $comment->setPostId($postId);
     $comment->setAuthor($author);
     $comment->setContent($content);
     $comment->setCreatingDate($creatingDate = new \DateTime());
     $comment->recordThat(new CommentWasAdded($commentId, $postId, $author, $content, $creatingDate));
     return $comment;
 }