]> src.bluestatic.org Git - isso.git/blob - Installer.php
Our test suite is now done with PHPUnit, although it's rather broken
[isso.git] / Installer.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Installer creator (Install.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * Installer
30 *
31 * Installer modules should extend this class. In the install module router,
32 * instantiate the right module. Methods beginning with step*() will be executed
33 * in numerical order.
34 *
35 * @author Blue Static
36 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
37 * @version $Revision$
38 * @package ISSO
39 *
40 */
41 abstract class BSInstaller
42 {
43 /**
44 * All the method steps
45 * @var array
46 */
47 private $steps = array();
48
49 /**
50 * The file name of this module
51 * @var string
52 */
53 protected $fileName;
54
55 /**
56 * Constructor: set up the steps
57 *
58 * @param string The file name for this module
59 */
60 public function __construct($fileName)
61 {
62 $this->fileName = $fileName;
63
64 BSRegister::RequiredModules(array('Input'));
65
66 $methods = get_class_methods($this);
67 foreach ($methods AS $name)
68 {
69 if (preg_match('#step([0-9]+)#', $name))
70 {
71 $this->steps[] = $name;
72 }
73 }
74 natsort($this->steps);
75
76 $this->_runStep(BSRegister::GetType('Input')->inputClean('step', TYPE_UINT));
77 }
78
79 // ###################################################################
80 /**
81 * An abstract method that needs to be overridden by a subclass that
82 * populates the page title
83 *
84 * @return string Returns the page title
85 */
86 protected abstract function _pageTitle();
87
88 // ###################################################################
89 /**
90 * Abstract method that will return link to the page after all the
91 * steps are completed. This needs to provide it's own <a>
92 *
93 * @return string Final page link
94 */
95 protected abstract function _finalLink();
96
97 // ###################################################################
98 /**
99 * Abstract method that prints out the first welcome screen that the
100 * user sees when no step has been selected
101 */
102 protected abstract function _welcomePage();
103
104 // ###################################################################
105 /**
106 * Prints out the page header... you really don't do this more than
107 * once
108 */
109 protected function _setUp()
110 {
111 ?>
112 <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
113 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
114 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
115 <head>
116 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
117 <title><?= $this->_pageTitle() ?></title>
118
119 <style type="text/css">
120 <!--
121 body
122 {
123 font-family: Verdana, Arial, Helvetica, sans-serif;
124 font-size: 12px;
125 }
126
127 body a
128 {
129 color: rgb(0, 0, 238);
130 }
131
132 h1
133 {
134 color: rgb(66, 137, 155);
135 }
136
137 .buttonlink
138 {
139 margin-top: 20px;
140 }
141
142 .buttonlink a
143 {
144 font-weight: bold;
145 padding: 5px;
146 border: 1px solid black;
147 text-decoration: none;
148 color: rgb(37, 37, 37);
149 background-color: rgb(239, 239, 239);
150 margin-top: 20px;
151 }
152 //-->
153 </style>
154 </head>
155 <body>
156
157 <?php
158 }
159
160 // ###################################################################
161 /**
162 * Runs the specific step method; if it does not exist, it will throw
163 * an error
164 *
165 * @param integer Step number
166 */
167 protected function _runStep($step)
168 {
169 if ($step == 0)
170 {
171 $this->_setUp();
172 $this->_welcomePage();
173 $this->_setDown(0);
174 }
175 else if (in_array("step$step", $this->steps))
176 {
177 $this->_setUp();
178 $this->{"step$step"}();
179 $this->_setDown($step);
180 }
181 else
182 {
183 trigger_error("step$step() does not exist in this module");
184 }
185 }
186
187 // ###################################################################
188 /**
189 * Prints out the footer part of the page, and the appropriate forwarding
190 * action button
191 *
192 * @param integer Step number
193 */
194 protected function _setDown($step)
195 {
196 // this is the last step, print the final button
197 if ($step == sizeof($this->steps))
198 {
199 echo '<div class="buttonlink">' . $this->_finalLink() . '</div>';
200 }
201 // just another step
202 else
203 {
204 echo '<div class="buttonlink"><a href="' . $this->fileName . '?step=' . ++$step . '">' . _('Next Step') . '</a></div>';
205 }
206
207 echo '
208 </body>
209
210 </html>';
211 }
212 }
213
214 /*=====================================================================*\
215 || ###################################################################
216 || # $HeadURL$
217 || # $Id$
218 || ###################################################################
219 \*=====================================================================*/
220 ?>