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