|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakeCMS Core |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Core |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
|
12
|
|
|
* @link https://github.com/CakeCMS/Core". |
|
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Core; |
|
17
|
|
|
|
|
18
|
|
|
use Core\Core\Plugin; |
|
|
|
|
|
|
19
|
|
|
use Cake\Core\Configure; |
|
20
|
|
|
use Cake\Http\BaseApplication; |
|
21
|
|
|
use Core\View\Middleware\ThemeMiddleware; |
|
22
|
|
|
use Cake\Routing\Middleware\AssetMiddleware; |
|
23
|
|
|
use Cake\Routing\Middleware\RoutingMiddleware; |
|
24
|
|
|
use Cake\Error\Middleware\ErrorHandlerMiddleware; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class Application |
|
28
|
|
|
* |
|
29
|
|
|
* @package App |
|
30
|
|
|
*/ |
|
31
|
|
|
class Application extends BaseApplication |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
public function bootstrap() |
|
35
|
|
|
{ |
|
36
|
|
|
parent::bootstrap(); |
|
37
|
|
|
|
|
38
|
|
|
$this->addPlugin('Core', ['bootstrap' => true, 'routes' => true]); |
|
39
|
|
|
|
|
40
|
|
|
// Load all plugins. |
|
41
|
|
|
/*$plugins = [ |
|
42
|
|
|
'Search', |
|
43
|
|
|
'Config', |
|
44
|
|
|
'Community', |
|
45
|
|
|
'Migrations', |
|
46
|
|
|
'Extensions', |
|
47
|
|
|
Configure::read('Theme.site'), |
|
48
|
|
|
Configure::read('Theme.admin'), |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
foreach ($plugins as $name) { |
|
52
|
|
|
if (Plugin::isLoaded($name)) { |
|
53
|
|
|
continue; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ($path = Plugin::findPlugin($name)) { |
|
57
|
|
|
$this->addPlugin($name, Plugin::getConfigForLoad($path)); |
|
58
|
|
|
} |
|
59
|
|
|
}*/ |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Setup the middleware queue your application will use. |
|
64
|
|
|
* |
|
65
|
|
|
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup. |
|
66
|
|
|
* @return \Cake\Http\MiddlewareQueue The updated middleware queue. |
|
67
|
|
|
*/ |
|
68
|
|
|
public function middleware($middlewareQueue) |
|
69
|
|
|
{ |
|
70
|
|
|
$middlewareQueue |
|
71
|
|
|
|
|
72
|
|
|
/** Catch any exceptions in the lower layers, and make an error page/response */ |
|
73
|
|
|
->add(ErrorHandlerMiddleware::class) |
|
74
|
|
|
|
|
75
|
|
|
/** Handle plugin/theme assets like CakePHP normally does. */ |
|
76
|
|
|
->add(AssetMiddleware::class) |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Add routing middleware. |
|
80
|
|
|
* Routes collection cache enabled by default, to disable route caching pass null as cacheConfig, example: |
|
81
|
|
|
* `new RoutingMiddleware($this)` you might want to disable this cache in case your routing |
|
82
|
|
|
* is extremely simple. |
|
83
|
|
|
*/ |
|
84
|
|
|
->add(new RoutingMiddleware($this, '_cake_routes_')) |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Add theme middleware. |
|
88
|
|
|
* Setup request params 'theme'. Param hold current theme name. |
|
89
|
|
|
*/ |
|
90
|
|
|
->add(ThemeMiddleware::class); |
|
91
|
|
|
|
|
92
|
|
|
return $middlewareQueue; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param \Cake\Core\PluginInterface|string $name |
|
97
|
|
|
* @param array $config |
|
98
|
|
|
* @return $this |
|
99
|
|
|
*/ |
|
100
|
|
|
public function addPlugin($name, array $config = []) |
|
101
|
|
|
{ |
|
102
|
|
|
parent::addPlugin($name, $config); |
|
103
|
|
|
|
|
104
|
|
|
$plugin = (array) $name; |
|
105
|
|
|
|
|
106
|
|
|
foreach ($plugin as $_name) { |
|
107
|
|
|
if ((bool) Plugin::isLoaded($_name)) { |
|
108
|
|
|
Plugin::addManifestCallback($name); |
|
|
|
|
|
|
109
|
|
|
Cms::mergeConfig('App.paths.locales', Plugin::getLocalePath($name)); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: