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: private function __construct() {
44: $this->sHttpBasePath = '';
45: }
46:
47: /**
48: * Get instance of self
49: *
50: * @return cUriBuilderCustom
51: */
52: public static function getInstance() {
53: if (self::$_instance == NULL) {
54: self::$_instance = new self();
55: }
56: return self::$_instance;
57: }
58:
59: /**
60: * Builds a URL in index-a-1.html style.
61: * Index keys of $aParams will be used as "a", corresponding values as "1"
62: * in this sample.
63: *
64: * @param array $aParams
65: * @param bool $bUseAbsolutePath
66: * @param array $aConfig If not set, will use cUriBuilderConfig::getConfig()
67: * @throws cInvalidArgumentException
68: */
69: public function buildUrl(array $aParams, $bUseAbsolutePath = false, array $aConfig = array()) {
70: if (sizeof($aParams) == 0) {
71: throw new cInvalidArgumentException('$aParams must have at least one entry!');
72: }
73: // if no config passed or not all parameters available, use default
74: // config
75: if (sizeof($aConfig) == 0 || !isset($aConfig['prefix']) || !isset($aConfig['suffix']) || !isset($aConfig['separator'])) {
76: include_once('class.uribuilder.config.php');
77: $aConfig = cUriBuilderConfig::getConfig();
78: }
79: $this->aConfig = $aConfig;
80:
81: $this->sUrl = $bUseAbsolutePath === true ? $this->sHttpBasePath : '';
82: $this->sUrl .= $this->aConfig['prefix'];
83: foreach ($aParams as $sKey => $mVal) {
84: $sVal = $mVal; // assuming mVal is a string and thus a single value
85: if (is_array($mVal)) { // mVal has more than one value, e.g.
86: // index-b-1-2.html
87: $sVal = implode($this->aConfig['separator'], $mVal);
88: }
89: $this->sUrl .= $this->aConfig['separator'] . strval($sKey) . $this->aConfig['separator'] . strval($sVal);
90: }
91: $this->sUrl .= $this->aConfig['suffix'];
92: }
93:
94: }
95: