FunctionListStrategy.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
15 
16 /**
17  * FunctionListStrategy implements a list of key/value pairs that is retrieved
18  * by a global function.
19  *
20  * Configuration examples:
21  * @code
22  * // key/value pairs provided by global function g_getListValues
23  * {"type":"function","name":"g_getListValues"}
24  *
25  * // key/value pairs provided by global function g_getListValues with parameters
26  * {"type":"function","name":"g_getListValues","params":["param1","param2"]}
27  * @endcode
28  *
29  * @author ingo herwig <ingo@wemove.com>
30  */
32 
33  /**
34  * @see ListStrategy::getList
35  * $options is an associative array with keys 'name' and 'params' (optional)
36  */
37  public function getList($options, $language=null) {
38  if (!isset($options['name'])) {
39  throw new ConfigurationException("No 'name' given in list options: "+$options);
40  }
41  $name = $options['name'];
42  $params = isset($options['params']) ? $options['params'] : null;
43 
44  if (function_exists($name)) {
45  $map = call_user_func_array($name, $params);
46  }
47  else {
48  throw new ConfigurationException('Function '.$name.' is not defined globally!');
49  }
50  return $map;
51  }
52 
53  /**
54  * @see ListStrategy::isStatic
55  */
56  public function isStatic($options) {
57  return false;
58  }
59 }
60 ?>
FunctionListStrategy implements a list of key/value pairs that is retrieved by a global function...
ListStrategy defines the interface for classes that retrieve value lists.
ConfigurationException signals an exception in the configuration.