-
-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathRequestFactory.php
118 lines (103 loc) · 3.41 KB
/
RequestFactory.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\PageBundle\Request;
use Sonata\PageBundle\Runtime\SonataPagePathRuntime;
use Symfony\Component\HttpFoundation\Request;
/**
* NEXT_MAJOR: Remove this class.
*
* @deprecated since sonata-project/page-bundle 4.7.0
*/
final class RequestFactory
{
/**
* @var array<string, class-string<Request>>
*/
private static array $types = [
'host' => Request::class,
'host_with_path' => SiteRequest::class,
'host_with_path_by_locale' => SiteRequest::class,
];
/**
* @deprecated since sonata-project/page-bundle 4.7.0, to be removed in 5.0.
*
* @param array<string, mixed> $parameters
* @param array<string, mixed> $cookies
* @param array<string, mixed> $files
* @param array<string, mixed> $server
* @param string|resource|null $content
*/
public static function create(
string $type,
string $uri,
string $method = 'GET',
array $parameters = [],
array $cookies = [],
array $files = [],
array $server = [],
$content = null,
): Request {
@trigger_error(\sprintf(
'The method "%s()" is deprecated since sonata-project/page-bundle 4.7.0 and will be removed in 5.0.'
.' Use "%s::%s()" instead.',
__METHOD__,
SonataPagePathRuntime::class,
__FUNCTION__
), \E_USER_DEPRECATED);
self::configureFactory($type);
return \call_user_func_array([self::getClass($type), 'create'], [$uri, $method, $parameters, $cookies, $files, $server, $content]);
}
/**
* @deprecated since sonata-project/page-bundle 4.7.0, to be removed in 5.0.
*/
public static function createFromGlobals(string $type): Request
{
@trigger_error(\sprintf(
'The method "%s()" is deprecated since sonata-project/page-bundle 4.7.0 and will be removed in 5.0.'
.' Use "%s::%s()" instead.',
__METHOD__,
SonataPagePathRuntime::class,
__FUNCTION__
), \E_USER_DEPRECATED);
self::configureFactory($type);
return \call_user_func_array([self::getClass($type), 'createFromGlobals'], []);
}
private static function configureFactory(string $type): void
{
if (!\in_array($type, ['host_with_path', 'host_with_path_by_locale'], true)) {
return;
}
Request::setFactory(
/**
* @param string|resource|null $content
*/
static fn (
array $query = [],
array $request = [],
array $attributes = [],
array $cookies = [],
array $files = [],
array $server = [],
$content = null,
) => new SiteRequest($query, $request, $attributes, $cookies, $files, $server, $content)
);
}
/**
* @return class-string<Request>
*/
private static function getClass(string $type): string
{
if (!\array_key_exists($type, self::$types)) {
throw new \RuntimeException('invalid type');
}
return self::$types[$type];
}
}