1: <?php
2:
3: /**
4: * This file contains the uri builder configuration class.
5: *
6: * @package Core
7: * @subpackage Frontend_URI
8: * @author Rudi Bieller
9: * @copyright four for business AG <www.4fb.de>
10: * @license http://www.contenido.org/license/LIZENZ.txt
11: * @link http://www.4fb.de
12: * @link http://www.contenido.org
13: */
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: if (!class_exists('NotInitializedException')) {
18: /**
19: */
20: class NotInitializedException extends Exception {
21: }
22: }
23:
24: /**
25: * Configure cUriBuilder URL style. Per default, configures for style
26: * index-a-1.html.
27: *
28: * If you need another style, extend this class to your needs and pass
29: * it to desired cUriBuilder.
30: *
31: * The cUriBuilderConfig::setConfig() must be called at least once to
32: * initialize the desired UriBuilder.
33: *
34: * Usage:
35: * ------
36: * <code>
37: * // Example for default front_content cUriBuilder
38: * $myCfg['name'] = 'front_content';
39: * $myCfg['config'] = array();
40: * cUriBuilderConfig::setConfig($myCfg);
41: *
42: * // Example for CustomPath cUriBuilder
43: * $myCfg['name'] = 'custom_path';
44: * $myCfg['config'] = array('prefix' => 'rocknroll', 'suffix' => '.4fb',
45: * 'separator' => ',');
46: * cUriBuilderConfig::setConfig($myCfg);
47: * </code>
48: *
49: * @package Core
50: * @subpackage Frontend_URI
51: */
52: class cUriBuilderConfig {
53:
54: /**
55: * UriBuilder configuration array
56: *
57: * @var array
58: */
59: private static $_aUriBuilderCfg = array(
60: 'config' => array(
61: 'prefix' => 'index',
62: 'suffix' => '.html',
63: 'separator' => '-'
64: )
65: );
66:
67: /**
68: * Set cUriBuilder configuration.
69: *
70: * @param array $cfg
71: * Assoziative configuration array as follows:
72: * - $cfg['name'] = Name of UriBuilder class to use
73: * - $cfg['config'] = UriBuilder configuration
74: * @throws cInvalidArgumentException
75: * If $cfg ist empty, $cfg['name'] is missing
76: * or $cfg['config'] exists but is not a array
77: */
78: public static function setConfig(array $cfg) {
79: if (count($cfg) == 0) {
80: throw new cInvalidArgumentException('cUriBuilderConfig: Empty configuration');
81: } elseif (!isset($cfg['name']) || (string) $cfg['name'] === '') {
82: throw new cInvalidArgumentException('cUriBuilderConfig: Missing UriBuilder name');
83: } elseif (isset($cfg['config']) && !is_array($cfg['config'])) {
84: throw new cInvalidArgumentException('cUriBuilderConfig: Invalid UriBuilder configuration');
85: }
86:
87: self::$_aUriBuilderCfg = $cfg;
88: }
89:
90: /**
91: * Returns cUriBuilder name.
92: *
93: * @throws cException
94: * If cUriBuilder configuration wasn't initialized before
95: * @return string
96: * cUriBuilder name
97: */
98: public static function getUriBuilderName() {
99: if (!is_array(self::$_aUriBuilderCfg) || !isset(self::$_aUriBuilderCfg['name'])) {
100: throw new cException('cUriBuilderConfig: Configuration is not set');
101: }
102:
103: return self::$_aUriBuilderCfg['name'];
104: }
105:
106: /**
107: * Returns cUriBuilder configuration.
108: *
109: * @throws cException
110: * If cUriBuilder configuration wasn't initialized before
111: * @return array
112: * cUriBuilder configuration
113: */
114: public static function getConfig() {
115: if (!is_array(self::$_aUriBuilderCfg)) {
116: throw new cException('cUriBuilderConfig: Configuration is not set');
117: }
118:
119: return self::$_aUriBuilderCfg['config'];
120: }
121:
122: }
123: