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