wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.WCMFInifileParser.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.WCMFInifileParser.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/util/class.InifileParser.php");
20 require_once(BASE."wcmf/lib/util/class.FileUtil.php");
21 
22 /**
23  * @class WCMFInifileParser
24  * @ingroup Presentation
25  * @brief WCMFInifileParser adds methods for wcmf specific inifiles.
26  * This class is a decorator to the InifileParser class, showing only the
27  * readonly methods of InifileParser in it's interface.
28  * The advantage in using the InifileParser singleton inside
29  * this class is that its instance will hold the same configuration
30  * data as the WCMFInifileParser instance does.@n
31  * For this reason other classes may use the InifileParser instance
32  * not knowing about the WCMFInifileParser class at all.
33  *
34  * @author ingo herwig <ingo@wemove.com>
35  */
37 {
38  var $_actionDelimiter = '?';
39 
40  /**
41  * Returns an instance of the class.
42  * @return A reference to the only instance of the Singleton object
43  */
44  function &getInstance()
45  {
46  static $instance = null;
47 
48  if (!isset($instance))
49  {
50  $instance = new WCMFInifileParser();
51  // assign instance to InifileParser instance
52  $baseInstance = &InifileParser::getInstance();
53  $baseInstance = &$instance;
54  }
55 
56  return $instance;
57  }
58  /**
59  * Get a list of available configuration files.
60  * @return Array of configuration file names.
61  * @note static method
62  * The method relies on the following globally defined variables
63  * - CONFIG_PATH: the path of the configuration files
64  * - CONFIG_EXTENSION: the extension of configuration files (e.g. 'ini')
65  */
66  function getIniFiles()
67  {
68  global $CONFIG_PATH, $CONFIG_EXTENSION;
69  $fileUtil = new FileUtil();
70  return $fileUtil->getFiles($CONFIG_PATH, "/\.".$CONFIG_EXTENSION."$/", true);
71  }
72  /**
73  * Get an ini file key that matches a given combination of resource, context, action best.
74  * @param section The section to search in.
75  * @param resource The given resource.
76  * @param context The given context.
77  * @param action The given action.
78  * @return The best matching key or an empty string if nothing matches.
79  */
80  function getBestActionKey($section, $resource, $context, $action)
81  {
82  $parser = &InifileParser::getInstance();
83  // check resource?context?action
84  if (strlen($resource) > 0 && strlen($context) > 0 && strlen($action) > 0)
85  {
86  $key = $resource.$this->_actionDelimiter.$context.$this->_actionDelimiter.$action;
87  if ($parser->getValue($key, $section, false) !== false)
88  return $key;
89  }
90 
91  // check resource??action
92  if (strlen($resource) > 0 && strlen($action) > 0)
93  {
94  $key = $resource.$this->_actionDelimiter.$this->_actionDelimiter.$action;
95  if ($parser->getValue($key, $section, false) !== false)
96  return $key;
97  }
98 
99  // check resource?context?
100  if (strlen($resource) > 0 && strlen($context) > 0)
101  {
102  $key = $resource.$this->_actionDelimiter.$context.$this->_actionDelimiter;
103  if ($parser->getValue($key, $section, false) !== false)
104  return $key;
105  }
106 
107  // check ?context?action
108  if (strlen($context) > 0 && strlen($action) > 0)
109  {
110  $key = $this->_actionDelimiter.$context.$this->_actionDelimiter.$action;
111  if ($parser->getValue($key, $section, false) !== false)
112  return $key;
113  }
114 
115  // check ??action
116  if (strlen($action) > 0)
117  {
118  $key = $this->_actionDelimiter.$this->_actionDelimiter.$action;
119  if ($parser->getValue($key, $section, false) !== false)
120  return $key;
121  }
122 
123  // check resource??
124  if (strlen($resource) > 0)
125  {
126  $key = $resource.$this->_actionDelimiter.$this->_actionDelimiter;
127  if ($parser->getValue($key, $section, false) !== false)
128  return $key;
129  }
130 
131  // check ?context?
132  if (strlen($context) > 0)
133  {
134  $key = $this->_actionDelimiter.$context.$this->_actionDelimiter;
135  if ($parser->getValue($key, $section, false) !== false)
136  return $key;
137  }
138 
139  // check ??
140  $key = $this->_actionDelimiter.$this->_actionDelimiter;
141  if ($parser->getValue($key, $section, false) !== false)
142  return $key;
143 
144  return '';
145  }
146 
147  /**
148  * Implement InifileParser public readonly Interface
149  */
150 
151  /**
152  * @see InifileParser::getErrorMsg()
153  */
154  function getErrorMsg()
155  {
156  $parser = &InifileParser::getInstance();
157  return $parser->getErrorMsg();
158  }
159  /**
160  * @see InifileParser::parseIniFile()
161  */
162  function parseIniFile($filename, $processValues=true)
163  {
164  $parser = &InifileParser::getInstance();
165  return $parser->parseIniFile($filename, $processValues);
166  }
167  /**
168  * @see InifileParser::getData()
169  */
170  function getData()
171  {
172  $parser = &InifileParser::getInstance();
173  return $parser->getData();
174  }
175  /**
176  * @see InifileParser::getSections()
177  */
178  function getSections()
179  {
180  $parser = &InifileParser::getInstance();
181  return $parser->getSections();
182  }
183  /**
184  * @see InifileParser::getSection()
185  */
186  function getSection($section)
187  {
188  $parser = &InifileParser::getInstance();
189  return $parser->getSection($section);
190  }
191  /**
192  * @see InifileParser::getValue()
193  */
194  function getValue($key, $section)
195  {
196  $parser = &InifileParser::getInstance();
197  return $parser->getValue($key, $section);
198  }
199 }
200 ?>
parseIniFile($filename, $processValues=true)
WCMFInifileParser adds methods for wcmf specific inifiles. This class is a decorator to the InifilePa...
getBestActionKey($section, $resource, $context, $action)
FileUtil provides basic support for file functionality like HTTP file upload.