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