[TASK] Use autoloader in rsaauth system extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / sv1 / backends / class.tx_rsaauth_backendfactory.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Dmitry Dulepov <dmitry@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * This class contains a factory for the RSA backends.
28 *
29 * @author Dmitry Dulepov <dmitry@typo3.org>
30 * @package TYPO3
31 * @subpackage tx_rsaauth
32 */
33 class tx_rsaauth_backendfactory {
34
35 /**
36 * A list of all available backends. Currently this list cannot be extended.
37 * This is for security reasons to avoid inserting some dummy backend to
38 * the list.
39 *
40 * @var array
41 */
42 static protected $availableBackends = array(
43 'EXT:rsaauth/sv1/backends/class.tx_rsaauth_php_backend.php:tx_rsaauth_php_backend',
44 'EXT:rsaauth/sv1/backends/class.tx_rsaauth_cmdline_backend.php:tx_rsaauth_cmdline_backend'
45 );
46
47 /**
48 * A flag that tells if the factory is initialized. This is to prevent
49 * continious creation of backends in case if none of them is available.
50 *
51 * @var boolean
52 */
53 static protected $initialized = FALSE;
54
55 /**
56 * A selected backend. This member is set in the getBackend() function. It
57 * will not be an abstract backend as shown below but a real class, which is
58 * derieved from the tx_rsaauth_abstract_backend.
59 *
60 * <!-- Please, keep the variable type! It helps IDEs to provide autocomple! -->
61 *
62 * @var tx_rsaauth_abstract_backend
63 */
64 static protected $selectedBackend = NULL;
65
66 /**
67 * Obtains a backend. This function will return a non-abstract class, which
68 * is derieved from the tx_rsaauth_abstract_backend. Applications should
69 * not use anoy methods that are not declared in the tx_rsaauth_abstract_backend.
70 *
71 * @return tx_rsaauth_abstract_backend A backend
72 */
73 static public function getBackend() {
74 if (!self::$initialized) {
75 // Backend does not exist yet. Create it.
76 foreach (self::$availableBackends as $backend) {
77 $backendObject = t3lib_div::getUserObj($backend);
78 // Check that it is derieved from the proper base class
79 if ($backendObject instanceof tx_rsaauth_abstract_backend) {
80 /* @var $backendObject tx_rsaauth_abstract_backend */
81 if ($backendObject->isAvailable()) {
82 // The backend is available, save it and stop the loop
83 self::$selectedBackend = $backendObject;
84 self::$initialized = TRUE;
85 break;
86 }
87 // Attempt to force destruction of the object
88 unset($backend);
89 }
90 }
91 }
92 return self::$selectedBackend;
93 }
94
95 }
96
97 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/backends/class.tx_rsaauth_backendfactory.php'])) {
98 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/backends/class.tx_rsaauth_backendfactory.php']);
99 }
100
101 ?>