fdf43dcc01000045efa1a6bc565d0411452ebbe0
[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 require_once(t3lib_extMgm::extPath('rsaauth', 'sv1/backends/class.tx_rsaauth_abstract_backend.php'));
26
27 /**
28 * This class contains a factory for the RSA backends.
29 *
30 * @author Dmitry Dulepov <dmitry@typo3.org>
31 * @package TYPO3
32 * @subpackage tx_rsaauth
33 */
34 class tx_rsaauth_backendfactory {
35
36 /**
37 * A list of all available backends. Currently this list cannot be extended.
38 * This is for security reasons to avoid inserting some dummy backend to
39 * the list.
40 *
41 * @var array
42 */
43 static protected $availableBackends = array(
44 'EXT:rsaauth/sv1/backends/class.tx_rsaauth_php_backend.php:tx_rsaauth_php_backend',
45 'EXT:rsaauth/sv1/backends/class.tx_rsaauth_cmdline_backend.php:tx_rsaauth_cmdline_backend'
46 );
47
48 /**
49 * A flag that tells if the factory is initialized. This is to prevent
50 * continious creation of backends in case if none of them is available.
51 *
52 * @var boolean
53 */
54 static protected $initialized = FALSE;
55
56 /**
57 * A selected backend. This member is set in the getBackend() function. It
58 * will not be an abstract backend as shown below but a real class, which is
59 * derieved from the tx_rsaauth_abstract_backend.
60 *
61 * <!-- Please, keep the variable type! It helps IDEs to provide autocomple! -->
62 *
63 * @var tx_rsaauth_abstract_backend
64 */
65 static protected $selectedBackend = NULL;
66
67 /**
68 * Obtains a backend. This function will return a non-abstract class, which
69 * is derieved from the tx_rsaauth_abstract_backend. Applications should
70 * not use anoy methods that are not declared in the tx_rsaauth_abstract_backend.
71 *
72 * @return tx_rsaauth_abstract_backend A backend
73 */
74 static public function getBackend() {
75 if (!self::$initialized) {
76 // Backend does not exist yet. Create it.
77 foreach (self::$availableBackends as $backend) {
78 $backendObject = t3lib_div::getUserObj($backend);
79 // Check that it is derieved from the proper base class
80 if ($backendObject instanceof tx_rsaauth_abstract_backend) {
81 /* @var $backendObject tx_rsaauth_abstract_backend */
82 if ($backendObject->isAvailable()) {
83 // The backend is available, save it and stop the loop
84 self::$selectedBackend = $backendObject;
85 self::$initialized = TRUE;
86 break;
87 }
88 // Attempt to force destruction of the object
89 unset($backend);
90 }
91 }
92 }
93 return self::$selectedBackend;
94 }
95
96 }
97
98 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/backends/class.tx_rsaauth_backendfactory.php'])) {
99 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/backends/class.tx_rsaauth_backendfactory.php']);
100 }
101
102 ?>