]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - config/Tools.php
Initial work for classes to hold configuration constants/variables. Base
[SourceForge/phpwiki.git] / config / Tools.php
1 <?php\r
2 rcs_id('$Id: Tools.php,v 1.1 2003-01-23 00:32:04 zorloc Exp $')\r
3 /*\r
4  Copyright 2002 $ThePhpWikiProgrammingTeam\r
5 \r
6  This file is part of PhpWiki.\r
7 \r
8  PhpWiki is free software; you can redistribute it and/or modify\r
9  it under the terms of the GNU General Public License as published by\r
10  the Free Software Foundation; either version 2 of the License, or\r
11  (at your option) any later version.\r
12 \r
13  PhpWiki is distributed in the hope that it will be useful,\r
14  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  GNU General Public License for more details.\r
17 \r
18  You should have received a copy of the GNU General Public License\r
19  along with PhpWiki; if not, write to the Free Software\r
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
21  */\r
22 \r
23 \r
24 /**\r
25  * ConfigValue\r
26  * \r
27  *\r
28  */\r
29 class ConfigValue {\r
30     var $name;\r
31     var $currentValue;\r
32     var $defaultValue;\r
33     var $description;\r
34     var $validator;\r
35     \r
36     function ConfigValue($params){\r
37         $this->name = $params['name'];\r
38         $this->defaultValue = $params['defaultValue'];\r
39         $this->description = $params['description'];\r
40         $this->validator = &$params['validator'];\r
41         $this->currentValue = $this->getStarting();\r
42     }\r
43 \r
44     function valid($value){\r
45         if ($this->validator->validate($value)) {\r
46             return true;\r
47         }\r
48         trigger_error("Value for " . $this->name . "is invalid", E_USER_WARNING);\r
49         return false;\r
50     }\r
51     \r
52     function getStarting(){\r
53         return $this->defaultValue;\r
54     }\r
55     \r
56     function getCurrent(){\r
57         return $this->currentValue;\r
58     }\r
59     \r
60     function setCurrent($value){\r
61         if ($this->valid($value)) {\r
62             $this->currentValue = $value;\r
63         }\r
64     }\r
65     \r
66     function getName(){\r
67         return $this->name;\r
68     }\r
69     \r
70     function getDefaultValue(){\r
71         return $this->defaultValue;\r
72     }\r
73     \r
74     function getShortDescription(){\r
75         return $this->description['short'];\r
76     }\r
77 \r
78     function getFullDescription(){\r
79         return $this->description['full'];\r
80     }\r
81 }\r
82 \r
83 /**\r
84\r
85 */\r
86 class ConfigConstant extends ConfigValue {\r
87 \r
88     function getStarting(){\r
89         if (defined($this->name)) {\r
90             $starting = constant($this->name);\r
91             if ($this->valid($starting)) {\r
92                 return $starting;\r
93             }\r
94         }\r
95         return $this->defaultValue;\r
96     }\r
97 }\r
98 \r
99 /**\r
100\r
101 */\r
102 class ConfigVariable extends ConfigValue {\r
103 \r
104     function getStarting(){\r
105         if (isset(${$this->name})) {\r
106             $starting = ${$this->name};\r
107             if ($this->valid($starting)) {\r
108                 return $starting;\r
109             }\r
110         }\r
111         return $this->defaultValue;\r
112     }\r
113 }\r
114 \r
115 //$Log: not supported by cvs2svn $\r
116 \r
117 // Local Variables:\r
118 // mode: php\r
119 // tab-width: 8\r
120 // c-basic-offset: 4\r
121 // c-hanging-comment-ender-p: nil\r
122 // indent-tabs-mode: nil\r
123 // End:\r
124 ?>