1: <?php
2: /**
3: * This file contains the uri builder custom 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: /**
19: * Custom uri builder class
20: *
21: * @package Core
22: * @subpackage Frontend_URI
23: */
24: class cUriBuilderCustom extends cUriBuilder {
25:
26: /**
27: * Self instance
28: *
29: * @var cUriBuilderCustom
30: */
31: private static $_instance;
32:
33: /**
34: * Configuration
35: *
36: * @var array
37: */
38: private $aConfig;
39:
40: /**
41: * Constructor
42: *
43: * @return void
44: */
45: private function __construct() {
46: $this->sHttpBasePath = '';
47: }
48:
49: /**
50: * Get instance of self
51: *
52: * @return cUriBuilderCustom
53: */
54: public static function getInstance() {
55: if (self::$_instance == NULL) {
56: self::$_instance = new self();
57: }
58: return self::$_instance;
59: }
60:
61: /**
62: * Builds a URL in index-a-1.html style.
63: * Index keys of $aParams will be used as "a", corresponding values as "1"
64: * in this sample.
65: *
66: * @param array $aParams
67: * @param bool $bUseAbsolutePath
68: * @param array $aConfig If not set, will use cUriBuilderConfig::getConfig()
69: * @return void
70: * @throws cInvalidArgumentException
71: */
72: public function buildUrl(array $aParams, $bUseAbsolutePath = false, array $aConfig = array()) {
73: if (sizeof($aParams) == 0) {
74: throw new cInvalidArgumentException('$aParams must have at least one entry!');
75: }
76: // if no config passed or not all parameters available, use default
77: // config
78: if (sizeof($aConfig) == 0 || !isset($aConfig['prefix']) || !isset($aConfig['suffix']) || !isset($aConfig['separator'])) {
79: include_once ('class.uribuilder.config.php');
80: $aConfig = cUriBuilderConfig::getConfig();
81: }
82: $this->aConfig = $aConfig;
83:
84: $this->sUrl = $bUseAbsolutePath === true ? $this->sHttpBasePath : '';
85: $this->sUrl .= $this->aConfig['prefix'];
86: foreach ($aParams as $sKey => $mVal) {
87: $sVal = $mVal; // assuming mVal is a string and thus a single value
88: if (is_array($mVal)) { // mVal has more than one value, e.g.
89: // index-b-1-2.html
90: $sVal = implode($this->aConfig['separator'], $mVal);
91: }
92: $this->sUrl .= $this->aConfig['separator'] . strval($sKey) . $this->aConfig['separator'] . strval($sVal);
93: }
94: $this->sUrl .= $this->aConfig['suffix'];
95: }
96:
97: }
98: