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