data = [ 'email' => uniqid() . '@example.com', 'status' => 'subscribed' ]; $this->segments = []; } /** * @param string $first_name * @return $this */ public function withFirstName($first_name) { $this->data['first_name'] = $first_name; return $this; } /** * @param string $last_name * @return $this */ public function withLastName($last_name) { $this->data['last_name'] = $last_name; return $this; } /** * @param string $email * @return $this */ public function withEmail($email) { $this->data['email'] = $email; return $this; } /** * @param \MailPoet\Models\Segment[] $segments * @return $this */ public function withSegments(array $segments) { $this->segments = array_merge($this->segments, $segments); return $this; } /** * @return \MailPoet\Models\Subscriber * @throws \Exception */ public function create() { $subscriber = \MailPoet\Models\Subscriber::createOrUpdate($this->data); foreach($this->segments as $segment) { SubscriberSegment::createOrUpdate([ 'subscriber_id' => $subscriber->id(), 'segment_id' => $segment->id(), ]); } return $subscriber; } }