Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
61 | abstract class View extends Fwolflib { |
||
|
|||
62 | |||
63 | /** |
||
64 | * Action parameter, the view command to determin what to display |
||
65 | * @var string // $_GET['a'], means which action user prefered of the module |
||
66 | */ |
||
67 | protected $sAction = null; |
||
68 | |||
69 | /** |
||
70 | * Ajax select div object |
||
71 | * @var object |
||
72 | */ |
||
73 | public $oAjaxSelDiv = null; |
||
74 | |||
75 | /** |
||
76 | * Cache object |
||
77 | * @var object |
||
78 | */ |
||
79 | public $oCache = NULL; |
||
80 | |||
81 | /** |
||
82 | * If cache turned on |
||
83 | * Remember to set cache config before turned it on. |
||
84 | * @var boolean |
||
85 | */ |
||
86 | public $bCacheOn = false; |
||
87 | |||
88 | /** |
||
89 | * Css file url used in header |
||
90 | * eg: array(array(0 => 'default.css', 1 => 'screen, print'), ...) |
||
91 | * @var array of array |
||
92 | */ |
||
93 | public $aCss = array(); |
||
94 | |||
95 | /** |
||
96 | * View's caller -- Controler object |
||
97 | * @var object |
||
98 | */ |
||
99 | public $oCtl = null; |
||
100 | |||
101 | /** |
||
102 | * Form object, auto new when first used. |
||
103 | * @var object |
||
104 | */ |
||
105 | public $oForm = null; |
||
106 | |||
107 | /** |
||
108 | * Js file url used in header |
||
109 | * eg: 'common.js', ..., Can index by string. |
||
110 | * @var array of string |
||
111 | */ |
||
112 | public $aJs = array(); |
||
113 | |||
114 | /** |
||
115 | * ListTable object, auto new when first used. |
||
116 | * @var object |
||
117 | */ |
||
118 | public $oLt = null; |
||
119 | |||
120 | /** |
||
121 | * Output content generated |
||
122 | * @var string |
||
123 | */ |
||
124 | public $sOutput = ''; |
||
125 | |||
126 | /** |
||
127 | * Main content part of output content, normail is page main content |
||
128 | * @var string |
||
129 | */ |
||
130 | protected $sOutputContent = ''; |
||
131 | |||
132 | /** |
||
133 | * Footer part of output content |
||
134 | * |
||
135 | * In common, this will include some end part of <body> and etc. |
||
136 | * @var string |
||
137 | */ |
||
138 | protected $sOutputFooter = ''; |
||
139 | |||
140 | /** |
||
141 | * Header part of output content, normally is html header part |
||
142 | * |
||
143 | * In common, this will include all <html> and some beginner part of <body> |
||
144 | * @var string |
||
145 | */ |
||
146 | protected $sOutputHeader = ''; |
||
147 | |||
148 | /** |
||
149 | * Menu part of output content, optional |
||
150 | * @var string |
||
151 | */ |
||
152 | protected $sOutputMenu = ''; |
||
153 | |||
154 | /** |
||
155 | * If use tidy to format output html code, default false. |
||
156 | * @var boolean |
||
157 | */ |
||
158 | public $bOutputTidy = false; |
||
159 | |||
160 | /** |
||
161 | * If show debug info on footer ? |
||
162 | * @var boolean |
||
163 | */ |
||
164 | public $bShowDebugInfo = false; |
||
165 | |||
166 | /** |
||
167 | * Template object, auto new when first used. |
||
168 | * @var object |
||
169 | */ |
||
170 | public $oTpl = null; |
||
171 | |||
172 | /** |
||
173 | * Template file path |
||
174 | * @var array |
||
175 | */ |
||
176 | protected $aTplFile = array( |
||
177 | 'footer' => 'footer.tpl', |
||
178 | 'header' => 'header.tpl', |
||
179 | 'menu' => 'menu.tpl', |
||
180 | ); |
||
181 | |||
182 | /** |
||
183 | * Validator object. |
||
184 | * @var object |
||
185 | */ |
||
186 | public $oValidator = null; |
||
187 | |||
188 | /** |
||
189 | * Html <title> of this view |
||
190 | * @var string |
||
191 | */ |
||
192 | protected $sViewTitle = ''; |
||
193 | |||
194 | |||
195 | // New Tpl object |
||
196 | abstract protected function NewObjTpl(); |
||
197 | |||
198 | |||
199 | /* |
||
200 | // Changed to define directly in this class (below), |
||
201 | // sub class only need to set tpl file name or do some other action. |
||
202 | abstract public function GenFooter(); |
||
203 | abstract public function GenHeader(); |
||
204 | abstract public function GenMenu(); |
||
205 | */ |
||
206 | |||
207 | // An template is given, point to action-relate method, |
||
208 | // and will check method exists at first. |
||
209 | //abstract protected function GenContent(); |
||
210 | |||
211 | |||
212 | /** |
||
213 | * construct |
||
214 | * @param object &$ctl Caller controler object |
||
215 | */ |
||
216 | public function __construct (&$ctl) { |
||
243 | |||
244 | |||
245 | /** |
||
246 | * Auto new obj if not set, for some special var only |
||
247 | * |
||
248 | * @param string $name |
||
249 | * @return object |
||
250 | */ |
||
251 | View Code Duplication | public function __get($name) |
|
264 | |||
265 | |||
266 | /** |
||
267 | * Get content to output with cache |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | public function CacheGetOutput() { |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Gen key of cache by request uri |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | public function CacheKey() { |
||
314 | |||
315 | |||
316 | /** |
||
317 | * Got cache lifetime, by second |
||
318 | * Should often re-define in sub class. |
||
319 | * |
||
320 | * @param string $key |
||
321 | * @return int |
||
322 | */ |
||
323 | public function CacheLifetime ($key = '') { |
||
330 | |||
331 | |||
332 | /** |
||
333 | * Generate main content of page |
||
334 | * |
||
335 | * Doing this by call sub-method according to $sAction, |
||
336 | * Also, this can be override by extended class. |
||
337 | */ |
||
338 | public function GenContent() { |
||
368 | |||
369 | |||
370 | /** |
||
371 | * Generate footer part |
||
372 | */ |
||
373 | public function GenFooter() { |
||
385 | |||
386 | |||
387 | /** |
||
388 | * Generate header part |
||
389 | * |
||
390 | * @see $aCss, $aJs |
||
391 | */ |
||
392 | public function GenHeader () { |
||
401 | |||
402 | |||
403 | /** |
||
404 | * Generate menu part |
||
405 | */ |
||
406 | public function GenMenu() |
||
411 | |||
412 | |||
413 | /** |
||
414 | * Get content to output |
||
415 | * |
||
416 | * @return string |
||
417 | * @see $sOutput |
||
418 | */ |
||
419 | public function GetOutput () { |
||
439 | |||
440 | |||
441 | /** |
||
442 | * New AjaxSelectDiv object |
||
443 | * |
||
444 | * @see $oAjaxSelectDiv |
||
445 | */ |
||
446 | protected function NewObjAjaxSelDiv() { |
||
449 | |||
450 | |||
451 | /** |
||
452 | * New Cache object |
||
453 | * |
||
454 | * Need replace by sub class, assign cache type |
||
455 | * |
||
456 | * @see $oCache |
||
457 | */ |
||
458 | protected function NewObjCache () { |
||
461 | |||
462 | |||
463 | /** |
||
464 | * New Form object |
||
465 | * |
||
466 | * @see $oForm |
||
467 | */ |
||
468 | protected function NewObjForm() { |
||
471 | |||
472 | |||
473 | /** |
||
474 | * New ListTable object |
||
475 | * |
||
476 | * @see $oLt |
||
477 | */ |
||
478 | protected function NewObjLt() { |
||
481 | |||
482 | |||
483 | /** |
||
484 | * New Validator object |
||
485 | * |
||
486 | * @see $oValidator |
||
487 | * @return object |
||
488 | */ |
||
489 | protected function NewObjValidator () { |
||
492 | |||
493 | |||
494 | /** |
||
495 | * Set <title> of view page |
||
496 | * @param string $title |
||
497 | */ |
||
498 | public function SetViewTitle($title) |
||
506 | |||
507 | |||
508 | /** |
||
509 | * Use tidy to format html string |
||
510 | * |
||
511 | * @param string &$html |
||
512 | * @return string |
||
513 | */ |
||
514 | View Code Duplication | public function Tidy (&$html) { |
|
535 | |||
536 | } // end of class View |
||
537 | ?> |
||
538 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.