Completed
Push — 6.0 ( eaf6e6...b4046f )
by liu
02:47
created

Rule::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
// +----------------------------------------------------------------------
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\route;
14
15
use Closure;
16
use think\Container;
17
use think\middleware\AllowCrossDomain;
18
use think\middleware\CheckRequestCache;
19
use think\middleware\FormTokenCheck;
20
use think\Request;
21
use think\Route;
22
use think\route\dispatch\Callback as CallbackDispatch;
23
use think\route\dispatch\Controller as ControllerDispatch;
24
25
/**
26
 * 路由规则基础类
27
 */
28
abstract class Rule
29
{
30
    /**
31
     * 路由标识
32
     * @var string
33
     */
34
    protected $name;
35
36
    /**
37
     * 所在域名
38
     * @var string
39
     */
40
    protected $domain;
41
42
    /**
43
     * 路由对象
44
     * @var Route
45
     */
46
    protected $router;
47
48
    /**
49
     * 路由所属分组
50
     * @var RuleGroup
51
     */
52
    protected $parent;
53
54
    /**
55
     * 路由规则
56
     * @var mixed
57
     */
58
    protected $rule;
59
60
    /**
61
     * 路由地址
62
     * @var string|Closure
63
     */
64
    protected $route;
65
66
    /**
67
     * 请求类型
68
     * @var string
69
     */
70
    protected $method;
71
72
    /**
73
     * 路由变量
74
     * @var array
75
     */
76
    protected $vars = [];
77
78
    /**
79
     * 路由参数
80
     * @var array
81
     */
82
    protected $option = [];
83
84
    /**
85
     * 路由变量规则
86
     * @var array
87
     */
88
    protected $pattern = [];
89
90
    /**
91
     * 需要和分组合并的路由参数
92
     * @var array
93
     */
94
    protected $mergeOptions = ['model', 'append', 'middleware'];
95
96
    abstract public function check(Request $request, string $url, bool $completeMatch = false);
97
98
    /**
99
     * 设置路由参数
100
     * @access public
101
     * @param  array $option 参数
102
     * @return $this
103
     */
104
    public function option(array $option)
105
    {
106
        $this->option = array_merge($this->option, $option);
107
108
        return $this;
109
    }
110
111
    /**
112
     * 设置单个路由参数
113
     * @access public
114
     * @param  string $name  参数名
115
     * @param  mixed  $value 值
116
     * @return $this
117
     */
118 33
    public function setOption(string $name, $value)
119
    {
120 33
        $this->option[$name] = $value;
121
122 33
        return $this;
123
    }
124
125
    /**
126
     * 注册变量规则
127
     * @access public
128
     * @param  array $pattern 变量规则
129
     * @return $this
130
     */
131
    public function pattern(array $pattern)
132
    {
133
        $this->pattern = array_merge($this->pattern, $pattern);
134
135
        return $this;
136
    }
137
138
    /**
139
     * 设置标识
140
     * @access public
141
     * @param  string $name 标识名
142
     * @return $this
143
     */
144
    public function name(string $name)
145
    {
146
        $this->name = $name;
147
148
        return $this;
149
    }
150
151
    /**
152
     * 获取路由对象
153
     * @access public
154
     * @return Route
155
     */
156 6
    public function getRouter(): Route
157
    {
158 6
        return $this->router;
159
    }
160
161
    /**
162
     * 获取Name
163
     * @access public
164
     * @return string
165
     */
166
    public function getName(): string
167
    {
168
        return $this->name ?: '';
169
    }
170
171
    /**
172
     * 获取当前路由规则
173
     * @access public
174
     * @return mixed
175
     */
176 3
    public function getRule()
177
    {
178 3
        return $this->rule;
179
    }
180
181
    /**
182
     * 获取当前路由地址
183
     * @access public
184
     * @return mixed
185
     */
186 30
    public function getRoute()
187
    {
188 30
        return $this->route;
189
    }
190
191
    /**
192
     * 获取当前路由的变量
193
     * @access public
194
     * @return array
195
     */
196
    public function getVars(): array
197
    {
198
        return $this->vars;
199
    }
200
201
    /**
202
     * 获取Parent对象
203
     * @access public
204
     * @return $this|null
205
     */
206
    public function getParent()
207
    {
208
        return $this->parent;
209
    }
210
211
    /**
212
     * 获取路由所在域名
213
     * @access public
214
     * @return string
215
     */
216
    public function getDomain(): string
217
    {
218
        return $this->domain ?: $this->parent->getDomain();
219
    }
220
221
    /**
222
     * 获取路由参数
223
     * @access public
224
     * @param  string $name 变量名
225
     * @return mixed
226
     */
227 12
    public function config(string $name = '')
228
    {
229 12
        return $this->router->config($name);
230
    }
231
232
    /**
233
     * 获取变量规则定义
234
     * @access public
235
     * @param  string $name 变量名
236
     * @return mixed
237
     */
238 30
    public function getPattern(string $name = '')
239
    {
240 30
        if ('' === $name) {
241 30
            return $this->pattern;
242
        }
243
244
        return $this->pattern[$name] ?? null;
245
    }
246
247
    /**
248
     * 获取路由参数定义
249
     * @access public
250
     * @param  string $name 参数名
251
     * @param  mixed  $default 默认值
252
     * @return mixed
253
     */
254 33
    public function getOption(string $name = '', $default = null)
255
    {
256 33
        if ('' === $name) {
257 33
            return $this->option;
258
        }
259
260
        return $this->option[$name] ?? $default;
261
    }
262
263
    /**
264
     * 获取当前路由的请求类型
265
     * @access public
266
     * @return string
267
     */
268 3
    public function getMethod(): string
269
    {
270 3
        return strtolower($this->method);
271
    }
272
273
    /**
274
     * 设置路由请求类型
275
     * @access public
276
     * @param  string $method 请求类型
277
     * @return $this
278
     */
279
    public function method(string $method)
280
    {
281
        return $this->setOption('method', strtolower($method));
282
    }
283
284
    /**
285
     * 检查后缀
286
     * @access public
287
     * @param  string $ext URL后缀
288
     * @return $this
289
     */
290
    public function ext(string $ext = '')
291
    {
292
        return $this->setOption('ext', $ext);
293
    }
294
295
    /**
296
     * 检查禁止后缀
297
     * @access public
298
     * @param  string $ext URL后缀
299
     * @return $this
300
     */
301
    public function denyExt(string $ext = '')
302
    {
303
        return $this->setOption('deny_ext', $ext);
304
    }
305
306
    /**
307
     * 检查域名
308
     * @access public
309
     * @param  string $domain 域名
310
     * @return $this
311
     */
312
    public function domain(string $domain)
313
    {
314
        $this->domain = $domain;
315
        return $this->setOption('domain', $domain);
316
    }
317
318
    /**
319
     * 设置参数过滤检查
320
     * @access public
321
     * @param  array $filter 参数过滤
322
     * @return $this
323
     */
324
    public function filter(array $filter)
325
    {
326
        $this->option['filter'] = $filter;
327
328
        return $this;
329
    }
330
331
    /**
332
     * 绑定模型
333
     * @access public
334
     * @param  array|string|Closure $var  路由变量名 多个使用 & 分割
335
     * @param  string|Closure       $model 绑定模型类
336
     * @param  bool                  $exception 是否抛出异常
337
     * @return $this
338
     */
339
    public function model($var, $model = null, bool $exception = true)
340
    {
341
        if ($var instanceof Closure) {
342
            $this->option['model'][] = $var;
343
        } elseif (is_array($var)) {
344
            $this->option['model'] = $var;
345
        } elseif (is_null($model)) {
346
            $this->option['model']['id'] = [$var, true];
347
        } else {
348
            $this->option['model'][$var] = [$model, $exception];
349
        }
350
351
        return $this;
352
    }
353
354
    /**
355
     * 附加路由隐式参数
356
     * @access public
357
     * @param  array $append 追加参数
358
     * @return $this
359
     */
360
    public function append(array $append = [])
361
    {
362
        $this->option['append'] = $append;
363
364
        return $this;
365
    }
366
367
    /**
368
     * 绑定验证
369
     * @access public
370
     * @param  mixed  $validate 验证器类
371
     * @param  string $scene 验证场景
372
     * @param  array  $message 验证提示
373
     * @param  bool   $batch 批量验证
374
     * @return $this
375
     */
376
    public function validate($validate, string $scene = null, array $message = [], bool $batch = false)
377
    {
378
        $this->option['validate'] = [$validate, $scene, $message, $batch];
379
380
        return $this;
381
    }
382
383
    /**
384
     * 指定路由中间件
385
     * @access public
386
     * @param string|array|Closure $middleware 中间件
387
     * @param mixed $params 参数
388
     * @return $this
389
     */
390 3
    public function middleware($middleware, ...$params)
391
    {
392 3
        if (empty($params) && is_array($middleware)) {
393
            $this->option['middleware'] = $middleware;
394
        } else {
395 3
            foreach ((array) $middleware as $item) {
396 3
                $this->option['middleware'][] = [$item, $params];
397
            }
398
        }
399
400 3
        return $this;
401
    }
402
403
    /**
404
     * 允许跨域
405
     * @access public
406
     * @param  array $header 自定义Header
407
     * @return $this
408
     */
409 3
    public function allowCrossDomain(array $header = [])
410
    {
411 3
        return $this->middleware(AllowCrossDomain::class, $header);
412
    }
413
414
    /**
415
     * 表单令牌验证
416
     * @access public
417
     * @param  string $token 表单令牌token名称
418
     * @return $this
419
     */
420
    public function token(string $token = '__token__')
421
    {
422
        return $this->middleware(FormTokenCheck::class, $token);
423
    }
424
425
    /**
426
     * 设置路由缓存
427
     * @access public
428
     * @param  array|string $cache 缓存
429
     * @return $this
430
     */
431
    public function cache($cache)
432
    {
433
        return $this->middleware(CheckRequestCache::class, $cache);
434
    }
435
436
    /**
437
     * 检查URL分隔符
438
     * @access public
439
     * @param  string $depr URL分隔符
440
     * @return $this
441
     */
442
    public function depr(string $depr)
443
    {
444
        return $this->setOption('param_depr', $depr);
445
    }
446
447
    /**
448
     * 设置需要合并的路由参数
449
     * @access public
450
     * @param  array $option 路由参数
451
     * @return $this
452
     */
453
    public function mergeOptions(array $option = [])
454
    {
455
        $this->mergeOptions = array_merge($this->mergeOptions, $option);
456
        return $this;
457
    }
458
459
    /**
460
     * 检查是否为HTTPS请求
461
     * @access public
462
     * @param  bool $https 是否为HTTPS
463
     * @return $this
464
     */
465
    public function https(bool $https = true)
466
    {
467
        return $this->setOption('https', $https);
468
    }
469
470
    /**
471
     * 检查是否为JSON请求
472
     * @access public
473
     * @param  bool $json 是否为JSON
474
     * @return $this
475
     */
476
    public function json(bool $json = true)
477
    {
478
        return $this->setOption('json', $json);
479
    }
480
481
    /**
482
     * 检查是否为AJAX请求
483
     * @access public
484
     * @param  bool $ajax 是否为AJAX
485
     * @return $this
486
     */
487
    public function ajax(bool $ajax = true)
488
    {
489
        return $this->setOption('ajax', $ajax);
490
    }
491
492
    /**
493
     * 检查是否为PJAX请求
494
     * @access public
495
     * @param  bool $pjax 是否为PJAX
496
     * @return $this
497
     */
498
    public function pjax(bool $pjax = true)
499
    {
500
        return $this->setOption('pjax', $pjax);
501
    }
502
503
    /**
504
     * 路由到一个模板地址 需要额外传入的模板变量
505
     * @access public
506
     * @param  array $view 视图
507
     * @return $this
508
     */
509
    public function view(array $view = [])
510
    {
511
        return $this->setOption('view', $view);
512
    }
513
514
    /**
515
     * 设置路由完整匹配
516
     * @access public
517
     * @param  bool $match 是否完整匹配
518
     * @return $this
519
     */
520
    public function completeMatch(bool $match = true)
521
    {
522
        return $this->setOption('complete_match', $match);
523
    }
524
525
    /**
526
     * 是否去除URL最后的斜线
527
     * @access public
528
     * @param  bool $remove 是否去除最后斜线
529
     * @return $this
530
     */
531 33
    public function removeSlash(bool $remove = true)
532
    {
533 33
        return $this->setOption('remove_slash', $remove);
534
    }
535
536
    /**
537
     * 设置路由规则全局有效
538
     * @access public
539
     * @return $this
540
     */
541
    public function crossDomainRule()
542
    {
543
        if ($this instanceof RuleGroup) {
544
            $method = '*';
545
        } else {
546
            $method = $this->method;
547
        }
548
549
        $this->router->setCrossDomainRule($this, $method);
550
551
        return $this;
552
    }
553
554
    /**
555
     * 合并分组参数
556
     * @access public
557
     * @return array
558
     */
559 30
    public function mergeGroupOptions(): array
560
    {
561 30
        $parentOption = $this->parent->getOption();
562
        // 合并分组参数
563 30
        foreach ($this->mergeOptions as $item) {
564 30
            if (isset($parentOption[$item]) && isset($this->option[$item])) {
565 10
                $this->option[$item] = array_merge($parentOption[$item], $this->option[$item]);
566
            }
567
        }
568
569 30
        $this->option = array_merge($parentOption, $this->option);
570
571 30
        return $this->option;
572
    }
573
574
    /**
575
     * 解析匹配到的规则路由
576
     * @access public
577
     * @param  Request $request 请求对象
578
     * @param  string  $rule 路由规则
579
     * @param  mixed   $route 路由地址
580
     * @param  string  $url URL地址
581
     * @param  array   $option 路由参数
582
     * @param  array   $matches 匹配的变量
583
     * @return Dispatch
584
     */
585 30
    public function parseRule(Request $request, string $rule, $route, string $url, array $option = [], array $matches = []): Dispatch
586
    {
587 30
        if (is_string($route) && isset($option['prefix'])) {
588
            // 路由地址前缀
589
            $route = $option['prefix'] . $route;
590
        }
591
592
        // 替换路由地址中的变量
593 30
        if (is_string($route) && !empty($matches)) {
594 3
            $search = $replace = [];
595
596 3
            foreach ($matches as $key => $value) {
597 3
                $search[]  = '<' . $key . '>';
598 3
                $replace[] = $value;
599
600 3
                $search[]  = ':' . $key;
601 3
                $replace[] = $value;
602
            }
603
604 3
            $route = str_replace($search, $replace, $route);
605
        }
606
607
        // 解析额外参数
608 30
        $count = substr_count($rule, '/');
609 30
        $url   = array_slice(explode('|', $url), $count + 1);
610 30
        $this->parseUrlParams(implode('|', $url), $matches);
611
612 30
        $this->vars = $matches;
613
614
        // 发起路由调度
615 30
        return $this->dispatch($request, $route, $option);
616
    }
617
618
    /**
619
     * 发起路由调度
620
     * @access protected
621
     * @param  Request $request Request对象
622
     * @param  mixed   $route  路由地址
623
     * @param  array   $option 路由参数
624
     * @return Dispatch
625
     */
626 30
    protected function dispatch(Request $request, $route, array $option): Dispatch
627
    {
628 30
        if (is_subclass_of($route, Dispatch::class)) {
629
            $result = new $route($request, $this, $route, $this->vars);
630 30
        } elseif ($route instanceof Closure) {
631
            // 执行闭包
632 21
            $result = new CallbackDispatch($request, $this, $route, $this->vars);
633 12
        } elseif (false !== strpos($route, '@') || false !== strpos($route, '::')) {
634
            // 路由到类的方法
635
            $route  = str_replace('::', '@', $route);
636
            $result = $this->dispatchMethod($request, $route);
637
        } else {
638
            // 路由到控制器/操作
639 12
            $result = $this->dispatchController($request, $route);
640
        }
641
642 30
        return $result;
643
    }
644
645
    /**
646
     * 解析URL地址为 模块/控制器/操作
647
     * @access protected
648
     * @param  Request $request Request对象
649
     * @param  string  $route 路由地址
650
     * @return CallbackDispatch
651
     */
652
    protected function dispatchMethod(Request $request, string $route): CallbackDispatch
653
    {
654
        $path = $this->parseUrlPath($route);
655
656
        $route  = str_replace('/', '@', implode('/', $path));
657
        $method = strpos($route, '@') ? explode('@', $route) : $route;
658
659
        return new CallbackDispatch($request, $this, $method, $this->vars);
660
    }
661
662
    /**
663
     * 解析URL地址为 模块/控制器/操作
664
     * @access protected
665
     * @param  Request $request Request对象
666
     * @param  string  $route 路由地址
667
     * @return ControllerDispatch
668
     */
669 12
    protected function dispatchController(Request $request, string $route): ControllerDispatch
670
    {
671 12
        $path = $this->parseUrlPath($route);
672
673 12
        $action     = array_pop($path);
674 12
        $controller = !empty($path) ? array_pop($path) : null;
675
676
        // 路由到模块/控制器/操作
677 12
        return new ControllerDispatch($request, $this, [$controller, $action], $this->vars);
678
    }
679
680
    /**
681
     * 路由检查
682
     * @access protected
683
     * @param  array   $option 路由参数
684
     * @param  Request $request Request对象
685
     * @return bool
686
     */
687 33
    protected function checkOption(array $option, Request $request): bool
688
    {
689
        // 请求类型检测
690 33
        if (!empty($option['method'])) {
691
            if (is_string($option['method']) && false === stripos($option['method'], $request->method())) {
692
                return false;
693
            }
694
        }
695
696
        // AJAX PJAX 请求检查
697 33
        foreach (['ajax', 'pjax', 'json'] as $item) {
698 33
            if (isset($option[$item])) {
699
                $call = 'is' . $item;
700
                if ($option[$item] && !$request->$call() || !$option[$item] && $request->$call()) {
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: ($option[$item] && ! $re...m] && $request->$call(), Probably Intended Meaning: $option[$item] && (! $re...] && $request->$call())
Loading history...
701 11
                    return false;
702
                }
703
            }
704
        }
705
706
        // 伪静态后缀检测
707 33
        if ($request->url() != '/' && ((isset($option['ext']) && false === stripos('|' . $option['ext'] . '|', '|' . $request->ext() . '|'))
708 33
            || (isset($option['deny_ext']) && false !== stripos('|' . $option['deny_ext'] . '|', '|' . $request->ext() . '|')))) {
709
            return false;
710
        }
711
712
        // 域名检查
713 33
        if ((isset($option['domain']) && !in_array($option['domain'], [$request->host(true), $request->subDomain()]))) {
714
            return false;
715
        }
716
717
        // HTTPS检查
718 33
        if ((isset($option['https']) && $option['https'] && !$request->isSsl())
719 33
            || (isset($option['https']) && !$option['https'] && $request->isSsl())) {
720
            return false;
721
        }
722
723
        // 请求参数检查
724 33
        if (isset($option['filter'])) {
725
            foreach ($option['filter'] as $name => $value) {
726
                if ($request->param($name, '', null) != $value) {
727
                    return false;
728
                }
729
            }
730
        }
731
732 33
        return true;
733
    }
734
735
    /**
736
     * 解析URL地址中的参数Request对象
737
     * @access protected
738
     * @param  string $rule 路由规则
739
     * @param  array  $var 变量
740
     * @return void
741
     */
742 30
    protected function parseUrlParams(string $url, array &$var = []): void
743
    {
744 30
        if ($url) {
745
            preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) {
746
                $var[$match[1]] = strip_tags($match[2]);
747
            }, $url);
748
        }
749 30
    }
750
751
    /**
752
     * 解析URL的pathinfo参数
753
     * @access public
754
     * @param  string $url URL地址
755
     * @return array
756
     */
757 15
    public function parseUrlPath(string $url): array
758
    {
759
        // 分隔符替换 确保路由定义使用统一的分隔符
760 15
        $url = str_replace('|', '/', $url);
761 15
        $url = trim($url, '/');
762
763 15
        if (strpos($url, '/')) {
764
            // [控制器/操作]
765 12
            $path = explode('/', $url);
766
        } else {
767 3
            $path = [$url];
768
        }
769
770 15
        return $path;
771
    }
772
773
    /**
774
     * 生成路由的正则规则
775
     * @access protected
776
     * @param  string $rule 路由规则
777
     * @param  array  $match 匹配的变量
778
     * @param  array  $pattern   路由变量规则
779
     * @param  array  $option    路由参数
780
     * @param  bool   $completeMatch   路由是否完全匹配
781
     * @param  string $suffix   路由正则变量后缀
782
     * @return string
783
     */
784 6
    protected function buildRuleRegex(string $rule, array $match, array $pattern = [], array $option = [], bool $completeMatch = false, string $suffix = ''): string
785
    {
786 6
        foreach ($match as $name) {
787 6
            $replace[] = $this->buildNameRegex($name, $pattern, $suffix);
788
        }
789
790
        // 是否区分 / 地址访问
791 6
        if ('/' != $rule) {
792 6
            if (!empty($option['remove_slash'])) {
793
                $rule = rtrim($rule, '/');
794 6
            } elseif (substr($rule, -1) == '/') {
795
                $rule     = rtrim($rule, '/');
796
                $hasSlash = true;
797
            }
798
        }
799
800 6
        $regex = str_replace(array_unique($match), array_unique($replace), $rule);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $replace seems to be defined by a foreach iteration on line 786. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
801 6
        $regex = str_replace([')?/', ')/', ')?-', ')-', '\\\\/'], [')\/', ')\/', ')\-', ')\-', '\/'], $regex);
802
803 6
        if (isset($hasSlash)) {
804
            $regex .= '\/';
805
        }
806
807 6
        return $regex . ($completeMatch ? '$' : '');
808
    }
809
810
    /**
811
     * 生成路由变量的正则规则
812
     * @access protected
813
     * @param  string $name    路由变量
814
     * @param  array  $pattern 变量规则
815
     * @param  string $suffix  路由正则变量后缀
816
     * @return string
817
     */
818 6
    protected function buildNameRegex(string $name, array $pattern, string $suffix): string
819
    {
820 6
        $optional = '';
821 6
        $slash    = substr($name, 0, 1);
822
823 6
        if (in_array($slash, ['/', '-'])) {
824 6
            $prefix = '\\' . $slash;
825 6
            $name   = substr($name, 1);
826 6
            $slash  = substr($name, 0, 1);
827
        } else {
828
            $prefix = '';
829
        }
830
831 6
        if ('<' != $slash) {
832 6
            return $prefix . preg_quote($name, '/');
833
        }
834
835 6
        if (strpos($name, '?')) {
836
            $name     = substr($name, 1, -2);
837
            $optional = '?';
838 6
        } elseif (strpos($name, '>')) {
839 6
            $name = substr($name, 1, -1);
840
        }
841
842 6
        if (isset($pattern[$name])) {
843
            $nameRule = $pattern[$name];
844
            if (0 === strpos($nameRule, '/') && '/' == substr($nameRule, -1)) {
845
                $nameRule = substr($nameRule, 1, -1);
846
            }
847
        } else {
848 6
            $nameRule = $this->router->config('default_route_pattern');
849
        }
850
851 6
        return '(' . $prefix . '(?<' . $name . $suffix . '>' . $nameRule . '))' . $optional;
852
    }
853
854
    /**
855
     * 设置路由参数
856
     * @access public
857
     * @param  string $method 方法名
858
     * @param  array  $args   调用参数
859
     * @return $this
860
     */
861
    public function __call($method, $args)
862
    {
863
        if (count($args) > 1) {
864
            $args[0] = $args;
865
        }
866
        array_unshift($args, $method);
867
868
        return call_user_func_array([$this, 'setOption'], $args);
869
    }
870
871
    public function __sleep()
872
    {
873
        return ['name', 'rule', 'route', 'method', 'vars', 'option', 'pattern'];
874
    }
875
876
    public function __wakeup()
877
    {
878
        $this->router = Container::pull('route');
879
    }
880
881
    public function __debugInfo()
882
    {
883
        return [
884
            'name'    => $this->name,
885
            'rule'    => $this->rule,
886
            'route'   => $this->route,
887
            'method'  => $this->method,
888
            'vars'    => $this->vars,
889
            'option'  => $this->option,
890
            'pattern' => $this->pattern,
891
        ];
892
    }
893
}
894