Skip to content

Commit c0b409a

Browse files
big-dreamliu21st
authored andcommitted
__sleep(),__wakeup() 调整为 __serialize(),__unserialize()
1 parent b7ed2cd commit c0b409a

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

src/think/route/Dispatch.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
*/
2929
abstract class Dispatch
3030
{
31+
/**
32+
* 控制器名
33+
* @var string
34+
*/
35+
protected $controller;
36+
37+
/**
38+
* 操作名
39+
* @var string
40+
*/
41+
protected $actionName;
42+
3143
/**
3244
* 应用对象
3345
* @var App
@@ -132,7 +144,8 @@ protected function getActionBindVars(): array
132144
/**
133145
* 执行中间件调度
134146
* @access public
135-
* @param object $controller 控制器实例
147+
* @param object $instance 控制器实例
148+
* @param string $action
136149
* @return void
137150
*/
138151
protected function responseWithMiddlewarePipeline($instance, $action)
@@ -321,13 +334,25 @@ public function getParam(): array
321334

322335
abstract public function exec();
323336

324-
public function __sleep()
337+
public function __serialize(): array
325338
{
326-
return ['rule', 'dispatch', 'param', 'controller', 'actionName'];
339+
return [
340+
'rule' => $this->rule,
341+
'dispatch' => $this->dispatch,
342+
'param' => $this->param,
343+
'controller' => $this->controller,
344+
'actionName' => $this->actionName,
345+
];
327346
}
328347

329-
public function __wakeup()
348+
public function __unserialize(array $data): void
330349
{
350+
$this->rule = $data['rule'];
351+
$this->dispatch = $data['dispatch'];
352+
$this->param = $data['param'];
353+
$this->controller = $data['controller'];
354+
$this->actionName = $data['actionName'];
355+
331356
$this->app = Container::pull('app');
332357
$this->request = $this->app->request;
333358
}

src/think/route/Rule.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,13 +1030,29 @@ public function __call($method, $args)
10301030
return call_user_func_array([$this, 'setOption'], $args);
10311031
}
10321032

1033-
public function __sleep()
1033+
public function __serialize(): array
10341034
{
1035-
return ['name', 'rule', 'route', 'method', 'vars', 'option', 'pattern'];
1035+
return [
1036+
'name' => $this->name,
1037+
'rule' => $this->rule,
1038+
'route' => $this->route,
1039+
'method' => $this->method,
1040+
'vars' => $this->vars,
1041+
'option' => $this->option,
1042+
'pattern' => $this->pattern,
1043+
];
10361044
}
10371045

1038-
public function __wakeup()
1046+
public function __unserialize(array $data): void
10391047
{
1048+
$this->name = $data['name'];
1049+
$this->rule = $data['rule'];
1050+
$this->route = $data['route'];
1051+
$this->method = $data['method'];
1052+
$this->vars = $data['vars'];
1053+
$this->option = $data['option'];
1054+
$this->pattern = $data['pattern'];
1055+
10401056
$this->router = Container::pull('route');
10411057
}
10421058

0 commit comments

Comments
 (0)