Skip to content

Commit

Permalink
Default subject based on mail class
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary committed Mar 2, 2023
1 parent 2f3e81a commit ac89359
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Generators/Statements/MailGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected function populateStub(string $stub, SendStatement $sendStatement)
{
$stub = str_replace('{{ namespace }}', config('blueprint.namespace') . '\\Mail', $stub);
$stub = str_replace('{{ class }}', $sendStatement->mail(), $stub);
$stub = str_replace('{{ subject }}', $sendStatement->subject(), $stub);
$stub = str_replace('{{ view }}', $sendStatement->view(), $stub);
$stub = str_replace('{{ properties }}', $this->populateConstructor('message', $sendStatement), $stub);

Expand Down
11 changes: 11 additions & 0 deletions src/Models/Statements/SendStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,24 @@ class SendStatement
*/
private $view;

/**
* @var string
*/
private $subject;

public function __construct(string $mail, ?string $to, array $data, string $type, string $view = null)
{
$this->mail = $mail;
$this->data = $data;
$this->to = $to;
$this->type = $type;
$this->view = $view ?? 'emails.' . Str::kebab($this->mail);
$this->subject = $type === self::TYPE_MAIL ? Str::headline($this->mail) : '';
}

public function subject(): string
{
return $this->subject;
}

public function mail()
Expand Down
2 changes: 1 addition & 1 deletion stubs/mail.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class {{ class }} extends Mailable
public function envelope(): Envelope
{
return new Envelope(
subject: '',
subject: '{{ subject }}',
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mailables/added-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct($user)
public function envelope(): Envelope
{
return new Envelope(
subject: '',
subject: 'Added Admin',
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mailables/mail-configured.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct($post)
public function envelope(): Envelope
{
return new Envelope(
subject: '',
subject: 'Review Post',
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mailables/published-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
public function envelope(): Envelope
{
return new Envelope(
subject: '',
subject: 'Published Post',
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mailables/return-type-declarations.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct($post)
public function envelope(): Envelope
{
return new Envelope(
subject: '',
subject: 'Review Post',
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mailables/review-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct($post)
public function envelope(): Envelope
{
return new Envelope(
subject: '',
subject: 'Review Post',
);
}

Expand Down

0 comments on commit ac89359

Please sign in to comment.