1: <?php
2:
3: /**
4: * This file contains the uri builder factory 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: * Factory for retrieving required cUriBuilder object.
19: *
20: * @package Core
21: * @subpackage Frontend_URI
22: */
23: class cUriBuilderFactory {
24:
25: /**
26: * Returns desired cUriBuilder object.
27: *
28: * @param string $sBuilder
29: * For now, those are valid: front_content, custom, custom_path
30: * or a Userdefined cUriBuilder name.
31: * The name must be a subpart of the cUriBuilder class,
32: * e.g. 'MyUriBuilder' for cUriBuilderMyUriBuilder.
33: * The classfile must be named like class.uribuilder.myuribuilder.php
34: * and it must be reside in /contenido/classes/uri/ folder.
35: * @return cUriBuilder
36: * @throws cInvalidArgumentException
37: * In case unknown type of builder is requested you'll get an Exception
38: */
39: public static function getUriBuilder($sBuilder) {
40: switch ($sBuilder) {
41: case 'front_content':
42: return cUriBuilderFrontcontent::getInstance();
43: break;
44: case 'custom':
45: return cUriBuilderCustom::getInstance();
46: break;
47: case 'custom_path':
48: return cUriBuilderCustomPath::getInstance();
49: break;
50: default:
51: // TODO check if this is needed any longer because we have autoloading feature
52: if ((string) $sBuilder !== '') {
53: $sClassName = 'cUriBuilder' . $sBuilder;
54: $sFileName = 'class.uribuilder.' . strtolower($sBuilder) . '.php';
55: $sPath = str_replace('\\', '/', dirname(__FILE__)) . '/';
56: if (!cFileHandler::exists($sPath . $sFileName)) {
57: throw new cInvalidArgumentException('The classfile of cUriBuilder couldn\'t included by Contenido_UriBuilderFactory: ' . $sBuilder . '!');
58: }
59: cInclude('classes', 'uri/' . $sFileName);
60: if (!class_exists($sClassName)) {
61: throw new cInvalidArgumentException('The classfile of cUriBuilder couldn\'t included by Contenido_UriBuilderFactory: ' . $sBuilder . '!');
62: }
63: return call_user_func(array($sClassName, 'getInstance'));
64: }
65:
66: throw new cInvalidArgumentException('Invalid/Empty cUriBuilder passed to cUriBuilderFactory: ' . $sBuilder . '!');
67: break;
68: }
69: }
70:
71: }
72: