-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathSerializableRequest.php
More file actions
89 lines (81 loc) · 3.29 KB
/
SerializableRequest.php
File metadata and controls
89 lines (81 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace InterNations\Component\HttpMock\Request;
use Serializable;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\FileBag;
use Symfony\Component\HttpFoundation\Request;
class SerializableRequest extends Request implements Serializable
{
public function serialize(): string
{
$this->getContent();
$files = [];
if ($this->files) {
foreach ($this->files as $key => $file) {
// Move the file in another directory
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5($file->getPathname());
$file->move(sys_get_temp_dir(), md5($file->getPathname()));
$files[$key] = [
'originalName' => $file->getClientOriginalName(),
'pathName' => $path,
];
}
}
return serialize([
'attributes' => $this->attributes,
'request' => $this->request,
'query' => $this->query,
'server' => $this->server,
'files' => $files,
'cookies' => $this->cookies,
'headers' => $this->headers,
'content' => $this->content,
'languages' => $this->languages,
'charsets' => $this->charsets,
'encodings' => $this->encodings,
'acceptableContentTypes' => $this->acceptableContentTypes,
'pathInfo' => $this->pathInfo,
'requestUri' => $this->requestUri,
'baseUrl' => $this->baseUrl,
'basePath' => $this->basePath,
'method' => $this->method,
'format' => $this->format,
'session' => $this->session,
'locale' => $this->locale,
'defaultLocale' => $this->defaultLocale,
]);
}
/** @param array<mixed> $data */
public function unserialize($data): void // @codingStandardsIgnoreLine
{
$attributes = unserialize($data);
$this->attributes = $attributes['attributes'];
$this->request = $attributes['request'];
$this->query = $attributes['query'];
$this->server = $attributes['server'];
$files = $attributes['files'];
$this->files = [];
if ($files) {
foreach($files as $key => $file) {
$this->files[$key] = new UploadedFile($file['pathName'], $file['originalName'], null, null, true);
}
}
$this->files = new FileBag($this->files);
$this->cookies = $attributes['cookies'];
$this->headers = $attributes['headers'];
$this->content = $attributes['content'];
$this->languages = $attributes['languages'];
$this->charsets = $attributes['charsets'];
$this->encodings = $attributes['encodings'];
$this->acceptableContentTypes = $attributes['acceptableContentTypes'];
$this->pathInfo = $attributes['pathInfo'];
$this->requestUri = $attributes['requestUri'];
$this->baseUrl = $attributes['baseUrl'];
$this->basePath = $attributes['basePath'];
$this->method = $attributes['method'];
$this->format = $attributes['format'];
$this->session = $attributes['session'];
$this->locale = $attributes['locale'];
$this->defaultLocale = $attributes['defaultLocale'];
}
}