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