1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpha\Controller; |
4
|
|
|
|
5
|
|
|
use Alpha\Util\Logging\Logger; |
6
|
|
|
use Alpha\Util\Config\ConfigProvider; |
7
|
|
|
use Alpha\Util\Http\Request; |
8
|
|
|
use Alpha\Util\Http\Response; |
9
|
|
|
use Alpha\View\View; |
10
|
|
|
use Alpha\Model\ActiveRecord; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Standard index controller for the application. Override the index.phtml template to build your |
14
|
|
|
* own home page for your application. |
15
|
|
|
* |
16
|
|
|
* @since 2.0 |
17
|
|
|
* |
18
|
|
|
* @author John Collins <[email protected]> |
19
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License |
20
|
|
|
* @copyright Copyright (c) 2018, John Collins (founder of Alpha Framework). |
21
|
|
|
* All rights reserved. |
22
|
|
|
* |
23
|
|
|
* <pre> |
24
|
|
|
* Redistribution and use in source and binary forms, with or |
25
|
|
|
* without modification, are permitted provided that the |
26
|
|
|
* following conditions are met: |
27
|
|
|
* |
28
|
|
|
* * Redistributions of source code must retain the above |
29
|
|
|
* copyright notice, this list of conditions and the |
30
|
|
|
* following disclaimer. |
31
|
|
|
* * Redistributions in binary form must reproduce the above |
32
|
|
|
* copyright notice, this list of conditions and the |
33
|
|
|
* following disclaimer in the documentation and/or other |
34
|
|
|
* materials provided with the distribution. |
35
|
|
|
* * Neither the name of the Alpha Framework nor the names |
36
|
|
|
* of its contributors may be used to endorse or promote |
37
|
|
|
* products derived from this software without specific |
38
|
|
|
* prior written permission. |
39
|
|
|
* |
40
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
41
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
42
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
43
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
44
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
45
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
46
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
47
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
48
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
49
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
50
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
51
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
52
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
53
|
|
|
* </pre> |
54
|
|
|
*/ |
55
|
|
|
class IndexController extends Controller implements ControllerInterface |
56
|
|
|
{ |
57
|
|
|
/** |
58
|
|
|
* Trace logger. |
59
|
|
|
* |
60
|
|
|
* @var \Alpha\Util\Logging\Logger |
61
|
|
|
* |
62
|
|
|
* @since 1.0 |
63
|
|
|
*/ |
64
|
|
|
private static $logger = null; |
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* constructor to set up the object. |
68
|
|
|
* |
69
|
|
|
* @param string $visibility The name of the rights group that can access this controller. |
70
|
|
|
* |
71
|
|
|
* @since 1.0 |
72
|
|
|
*/ |
73
|
|
|
public function __construct($visibility = 'Public') |
74
|
|
|
{ |
75
|
|
|
self::$logger = new Logger('IndexController'); |
76
|
|
|
self::$logger->debug('>>__construct()'); |
77
|
|
|
|
78
|
|
|
// ensure that the super class constructor is called, indicating the rights group |
79
|
|
|
parent::__construct($visibility); |
80
|
|
|
|
81
|
|
|
self::$logger->debug('<<__construct'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Handle GET requests. |
86
|
|
|
* |
87
|
|
|
* @param \Alpha\Util\Http\Request $request |
88
|
|
|
* |
89
|
|
|
* @return \Alpha\Util\Http\Response |
90
|
|
|
* |
91
|
|
|
* @since 1.0 |
92
|
|
|
*/ |
93
|
|
|
public function doGET($request) |
94
|
|
|
{ |
95
|
|
|
self::$logger->debug('>>doGET(request=['.var_export($request, true).'])'); |
96
|
|
|
|
97
|
|
|
$config = ConfigProvider::getInstance(); |
98
|
|
|
|
99
|
|
|
if ($config->get('app.check.installed') && !ActiveRecord::isInstalled()) { |
100
|
|
|
$response = new Response(301); |
101
|
|
|
$response->redirect($config->get('app.url').'/install'); |
102
|
|
|
|
103
|
|
|
self::$logger->warn('App not installed so re-directing to the install controller'); |
104
|
|
|
self::$logger->debug('<<doGET'); |
105
|
|
|
|
106
|
|
|
return $response; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$body = View::loadTemplateFragment('html', 'head.phtml', array('title' => $config->get('app.title'), 'description' => 'Welcome to our site', 'allowCSSOverrides' => true)); |
110
|
|
|
$body .= View::loadTemplateFragment('html', 'index.phtml'); |
111
|
|
|
$body .= View::loadTemplateFragment('html', 'footer.phtml'); |
112
|
|
|
|
113
|
|
|
self::$logger->debug('<<doGET'); |
114
|
|
|
|
115
|
|
|
return new Response(200, $body, array('Content-Type' => 'text/html')); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|