1: <?php
2:
3: namespace malkusch\bav;
4:
5: /**
6: * Registry for the configuration
7: *
8: * BAV uses this static container for its runtime configuration. Per default the
9: * registry is initialized with the {@link DefaultConfiguration}. You can
10: * set your own configuration with {@link setConfiguration()} or preferably
11: * by providing the file bav/configuration.php. This file should return a
12: * {@link Configuration} object:
13: *
14: * <code>
15: * <?php
16: *
17: * namespace malkusch\bav;
18: *
19: * $configuration = new DefaultConfiguration();
20: *
21: * $pdo = new \PDO("mysql:host=localhost;dbname=test");
22: * $configuration->setDataBackendContainer(new PDODataBackendContainer($pdo));
23: *
24: * $configuration->setUpdatePlan(new AutomaticUpdatePlan());
25: *
26: * return $configuration;
27: * </code>
28: *
29: * @author Markus Malkusch <markus@malkusch.de>
30: * @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
31: * @license GPL
32: * @see Configuration
33: * @api
34: */
35: class ConfigurationRegistry
36: {
37:
38: const BAV_PATH = "/../../configuration.php";
39:
40: const INCLUDE_PATH = "bav/configuration.php";
41:
42: /**
43: * @var Configuration
44: */
45: private static $configuration;
46:
47: /**
48: * locate a configuration or register the default configuration.
49: *
50: * You may define the file bav/configuration.php. This file should return
51: * a Configuration object.
52: *
53: * @see DefaultConfiguration
54: * @throws ConfigurationException
55: */
56: public static function classConstructor()
57: {
58: $locator = new ConfigurationLocator(array(
59: __DIR__ . self::BAV_PATH,
60: self::INCLUDE_PATH
61: ));
62: $configuration = $locator->locate();
63: if ($configuration == null) {
64: $configuration = new DefaultConfiguration();
65:
66: }
67: self::setConfiguration($configuration);
68: }
69:
70: /**
71: * Register a configuration programmatically.
72: *
73: * Alternatively you can provide the file bav/configuration.php which
74: * returns a {@link Configuration} object.
75: */
76: public static function setConfiguration(Configuration $configuration)
77: {
78: self::$configuration = $configuration;
79: }
80:
81: /**
82: * Returns the configuration
83: *
84: * @return Configuration
85: */
86: public static function getConfiguration()
87: {
88: return self::$configuration;
89: }
90: }
91: