1 | <?php |
||
24 | class MultiDomainsManager extends \yii\base\Component |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * @var string the base domain. |
||
29 | */ |
||
30 | public $baseDomain = ''; |
||
31 | |||
32 | /** |
||
33 | * <Sub Domain Name> => [ |
||
34 | * 'component' => <URL Manager Component Configuration Array>, |
||
35 | * 'schema' => 'http'(default) or 'https', |
||
36 | * ] |
||
37 | * For example: |
||
38 | * ```php |
||
39 | * $baseDomain = 'example.com'; |
||
40 | * $subDomains = [ |
||
41 | * '' => [ |
||
42 | * 'component' => [ |
||
43 | * // `class` could be ignored as it is `vistart\Models\components\MultiDomainsUrlManager`. |
||
44 | * 'class' => 'yii\web\UrlManager', |
||
45 | * 'enablePrettyUrl' => true, |
||
46 | * 'showScriptName' => false, |
||
47 | * 'suffix' => '.html', |
||
48 | * // the other properties... |
||
49 | * ], |
||
50 | * 'schema' => 'http', // `schema` could be ignored as it is 'http'. |
||
51 | * ], |
||
52 | * 'my' => [ |
||
53 | * 'component' => [ |
||
54 | * 'enablePrettyUrl' => true, |
||
55 | * 'showScriptName' => false, |
||
56 | * 'suffix' => '.html', |
||
57 | * 'rules' => [ |
||
58 | * 'posts/<year:\d{4}>/<category>' => 'post/index', |
||
59 | * 'posts' => 'post/index', |
||
60 | * 'post/<id:\d+>' => 'post/view', |
||
61 | * ], |
||
62 | * ], |
||
63 | * 'schema' => 'https', |
||
64 | * ], |
||
65 | * 'sso' => [ |
||
66 | * 'component' => [ |
||
67 | * 'enablePrettyUrl' => true, |
||
68 | * 'showScriptName' => false, |
||
69 | * 'rules' => [ |
||
70 | * '' => 'sso/login', |
||
71 | * 'logout' => 'sso/logout', |
||
72 | * ], |
||
73 | * ], |
||
74 | * 'schema' => 'https', |
||
75 | * ], |
||
76 | * ]; |
||
77 | * ``` |
||
78 | * and you can configure the `config/web.php` (basic template) or `config/main.php` (advanced template) |
||
79 | * `components` section to add an element named `multiDomainsManager`: |
||
80 | * ```php |
||
81 | * $config = [ |
||
82 | * ... |
||
83 | * 'components' => [ |
||
84 | * ... |
||
85 | * 'multiDomainsManager' => [ |
||
86 | * 'baseDomain' => 'example.com', |
||
87 | * 'subDomains' => [ |
||
88 | * 'my' => [ |
||
89 | * 'component' => require(<the path of 'my' web application UrlManager config file>), |
||
90 | * ], |
||
91 | * ... |
||
92 | * ], |
||
93 | * ], |
||
94 | * ... |
||
95 | * ], |
||
96 | * ]; |
||
97 | * ``` |
||
98 | * @var array array of sub-domains. |
||
99 | */ |
||
100 | public $subDomains = []; |
||
101 | |||
102 | /** |
||
103 | * @var string Current sub-domain name. If current sub-domain does not exist |
||
104 | * in `$this->subDomains`, return `Yii::$app->urlManager` instead. |
||
105 | */ |
||
106 | public $currentDomain = ''; |
||
107 | |||
108 | /** |
||
109 | * Get UrlManager component of specified sub-domain application. |
||
110 | * @param string $subdomain |
||
111 | * @return \yii\web\UrlManager |
||
112 | */ |
||
113 | 2 | public function get($subdomain = '') |
|
136 | |||
137 | /** |
||
138 | * Get URL Manager of current domain web application. |
||
139 | * @return \yii\web\UrlManager |
||
140 | */ |
||
141 | 1 | public function getCurrent() |
|
145 | } |
||
146 |