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