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