maintenant sa march

This commit is contained in:
Maxime Renou 2020-06-09 18:34:22 +02:00
parent 2ff5b2012d
commit 9559436543
2 changed files with 30 additions and 13 deletions

View File

@ -54,27 +54,37 @@ class BluescaleMailApi
$multipart_form = []; $multipart_form = [];
foreach ($template as $key => $value) { // Formatting whole template to pass in 'multipart' form foreach ($template as $key => $value)
{
if ($key == 'attachments')
{
foreach ($value as $i => $attachment) {
$multipart_form[] = [
'name' => "{$key}[$i]",
'contents' => file_get_contents($attachment['path']),
'filename' => $attachment['filename']
];
}
continue;
}
if (!is_array($value)) { if (!is_array($value)) {
$multipart_form[] = ['name' => $key, 'contents' => $value]; $multipart_form[] = ['name' => $key, 'contents' => $value];
continue; continue;
} }
foreach ($value as $multiKey => $multiValue) { foreach ($value as $subkey => $subvalue)
$multiName = $key . '[' .$multiKey . ']' . (is_array($multiValue) ? '[' . key($multiValue) . ']' : '' ); {
$data = ['name' => $multiName]; $multipart_form[] = [
'name' => "{$key}[$subkey]" . (is_array($subvalue) ? '[' . key($subvalue) . ']' : '' ),
if ($key === "attachments") { 'contents' => (is_array($subvalue) ? reset($subvalue) : $subvalue)
$data['contents'] = file_get_contents($multiValue['path']); ];
$data['filename'] = $multiValue['filename'];
} else {
$data['contents'] = (is_array($multiValue) ? reset($multiValue) : $multiValue);
}
$multipart_form[] = $data;
} }
} }
dump($multipart_form);
try { try {
return $client->request('post', $url, [ return $client->request('post', $url, [
'multipart' => $multipart_form, 'multipart' => $multipart_form,

View File

@ -46,6 +46,11 @@ class BluescaleMailTemplate implements \JsonSerializable
*/ */
public $parameters = []; public $parameters = [];
public static function make(string $template_id)
{
return new self($template_id);
}
public function __construct(string $template_id) public function __construct(string $template_id)
{ {
$this->template_id = $template_id; $this->template_id = $template_id;
@ -164,6 +169,8 @@ class BluescaleMailTemplate implements \JsonSerializable
'path' => $file, 'path' => $file,
'filename' => $filename ?? basename($file) 'filename' => $filename ?? basename($file)
]; ];
return $this;
} }
/** /**