@@ -15,7 +15,7 @@ |
||
15 | 15 | |
16 | 16 | namespace Multidimensional\Subdomains\Routing; |
17 | 17 | |
18 | -use Cake\Network\Request; |
|
18 | +use Cake\Network\Request; |
|
19 | 19 | use Cake\Routing\Router; |
20 | 20 | use Cake\Core\Configure; |
21 | 21 |
@@ -22,23 +22,23 @@ |
||
22 | 22 | trait SubdomainRouteTrait |
23 | 23 | { |
24 | 24 | |
25 | - private function _getSubdomains() { |
|
25 | + private function _getSubdomains() { |
|
26 | 26 | |
27 | - $validConfiguration = Configure::check('Multidimensional/Subdomains.subdomains'); |
|
27 | + $validConfiguration = Configure::check('Multidimensional/Subdomains.subdomains'); |
|
28 | 28 | |
29 | - if (!$validConfiguration) { |
|
30 | - return []; |
|
31 | - } |
|
29 | + if (!$validConfiguration) { |
|
30 | + return []; |
|
31 | + } |
|
32 | 32 | |
33 | - $subdomains = Configure::read('Multidimensional/Subdomains.subdomains'); |
|
33 | + $subdomains = Configure::read('Multidimensional/Subdomains.subdomains'); |
|
34 | 34 | |
35 | - if (!is_array($subdomains) || count($subdomains) == 0) { |
|
36 | - return []; |
|
37 | - } |
|
35 | + if (!is_array($subdomains) || count($subdomains) == 0) { |
|
36 | + return []; |
|
37 | + } |
|
38 | 38 | |
39 | - return $subdomains; |
|
39 | + return $subdomains; |
|
40 | 40 | |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | 43 | private function _getPrefixAndHost(array $context = []) { |
44 | 44 | if (empty($context['_host'])) { |
@@ -19,8 +19,7 @@ |
||
19 | 19 | use Cake\Routing\Router; |
20 | 20 | use Cake\Core\Configure; |
21 | 21 | |
22 | -trait SubdomainRouteTrait |
|
23 | -{ |
|
22 | +trait SubdomainRouteTrait { |
|
24 | 23 | |
25 | 24 | private function _getSubdomains() { |
26 | 25 |
@@ -17,7 +17,6 @@ |
||
17 | 17 | |
18 | 18 | use Cake\Core\Configure; |
19 | 19 | use Cake\Console\Shell; |
20 | -use Cake\Console\Helper; |
|
21 | 20 | |
22 | 21 | class SubdomainsInstallShell extends Shell { |
23 | 22 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | } |
44 | 44 | |
45 | - if ((($first_run) ? (strtolower($this->in('Install Subdomains Plugin?', ['y','n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y','n'])) == 'y'))) { |
|
45 | + if ((($first_run) ? (strtolower($this->in('Install Subdomains Plugin?', ['y', 'n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y', 'n'])) == 'y'))) { |
|
46 | 46 | |
47 | 47 | do { |
48 | 48 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | $this->out(); |
62 | 62 | |
63 | - if (strtolower($this->in('Add Another Subdomain?', ['y','n'])) == 'n') { |
|
63 | + if (strtolower($this->in('Add Another Subdomain?', ['y', 'n'])) == 'n') { |
|
64 | 64 | $addMore = false; |
65 | 65 | } |
66 | 66 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | $subdomains[] = $subdomain; |
82 | 82 | $valid = true; |
83 | 83 | $this->out(); |
84 | - }else{ |
|
84 | + } else { |
|
85 | 85 | $valid = false; |
86 | 86 | $this->out(); |
87 | 87 | $this->_io->out('<error>Invalid Subdomain.</error>'); |
88 | 88 | } |
89 | 89 | |
90 | - } while (!$valid || strtolower($this->in('Add Another Subdomain?', ['y','n'])) == 'y'); |
|
90 | + } while (!$valid || strtolower($this->in('Add Another Subdomain?', ['y', 'n'])) == 'y'); |
|
91 | 91 | |
92 | 92 | } |
93 | 93 | |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | |
107 | 107 | $this->out(); |
108 | 108 | |
109 | - while (count($subdomains) > 0 && strtolower($this->in('Delete a Subdomain?', ['y','n'])) == 'y') { |
|
109 | + while (count($subdomains) > 0 && strtolower($this->in('Delete a Subdomain?', ['y', 'n'])) == 'y') { |
|
110 | 110 | |
111 | 111 | $this->out(); |
112 | 112 | $deleteKey = (int) $this->in('Enter Number to Delete:', array_keys($subdomains)); |
113 | 113 | |
114 | 114 | if (isset($subdomains[$deleteKey])) { |
115 | 115 | $this->out(); |
116 | - $this->out('Deleted: ' . $subdomains[$deleteKey], 2); |
|
116 | + $this->out('Deleted: ' . $subdomains[$deleteKey], 2); |
|
117 | 117 | unset($subdomains[$deleteKey]); |
118 | 118 | } |
119 | 119 | |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | $this->_io->out('<error>No Subdomains Configured.</error>', 2); |
128 | 128 | } |
129 | 129 | |
130 | - } while (count($subdomains) == 0 && strtolower($this->in('Start Over?', ['y','n'])) == 'y'); |
|
130 | + } while (count($subdomains) == 0 && strtolower($this->in('Start Over?', ['y', 'n'])) == 'y'); |
|
131 | 131 | |
132 | 132 | $this->out(); |
133 | - if(count($subdomains) > 0) { |
|
133 | + if (count($subdomains) > 0) { |
|
134 | 134 | $this->out('Configuration Saved!', 2); |
135 | 135 | } else { |
136 | 136 | $this->_io->out('<error>Plugin Not Currently Active.</error>', 2); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | private function _modifyArray(array $array) { |
143 | 143 | |
144 | - return array_combine(range(1, count($array)), array_values($array));; |
|
144 | + return array_combine(range(1, count($array)), array_values($array)); ; |
|
145 | 145 | |
146 | 146 | } |
147 | 147 |
@@ -81,7 +81,7 @@ |
||
81 | 81 | $subdomains[] = $subdomain; |
82 | 82 | $valid = true; |
83 | 83 | $this->out(); |
84 | - }else{ |
|
84 | + } else{ |
|
85 | 85 | $valid = false; |
86 | 86 | $this->out(); |
87 | 87 | $this->_io->out('<error>Invalid Subdomain.</error>'); |
@@ -21,129 +21,129 @@ |
||
21 | 21 | |
22 | 22 | class SubdomainsInstallShell extends Shell { |
23 | 23 | |
24 | - public function main() { |
|
24 | + public function main() { |
|
25 | 25 | |
26 | - $subdomains = array(); |
|
26 | + $subdomains = array(); |
|
27 | 27 | |
28 | - $this->clear(); |
|
28 | + $this->clear(); |
|
29 | 29 | |
30 | - $this->_io->styles('error', ['text' => 'red']); |
|
30 | + $this->_io->styles('error', ['text' => 'red']); |
|
31 | 31 | $this->helper('Multidimensional/Subdomains.Header')->output(); |
32 | 32 | |
33 | 33 | $first_run = Configure::check('Multidimensional/Subdomains.subdomains') ? false : true; |
34 | 34 | |
35 | - if ($first_run == false) { |
|
35 | + if ($first_run == false) { |
|
36 | 36 | |
37 | - $subdomains = Configure::consume('Multidimensional/Subdomains.subdomains'); |
|
37 | + $subdomains = Configure::consume('Multidimensional/Subdomains.subdomains'); |
|
38 | 38 | |
39 | - if (count($subdomains) == 0) { |
|
40 | - $first_run = true; |
|
41 | - } |
|
39 | + if (count($subdomains) == 0) { |
|
40 | + $first_run = true; |
|
41 | + } |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | if ((($first_run) ? (strtolower($this->in('Install Subdomains Plugin?', ['y','n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y','n'])) == 'y'))) { |
46 | 46 | |
47 | - do { |
|
47 | + do { |
|
48 | 48 | |
49 | - $this->out(); |
|
49 | + $this->out(); |
|
50 | 50 | |
51 | - $addMore = true; |
|
51 | + $addMore = true; |
|
52 | 52 | |
53 | - if ($first_run === false && count($subdomains) > 0) { |
|
53 | + if ($first_run === false && count($subdomains) > 0) { |
|
54 | 54 | |
55 | - $this->out('Current Subdomains:', 2); |
|
55 | + $this->out('Current Subdomains:', 2); |
|
56 | 56 | |
57 | - foreach ($subdomains AS $prefix) { |
|
58 | - $this->out(' - ' . $prefix); |
|
59 | - } |
|
57 | + foreach ($subdomains AS $prefix) { |
|
58 | + $this->out(' - ' . $prefix); |
|
59 | + } |
|
60 | 60 | |
61 | - $this->out(); |
|
61 | + $this->out(); |
|
62 | 62 | |
63 | - if (strtolower($this->in('Add Another Subdomain?', ['y','n'])) == 'n') { |
|
64 | - $addMore = false; |
|
65 | - } |
|
63 | + if (strtolower($this->in('Add Another Subdomain?', ['y','n'])) == 'n') { |
|
64 | + $addMore = false; |
|
65 | + } |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - if ($addMore) { |
|
69 | + if ($addMore) { |
|
70 | 70 | |
71 | - if (count($subdomains) == 0) { |
|
72 | - $this->out('Add Your First Subdomain.'); |
|
73 | - } |
|
71 | + if (count($subdomains) == 0) { |
|
72 | + $this->out('Add Your First Subdomain.'); |
|
73 | + } |
|
74 | 74 | |
75 | - do { |
|
75 | + do { |
|
76 | 76 | |
77 | - $valid = true; |
|
78 | - $this->out(); |
|
79 | - $subdomain = $this->in('Subdomain:'); |
|
80 | - if (preg_match('/^[A-Za-z0-9]{1}(?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9]{1})?$/', $subdomain, $matches)) { |
|
81 | - $subdomains[] = $subdomain; |
|
82 | - $valid = true; |
|
83 | - $this->out(); |
|
84 | - }else{ |
|
85 | - $valid = false; |
|
86 | - $this->out(); |
|
87 | - $this->_io->out('<error>Invalid Subdomain.</error>'); |
|
88 | - } |
|
77 | + $valid = true; |
|
78 | + $this->out(); |
|
79 | + $subdomain = $this->in('Subdomain:'); |
|
80 | + if (preg_match('/^[A-Za-z0-9]{1}(?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9]{1})?$/', $subdomain, $matches)) { |
|
81 | + $subdomains[] = $subdomain; |
|
82 | + $valid = true; |
|
83 | + $this->out(); |
|
84 | + }else{ |
|
85 | + $valid = false; |
|
86 | + $this->out(); |
|
87 | + $this->_io->out('<error>Invalid Subdomain.</error>'); |
|
88 | + } |
|
89 | 89 | |
90 | - } while (!$valid || strtolower($this->in('Add Another Subdomain?', ['y','n'])) == 'y'); |
|
90 | + } while (!$valid || strtolower($this->in('Add Another Subdomain?', ['y','n'])) == 'y'); |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - $subdomains = array_values(array_unique($subdomains)); |
|
94 | + $subdomains = array_values(array_unique($subdomains)); |
|
95 | 95 | |
96 | - $subdomains = $this->_modifyArray($subdomains); |
|
96 | + $subdomains = $this->_modifyArray($subdomains); |
|
97 | 97 | |
98 | - $this->out(); |
|
99 | - $this->out('Current Subdomains:', 2); |
|
98 | + $this->out(); |
|
99 | + $this->out('Current Subdomains:', 2); |
|
100 | 100 | |
101 | - if (count($subdomains) > 0) { |
|
102 | - foreach ($subdomains AS $key => $value) { |
|
103 | - $this->out(' ' . ($key) . '. ' . $value); |
|
104 | - } |
|
105 | - } |
|
101 | + if (count($subdomains) > 0) { |
|
102 | + foreach ($subdomains AS $key => $value) { |
|
103 | + $this->out(' ' . ($key) . '. ' . $value); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | - $this->out(); |
|
107 | + $this->out(); |
|
108 | 108 | |
109 | - while (count($subdomains) > 0 && strtolower($this->in('Delete a Subdomain?', ['y','n'])) == 'y') { |
|
109 | + while (count($subdomains) > 0 && strtolower($this->in('Delete a Subdomain?', ['y','n'])) == 'y') { |
|
110 | 110 | |
111 | - $this->out(); |
|
112 | - $deleteKey = (int) $this->in('Enter Number to Delete:', array_keys($subdomains)); |
|
111 | + $this->out(); |
|
112 | + $deleteKey = (int) $this->in('Enter Number to Delete:', array_keys($subdomains)); |
|
113 | 113 | |
114 | - if (isset($subdomains[$deleteKey])) { |
|
115 | - $this->out(); |
|
116 | - $this->out('Deleted: ' . $subdomains[$deleteKey], 2); |
|
117 | - unset($subdomains[$deleteKey]); |
|
118 | - } |
|
114 | + if (isset($subdomains[$deleteKey])) { |
|
115 | + $this->out(); |
|
116 | + $this->out('Deleted: ' . $subdomains[$deleteKey], 2); |
|
117 | + unset($subdomains[$deleteKey]); |
|
118 | + } |
|
119 | 119 | |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | - Configure::write('Multidimensional/Subdomains.subdomains', array_values($subdomains)); |
|
123 | - Configure::dump('subdomains', 'default', ['Multidimensional/Subdomains']); |
|
122 | + Configure::write('Multidimensional/Subdomains.subdomains', array_values($subdomains)); |
|
123 | + Configure::dump('subdomains', 'default', ['Multidimensional/Subdomains']); |
|
124 | 124 | |
125 | - if (count($subdomains) == 0) { |
|
126 | - $this->out(); |
|
127 | - $this->_io->out('<error>No Subdomains Configured.</error>', 2); |
|
128 | - } |
|
125 | + if (count($subdomains) == 0) { |
|
126 | + $this->out(); |
|
127 | + $this->_io->out('<error>No Subdomains Configured.</error>', 2); |
|
128 | + } |
|
129 | 129 | |
130 | - } while (count($subdomains) == 0 && strtolower($this->in('Start Over?', ['y','n'])) == 'y'); |
|
130 | + } while (count($subdomains) == 0 && strtolower($this->in('Start Over?', ['y','n'])) == 'y'); |
|
131 | 131 | |
132 | - $this->out(); |
|
133 | - if(count($subdomains) > 0) { |
|
134 | - $this->out('Configuration Saved!', 2); |
|
135 | - } else { |
|
136 | - $this->_io->out('<error>Plugin Not Currently Active.</error>', 2); |
|
137 | - } |
|
138 | - } |
|
132 | + $this->out(); |
|
133 | + if(count($subdomains) > 0) { |
|
134 | + $this->out('Configuration Saved!', 2); |
|
135 | + } else { |
|
136 | + $this->_io->out('<error>Plugin Not Currently Active.</error>', 2); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - private function _modifyArray(array $array) { |
|
142 | + private function _modifyArray(array $array) { |
|
143 | 143 | |
144 | - return array_combine(range(1, count($array)), array_values($array));; |
|
144 | + return array_combine(range(1, count($array)), array_values($array));; |
|
145 | 145 | |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | 148 | |
149 | 149 | } |
150 | 150 | \ No newline at end of file |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * If you don't have this file, copy it to your main CakePHP config folder. |
23 | 23 | /*/ |
24 | 24 | |
25 | -return array ( |
|
25 | +return array( |
|
26 | 26 | 'Multidimensional/Subdomains' => |
27 | 27 | array('subdomains' => |
28 | 28 | array('{SUBDOMAIN_1}', '{SUBDOMAIN_2}', ... '{SUBDOMAIN_N}') |
@@ -23,8 +23,8 @@ |
||
23 | 23 | /*/ |
24 | 24 | |
25 | 25 | return array ( |
26 | - 'Multidimensional/Subdomains' => |
|
26 | + 'Multidimensional/Subdomains' => |
|
27 | 27 | array('subdomains' => |
28 | - array('{SUBDOMAIN_1}', '{SUBDOMAIN_2}', ... '{SUBDOMAIN_N}') |
|
29 | - ) |
|
28 | + array('{SUBDOMAIN_1}', '{SUBDOMAIN_2}', ... '{SUBDOMAIN_N}') |
|
29 | + ) |
|
30 | 30 | ); |
31 | 31 | \ No newline at end of file |
@@ -24,7 +24,7 @@ |
||
24 | 24 | |
25 | 25 | $subdomains = Configure::read('Multidimensional/Subdomains.subdomains'); |
26 | 26 | |
27 | - if(is_array($subdomains)) { |
|
27 | + if (is_array($subdomains)) { |
|
28 | 28 | |
29 | 29 | foreach ($subdomains AS $prefix) { |
30 | 30 |
@@ -22,18 +22,18 @@ |
||
22 | 22 | |
23 | 23 | if ($validConfiguration) { |
24 | 24 | |
25 | - $subdomains = Configure::read('Multidimensional/Subdomains.subdomains'); |
|
25 | + $subdomains = Configure::read('Multidimensional/Subdomains.subdomains'); |
|
26 | 26 | |
27 | - if(is_array($subdomains)) { |
|
27 | + if(is_array($subdomains)) { |
|
28 | 28 | |
29 | - foreach ($subdomains AS $prefix) { |
|
29 | + foreach ($subdomains AS $prefix) { |
|
30 | 30 | |
31 | - Router::scope('/', ['prefix' => $prefix], function($routes) { |
|
32 | - $routes->fallbacks('InflectedRoute'); |
|
33 | - }); |
|
31 | + Router::scope('/', ['prefix' => $prefix], function($routes) { |
|
32 | + $routes->fallbacks('InflectedRoute'); |
|
33 | + }); |
|
34 | 34 | |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - } |
|
37 | + } |
|
38 | 38 | |
39 | - } |
|
40 | 39 | \ No newline at end of file |
40 | + } |
|
41 | 41 | \ No newline at end of file |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | foreach ($subdomains AS $prefix) { |
30 | 30 | |
31 | - Router::scope('/', ['prefix' => $prefix], function($routes) { |
|
31 | + Router::scope('/', ['prefix' => $prefix], function($routes) { |
|
32 | 32 | $routes->fallbacks('InflectedRoute'); |
33 | 33 | }); |
34 | 34 |
@@ -25,9 +25,9 @@ |
||
25 | 25 | $subdomainConfig = array('subdomains' => NULL); |
26 | 26 | |
27 | 27 | if (file_exists(CONFIG . 'subdomains.php')) { |
28 | - Configure::load('subdomains'); |
|
28 | + Configure::load('subdomains'); |
|
29 | 29 | } else { |
30 | - Configure::write('Multidimensional/Subdomains', $subdomainConfig); |
|
30 | + Configure::write('Multidimensional/Subdomains', $subdomainConfig); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | ?> |
34 | 34 | \ No newline at end of file |
@@ -18,7 +18,6 @@ |
||
18 | 18 | use Cake\Routing\Route\DashedRoute as CakeDashedRoute; |
19 | 19 | use Multidimensional\Subdomains\Routing\SubdomainRouteTrait; |
20 | 20 | |
21 | -class DashedRoute extends CakeDashedRoute |
|
22 | -{ |
|
21 | +class DashedRoute extends CakeDashedRoute { |
|
23 | 22 | use SubdomainRouteTrait; |
24 | 23 | } |
25 | 24 | \ No newline at end of file |
@@ -18,7 +18,6 @@ |
||
18 | 18 | use Cake\Routing\Route\Route as CakeRoute; |
19 | 19 | use Multidimensional\Subdomains\Routing\SubdomainRouteTrait; |
20 | 20 | |
21 | -class Route extends CakeRoute |
|
22 | -{ |
|
21 | +class Route extends CakeRoute { |
|
23 | 22 | use SubdomainRouteTrait; |
24 | 23 | } |
25 | 24 | \ No newline at end of file |
@@ -18,7 +18,6 @@ |
||
18 | 18 | use Cake\Routing\Route\InflectedRoute as CakeInflectedRoute; |
19 | 19 | use Multidimensional\Subdomains\Routing\SubdomainRouteTrait; |
20 | 20 | |
21 | -class InflectedRoute extends CakeInflectedRoute |
|
22 | -{ |
|
21 | +class InflectedRoute extends CakeInflectedRoute { |
|
23 | 22 | use SubdomainRouteTrait; |
24 | 23 | } |
25 | 24 | \ No newline at end of file |
@@ -25,9 +25,9 @@ |
||
25 | 25 | $this->_io->styles('header', ['text' => 'green']); |
26 | 26 | |
27 | 27 | $this->_io->out('<header> ______ _____ ___ ____ __ ______ _____ ______</header>'); |
28 | - $this->_io->out('<header> / __/ / / / _ )/ _ \/ __ \/ |/ / _ | / _/ |/ / __/</header>'); |
|
29 | - $this->_io->out('<header> _\ \/ /_/ / _ / // / /_/ / /|_/ / __ |_/ // /\ \ </header>'); |
|
30 | - $this->_io->out('<header>/___/\____/____/____/\____/_/ /_/_/ |_/___/_/|_/___/ </header>'); |
|
28 | + $this->_io->out('<header> / __/ / / / _ )/ _ \/ __ \/ |/ / _ | / _/ |/ / __/</header>'); |
|
29 | + $this->_io->out('<header> _\ \/ /_/ / _ / // / /_/ / /|_/ / __ |_/ // /\ \ </header>'); |
|
30 | + $this->_io->out('<header>/___/\____/____/____/\____/_/ /_/_/ |_/___/_/|_/___/ </header>'); |
|
31 | 31 | $this->_io->out("\n"); |
32 | 32 | $this->_io->out('<header> CakePHP : Subdomains Router </header>'); |
33 | 33 | $this->_io->out('<header> by https://multidimension.al </header>'); |
@@ -17,10 +17,8 @@ |
||
17 | 17 | |
18 | 18 | use Cake\Console\Helper; |
19 | 19 | |
20 | -class HeaderHelper extends Helper |
|
21 | -{ |
|
22 | - public function output($args = null) |
|
23 | - { |
|
20 | +class HeaderHelper extends Helper { |
|
21 | + public function output($args = null) { |
|
24 | 22 | $this->_io->out("\n\n"); |
25 | 23 | $this->_io->styles('header', ['text' => 'green']); |
26 | 24 |