Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29d8c68

Browse files
committed
[Mime] Add DataPart::setContentId()
1 parent 6c8c93d commit 29d8c68

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Symfony/Component/Mime/Part/DataPart.php

+14
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public function asInline(): static
8989
return $this->setDisposition('inline');
9090
}
9191

92+
/**
93+
* @return $this
94+
*/
95+
public function setContentId(string $cid): static
96+
{
97+
if (!str_contains($cid, '@')) {
98+
throw new InvalidArgumentException(sprintf('Invalid cid "%s".', $cid));
99+
}
100+
101+
$this->cid = $cid;
102+
103+
return $this;
104+
}
105+
92106
public function getContentId(): string
93107
{
94108
return $this->cid ?: $this->cid = $this->generateContentId();

src/Symfony/Component/Mime/Tests/Part/DataPartTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ public function testHasContentId()
166166
$this->assertTrue($p->hasContentId());
167167
}
168168

169+
public function testSetContentId()
170+
{
171+
$p = new DataPart('content');
172+
$p->setContentId('test@test');
173+
$this->assertTrue($p->hasContentId());
174+
$this->assertSame('test@test', $p->getContentId());
175+
}
176+
177+
public function testSetContentIdInvalid()
178+
{
179+
$this->expectException(InvalidArgumentException::class);
180+
181+
$p = new DataPart('content');
182+
$p->setContentId('test');
183+
}
184+
169185
public function testGetFilename()
170186
{
171187
$p = new DataPart('content', null);

0 commit comments

Comments
 (0)