maintenant sa march
This commit is contained in:
parent
2ff5b2012d
commit
9559436543
|
@ -54,27 +54,37 @@ class BluescaleMailApi
|
|||
|
||||
$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)) {
|
||||
$multipart_form[] = ['name' => $key, 'contents' => $value];
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($value as $multiKey => $multiValue) {
|
||||
$multiName = $key . '[' .$multiKey . ']' . (is_array($multiValue) ? '[' . key($multiValue) . ']' : '' );
|
||||
$data = ['name' => $multiName];
|
||||
|
||||
if ($key === "attachments") {
|
||||
$data['contents'] = file_get_contents($multiValue['path']);
|
||||
$data['filename'] = $multiValue['filename'];
|
||||
} else {
|
||||
$data['contents'] = (is_array($multiValue) ? reset($multiValue) : $multiValue);
|
||||
}
|
||||
|
||||
$multipart_form[] = $data;
|
||||
foreach ($value as $subkey => $subvalue)
|
||||
{
|
||||
$multipart_form[] = [
|
||||
'name' => "{$key}[$subkey]" . (is_array($subvalue) ? '[' . key($subvalue) . ']' : '' ),
|
||||
'contents' => (is_array($subvalue) ? reset($subvalue) : $subvalue)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
dump($multipart_form);
|
||||
|
||||
try {
|
||||
return $client->request('post', $url, [
|
||||
'multipart' => $multipart_form,
|
||||
|
|
|
@ -46,6 +46,11 @@ class BluescaleMailTemplate implements \JsonSerializable
|
|||
*/
|
||||
public $parameters = [];
|
||||
|
||||
public static function make(string $template_id)
|
||||
{
|
||||
return new self($template_id);
|
||||
}
|
||||
|
||||
public function __construct(string $template_id)
|
||||
{
|
||||
$this->template_id = $template_id;
|
||||
|
@ -164,6 +169,8 @@ class BluescaleMailTemplate implements \JsonSerializable
|
|||
'path' => $file,
|
||||
'filename' => $filename ?? basename($file)
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue