ConfigListStrategy.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 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 
17 
18 /**
19  * ConfigListStrategy implements a list of key/value pairs that is retrieved
20  * from a configuration section.
21  *
22  * Configuration example:
23  * @code
24  * // configuration section EntityStage
25  * {"type":"config","section":"EntityStage"}
26  * @endcode
27  *
28  * @author ingo herwig <ingo@wemove.com>
29  */
30 class ConfigListStrategy implements ListStrategy {
31 
32  private $lists = [];
33 
34  /**
35  * @see ListStrategy::getList
36  * $options is an associative array with key 'section'
37  */
38  public function getList($options, $valuePattern=null, $key=null, $language=null) {
39  if (!isset($options['section'])) {
40  throw new ConfigurationException("No 'pattern' given in list options: "+StringUtil::getDump($options));
41  }
42  $section = $options['section'];
43  $listKey = $section.$language;
44  if (!isset($this->lists[$listKey])) {
45  $config = ObjectFactory::getInstance('configuration');
46  $map = $config->getSection($section);
47  $result = [];
48  $message = ObjectFactory::getInstance('message');
49  foreach ($map as $curKey => $curValue) {
50  $displayValue = $message->getText($curValue, null, $language);
51  if ((!$valuePattern || preg_match($valuePattern, $displayValue)) && (!$key || $key == $curKey)) {
52  $result[$curKey] = $displayValue;
53  }
54  }
55  $this->lists[$listKey] = $result;
56  }
57  return $this->lists[$listKey];
58  }
59 
60  /**
61  * @see ListStrategy::isStatic
62  */
63  public function isStatic($options) {
64  return true;
65  }
66 }
67 ?>
ConfigListStrategy implements a list of key/value pairs that is retrieved from a configuration sectio...
static getDump($variable, $strlen=100, $width=25, $depth=10, $i=0, &$objects=[])
Get the dump of a variable as string.
Definition: StringUtil.php:29
ListStrategy defines the interface for classes that retrieve value lists.
getList($options, $valuePattern=null, $key=null, $language=null)
StringUtil provides support for string manipulation.
Definition: StringUtil.php:18
ConfigurationException signals an exception in the configuration.
static getInstance($name, $dynamicConfiguration=[])
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...