summaryrefslogtreecommitdiff
path: root/lib/querypath/src/QueryPath/Options.php
blob: 846984db5601e7e8ebc0fabc131054f99501ffa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
 * @file
 *
 * Options management.
 */
namespace QueryPath;


/**
 * Manage default options.
 *
 * This class stores the default options for QueryPath. When a new
 * QueryPath object is constructed, options specified here will be
 * used.
 *
 * <b>Details</b>
 * This class defines no options of its own. Instead, it provides a
 * central tool for developers to override options set by QueryPath.
 * When a QueryPath object is created, it will evaluate options in the
 * following order:
 *
 * - Options passed into qp() have highest priority.
 * - Options in QueryPath::Options (this class) have the next highest priority.
 * - If the option is not specified elsewhere, QueryPath will use its own defaults.
 *
 * @see qp()
 * @see QueryPath::Options::set()
 * @ingroup querypath_util
 */
class Options {
  /**
   * This is the static options array.
   *
   * Use the {@link set()}, {@link get()}, and {@link merge()} to
   * modify this array.
   */
  static $options = array();
  /**
   * Set the default options.
   *
   * The passed-in array will be used as the default options list.
   *
   * @param array $array
   *  An associative array of options.
   */
  static function set($array) {
    self::$options = $array;
  }
  /**
   * Get the default options.
   *
   * Get all options currently set as default.
   *
   * @return array
   *  An array of options. Note that only explicitly set options are
   *  returned. {@link QueryPath} defines default options which are not
   *  stored in this object.
   */
  static function get() {
    return self::$options;
  }
  /**
   * Merge the provided array with existing options.
   *
   * On duplicate keys, the value in $array will overwrite the
   * value stored in the options.
   *
   * @param array $array
   *  Associative array of options to merge into the existing options.
   */
  static function merge($array) {
    self::$options = $array + self::$options;
  }
  /**
   * Returns true of the specified key is already overridden in this object.
   *
   * @param string $key
   *  The key to search for.
   */
  static function has($key) {
    return array_key_exists($key, self::$options);
  }
}