Skip to content

Commit ff1a0c0

Browse files
committed
optimize code
1 parent 483ec41 commit ff1a0c0

6 files changed

+84
-84
lines changed

ext-src/stubs/php_swoole_http_cookie.stub.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
namespace Swoole\Http {
33
class Cookie {
44
public function __construct() {}
5-
public function setName(string $name): \Swoole\Http\Cookie {}
6-
public function setValue(string $value = '', bool $encode = true): \Swoole\Http\Cookie {}
7-
public function setExpires(int $expires = 0): \Swoole\Http\Cookie {}
8-
public function setPath(string $path = '/'): \Swoole\Http\Cookie {}
9-
public function setDomain(string $domain = ''): \Swoole\Http\Cookie {}
10-
public function setSecure(bool $secure = false): \Swoole\Http\Cookie {}
11-
public function setHttpOnly(bool $httpOnly = false): \Swoole\Http\Cookie {}
12-
public function setSameSite(string $sameSite = ''): \Swoole\Http\Cookie {}
13-
public function setPriority(string $priority = ''): \Swoole\Http\Cookie {}
14-
public function setPartitioned(bool $partitioned = false): \Swoole\Http\Cookie {}
5+
public function withName(string $name): \Swoole\Http\Cookie {}
6+
public function withValue(string $value = '', bool $encode = true): \Swoole\Http\Cookie {}
7+
public function withExpires(int $expires = 0): \Swoole\Http\Cookie {}
8+
public function withPath(string $path = '/'): \Swoole\Http\Cookie {}
9+
public function withDomain(string $domain = ''): \Swoole\Http\Cookie {}
10+
public function withSecure(bool $secure = false): \Swoole\Http\Cookie {}
11+
public function withHttpOnly(bool $httpOnly = false): \Swoole\Http\Cookie {}
12+
public function withSameSite(string $sameSite = ''): \Swoole\Http\Cookie {}
13+
public function withPriority(string $priority = ''): \Swoole\Http\Cookie {}
14+
public function withPartitioned(bool $partitioned = false): \Swoole\Http\Cookie {}
1515
public function getCookie(): array {}
1616
public function reset(): bool {}
1717
}

ext-src/stubs/php_swoole_http_cookie_arginfo.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 02aefd39f4852eea3258eea8edb7000fa86af163 */
2+
* Stub hash: 3a257967f878f1186db07db30ea2caf29bb97fa7 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Swoole_Http_Cookie___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()
66

7-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setName, 0, 1, Swoole\\Http\\Cookie, 0)
7+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withName, 0, 1, Swoole\\Http\\Cookie, 0)
88
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
99
ZEND_END_ARG_INFO()
1010

11-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setValue, 0, 0, Swoole\\Http\\Cookie, 0)
11+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withValue, 0, 0, Swoole\\Http\\Cookie, 0)
1212
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, value, IS_STRING, 0, "\'\'")
1313
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encode, _IS_BOOL, 0, "true")
1414
ZEND_END_ARG_INFO()
1515

16-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setExpires, 0, 0, Swoole\\Http\\Cookie, 0)
16+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withExpires, 0, 0, Swoole\\Http\\Cookie, 0)
1717
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, expires, IS_LONG, 0, "0")
1818
ZEND_END_ARG_INFO()
1919

20-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setPath, 0, 0, Swoole\\Http\\Cookie, 0)
20+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withPath, 0, 0, Swoole\\Http\\Cookie, 0)
2121
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 0, "\'/\'")
2222
ZEND_END_ARG_INFO()
2323

24-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setDomain, 0, 0, Swoole\\Http\\Cookie, 0)
24+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withDomain, 0, 0, Swoole\\Http\\Cookie, 0)
2525
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 0, "\'\'")
2626
ZEND_END_ARG_INFO()
2727

28-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setSecure, 0, 0, Swoole\\Http\\Cookie, 0)
28+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withSecure, 0, 0, Swoole\\Http\\Cookie, 0)
2929
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, secure, _IS_BOOL, 0, "false")
3030
ZEND_END_ARG_INFO()
3131

32-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setHttpOnly, 0, 0, Swoole\\Http\\Cookie, 0)
32+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withHttpOnly, 0, 0, Swoole\\Http\\Cookie, 0)
3333
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, httpOnly, _IS_BOOL, 0, "false")
3434
ZEND_END_ARG_INFO()
3535

36-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setSameSite, 0, 0, Swoole\\Http\\Cookie, 0)
36+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withSameSite, 0, 0, Swoole\\Http\\Cookie, 0)
3737
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sameSite, IS_STRING, 0, "\'\'")
3838
ZEND_END_ARG_INFO()
3939

40-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setPriority, 0, 0, Swoole\\Http\\Cookie, 0)
40+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withPriority, 0, 0, Swoole\\Http\\Cookie, 0)
4141
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, priority, IS_STRING, 0, "\'\'")
4242
ZEND_END_ARG_INFO()
4343

44-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_setPartitioned, 0, 0, Swoole\\Http\\Cookie, 0)
44+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Swoole_Http_Cookie_withPartitioned, 0, 0, Swoole\\Http\\Cookie, 0)
4545
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, partitioned, _IS_BOOL, 0, "false")
4646
ZEND_END_ARG_INFO()
4747

ext-src/swoole_http_cookie.cc

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ static void php_swoole_http_cookie_free_object(zend_object *object) {
6666

6767
SW_EXTERN_C_BEGIN
6868
static PHP_METHOD(swoole_http_cookie, __construct);
69-
static PHP_METHOD(swoole_http_cookie, setName);
70-
static PHP_METHOD(swoole_http_cookie, setValue);
71-
static PHP_METHOD(swoole_http_cookie, setExpires);
72-
static PHP_METHOD(swoole_http_cookie, setPath);
73-
static PHP_METHOD(swoole_http_cookie, setDomain);
74-
static PHP_METHOD(swoole_http_cookie, setSecure);
75-
static PHP_METHOD(swoole_http_cookie, setHttpOnly);
76-
static PHP_METHOD(swoole_http_cookie, setSameSite);
77-
static PHP_METHOD(swoole_http_cookie, setPriority);
78-
static PHP_METHOD(swoole_http_cookie, setPartitioned);
79-
static PHP_METHOD(swoole_http_cookie, setUrlEncode);
69+
static PHP_METHOD(swoole_http_cookie, withName);
70+
static PHP_METHOD(swoole_http_cookie, withValue);
71+
static PHP_METHOD(swoole_http_cookie, withExpires);
72+
static PHP_METHOD(swoole_http_cookie, withPath);
73+
static PHP_METHOD(swoole_http_cookie, withDomain);
74+
static PHP_METHOD(swoole_http_cookie, withSecure);
75+
static PHP_METHOD(swoole_http_cookie, withHttpOnly);
76+
static PHP_METHOD(swoole_http_cookie, withSameSite);
77+
static PHP_METHOD(swoole_http_cookie, withPriority);
78+
static PHP_METHOD(swoole_http_cookie, withPartitioned);
79+
static PHP_METHOD(swoole_http_cookie, withUrlEncode);
8080
static PHP_METHOD(swoole_http_cookie, getCookie);
8181
static PHP_METHOD(swoole_http_cookie, reset);
8282
SW_EXTERN_C_END
@@ -85,16 +85,16 @@ SW_EXTERN_C_END
8585
const zend_function_entry swoole_http_cookie_methods[] =
8686
{
8787
PHP_ME(swoole_http_cookie, __construct, arginfo_class_Swoole_Http_Cookie___construct, ZEND_ACC_PUBLIC)
88-
PHP_ME(swoole_http_cookie, setName, arginfo_class_Swoole_Http_Cookie_setName, ZEND_ACC_PUBLIC)
89-
PHP_ME(swoole_http_cookie, setValue, arginfo_class_Swoole_Http_Cookie_setValue, ZEND_ACC_PUBLIC)
90-
PHP_ME(swoole_http_cookie, setExpires, arginfo_class_Swoole_Http_Cookie_setExpires, ZEND_ACC_PUBLIC)
91-
PHP_ME(swoole_http_cookie, setPath, arginfo_class_Swoole_Http_Cookie_setPath, ZEND_ACC_PUBLIC)
92-
PHP_ME(swoole_http_cookie, setDomain, arginfo_class_Swoole_Http_Cookie_setDomain, ZEND_ACC_PUBLIC)
93-
PHP_ME(swoole_http_cookie, setSecure, arginfo_class_Swoole_Http_Cookie_setSecure, ZEND_ACC_PUBLIC)
94-
PHP_ME(swoole_http_cookie, setHttpOnly, arginfo_class_Swoole_Http_Cookie_setHttpOnly, ZEND_ACC_PUBLIC)
95-
PHP_ME(swoole_http_cookie, setSameSite, arginfo_class_Swoole_Http_Cookie_setSameSite, ZEND_ACC_PUBLIC)
96-
PHP_ME(swoole_http_cookie, setPriority, arginfo_class_Swoole_Http_Cookie_setPriority, ZEND_ACC_PUBLIC)
97-
PHP_ME(swoole_http_cookie, setPartitioned, arginfo_class_Swoole_Http_Cookie_setPartitioned, ZEND_ACC_PUBLIC)
88+
PHP_ME(swoole_http_cookie, withName, arginfo_class_Swoole_Http_Cookie_withName, ZEND_ACC_PUBLIC)
89+
PHP_ME(swoole_http_cookie, withValue, arginfo_class_Swoole_Http_Cookie_withValue, ZEND_ACC_PUBLIC)
90+
PHP_ME(swoole_http_cookie, withExpires, arginfo_class_Swoole_Http_Cookie_withExpires, ZEND_ACC_PUBLIC)
91+
PHP_ME(swoole_http_cookie, withPath, arginfo_class_Swoole_Http_Cookie_withPath, ZEND_ACC_PUBLIC)
92+
PHP_ME(swoole_http_cookie, withDomain, arginfo_class_Swoole_Http_Cookie_withDomain, ZEND_ACC_PUBLIC)
93+
PHP_ME(swoole_http_cookie, withSecure, arginfo_class_Swoole_Http_Cookie_withSecure, ZEND_ACC_PUBLIC)
94+
PHP_ME(swoole_http_cookie, withHttpOnly, arginfo_class_Swoole_Http_Cookie_withHttpOnly, ZEND_ACC_PUBLIC)
95+
PHP_ME(swoole_http_cookie, withSameSite, arginfo_class_Swoole_Http_Cookie_withSameSite, ZEND_ACC_PUBLIC)
96+
PHP_ME(swoole_http_cookie, withPriority, arginfo_class_Swoole_Http_Cookie_withPriority, ZEND_ACC_PUBLIC)
97+
PHP_ME(swoole_http_cookie, withPartitioned, arginfo_class_Swoole_Http_Cookie_withPartitioned, ZEND_ACC_PUBLIC)
9898
PHP_ME(swoole_http_cookie, getCookie, arginfo_class_Swoole_Http_Cookie_getCookie, ZEND_ACC_PUBLIC)
9999
PHP_ME(swoole_http_cookie, reset, arginfo_class_Swoole_Http_Cookie_reset, ZEND_ACC_PUBLIC)
100100
PHP_FE_END
@@ -118,7 +118,7 @@ static PHP_METHOD(swoole_http_cookie, __construct) {
118118
RETURN_TRUE;
119119
}
120120

121-
static PHP_METHOD(swoole_http_cookie, setName) {
121+
static PHP_METHOD(swoole_http_cookie, withName) {
122122
zend_string *name = nullptr;
123123
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
124124

@@ -136,7 +136,7 @@ static PHP_METHOD(swoole_http_cookie, setName) {
136136
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
137137
}
138138

139-
static PHP_METHOD(swoole_http_cookie, setValue) {
139+
static PHP_METHOD(swoole_http_cookie, withValue) {
140140
zend_string *value = nullptr;
141141
zend_bool encode = true;
142142
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
@@ -161,7 +161,7 @@ static PHP_METHOD(swoole_http_cookie, setValue) {
161161
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
162162
}
163163

164-
static PHP_METHOD(swoole_http_cookie, setExpires) {
164+
static PHP_METHOD(swoole_http_cookie, withExpires) {
165165
zend_long expires = 0;
166166
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
167167

@@ -174,7 +174,7 @@ static PHP_METHOD(swoole_http_cookie, setExpires) {
174174
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
175175
}
176176

177-
static PHP_METHOD(swoole_http_cookie, setPath) {
177+
static PHP_METHOD(swoole_http_cookie, withPath) {
178178
zend_string *path = nullptr;
179179
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
180180

@@ -193,7 +193,7 @@ static PHP_METHOD(swoole_http_cookie, setPath) {
193193
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
194194
}
195195

196-
static PHP_METHOD(swoole_http_cookie, setDomain) {
196+
static PHP_METHOD(swoole_http_cookie, withDomain) {
197197
zend_string *domain = nullptr;
198198
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
199199

@@ -212,7 +212,7 @@ static PHP_METHOD(swoole_http_cookie, setDomain) {
212212
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
213213
}
214214

215-
static PHP_METHOD(swoole_http_cookie, setSecure) {
215+
static PHP_METHOD(swoole_http_cookie, withSecure) {
216216
zend_bool secure = false;
217217
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
218218

@@ -225,7 +225,7 @@ static PHP_METHOD(swoole_http_cookie, setSecure) {
225225
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
226226
}
227227

228-
static PHP_METHOD(swoole_http_cookie, setHttpOnly) {
228+
static PHP_METHOD(swoole_http_cookie, withHttpOnly) {
229229
zend_bool httpOnly = false;
230230
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
231231

@@ -238,7 +238,7 @@ static PHP_METHOD(swoole_http_cookie, setHttpOnly) {
238238
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
239239
}
240240

241-
static PHP_METHOD(swoole_http_cookie, setSameSite) {
241+
static PHP_METHOD(swoole_http_cookie, withSameSite) {
242242
zend_string *sameSite = nullptr;
243243
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
244244

@@ -257,7 +257,7 @@ static PHP_METHOD(swoole_http_cookie, setSameSite) {
257257
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
258258
}
259259

260-
static PHP_METHOD(swoole_http_cookie, setPriority) {
260+
static PHP_METHOD(swoole_http_cookie, withPriority) {
261261
zend_string *priority = nullptr;
262262
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
263263

@@ -276,7 +276,7 @@ static PHP_METHOD(swoole_http_cookie, setPriority) {
276276
RETURN_OBJ_COPY(Z_OBJ_P(ZEND_THIS));
277277
}
278278

279-
static PHP_METHOD(swoole_http_cookie, setPartitioned) {
279+
static PHP_METHOD(swoole_http_cookie, withPartitioned) {
280280
zend_bool partitioned = false;
281281
HttpCookie *cookie = php_swoole_http_get_cookie(ZEND_THIS);
282282

tests/swoole_http_server/cookieAlias.phpt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ $pm->childFunc = function () use ($pm) {
2020
});
2121
$server->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($pm) {
2222
$cookie = new Swoole\Http\Cookie();
23-
$cookie->setName('key1')
24-
->setValue('val1')
25-
->setExpires(time() + 84600)
26-
->setPath('/')
27-
->setDomain('id.test.com')
28-
->setSecure(true)
29-
->setHttpOnly(true)
30-
->setSameSite('None')
31-
->setPriority('High')
32-
->setPartitioned(true);
23+
$cookie->withName('key1')
24+
->withValue('val1')
25+
->withExpires(time() + 84600)
26+
->withPath('/')
27+
->withDomain('id.test.com')
28+
->withSecure(true)
29+
->withHttpOnly(true)
30+
->withSameSite('None')
31+
->withPriority('High')
32+
->withPartitioned(true);
3333
$response->setObjectCookie($cookie);
3434
$response->setCookie('key1', 'val1', time() + 84600, '/', 'id.test.com', true, true, 'None', 'High', true);
3535
$response->setRawCookie('key1', 'val1', time() + 84600, '/', 'id.test.com', true, true, 'None', 'High', true);
3636

37-
$cookie->setValue('');
37+
$cookie->withValue('');
3838
$response->setObjectCookie($cookie);
3939
$response->end("<h1>Hello Swoole. #" . rand(1000, 9999) . "</h1>");
4040
});

tests/swoole_http_server/objectCookie.phpt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ $pm->childFunc = function () use ($pm) {
2020
});
2121
$server->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($pm) {
2222
$cookie = new Swoole\Http\Cookie();
23-
$cookie->setName('key1')
24-
->setValue('val1')
25-
->setExpires(time() + 84600)
26-
->setPath('/')
27-
->setDomain('id.test.com')
28-
->setSecure(true)
29-
->setHttpOnly(true)
30-
->setSameSite('None')
31-
->setPriority('High')
32-
->setPartitioned(true);
23+
$cookie->withName('key1')
24+
->withValue('val1')
25+
->withExpires(time() + 84600)
26+
->withPath('/')
27+
->withDomain('id.test.com')
28+
->withSecure(true)
29+
->withHttpOnly(true)
30+
->withSameSite('None')
31+
->withPriority('High')
32+
->withPartitioned(true);
3333
$response->setObjectCookie($cookie);
34-
$cookie->setValue('');
34+
$cookie->withValue('');
3535
$response->setObjectCookie($cookie);
3636
$response->end("<h1>Hello Swoole. #" . rand(1000, 9999) . "</h1>");
3737
});

tests/swoole_http_server/objectCookieMemory.phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ $pm->childFunc = function () use ($pm) {
3636
$cookie = new Swoole\Http\Cookie();
3737
$i = 10000;
3838
while($i--) {
39-
$cookie->setName('key1')
40-
->setValue('val1')
41-
->setExpires(time() + 84600)
42-
->setPath('/')
43-
->setDomain('id.test.com')
44-
->setSecure(true)
45-
->setHttpOnly(true)
46-
->setSameSite('None')
47-
->setPriority('High')
48-
->setPartitioned(true);
39+
$cookie->withName('key1')
40+
->withValue('val1')
41+
->withExpires(time() + 84600)
42+
->withPath('/')
43+
->withDomain('id.test.com')
44+
->withSecure(true)
45+
->withHttpOnly(true)
46+
->withSameSite('None')
47+
->withPriority('High')
48+
->withPartitioned(true);
4949
}
5050

5151
global $previous;

0 commit comments

Comments
 (0)