[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Backend / BackendFactory.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Backend;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * This class contains a factory for the RSA backends.
18 *
19 * @author Dmitry Dulepov <dmitry@typo3.org>
20 */
21 class BackendFactory {
22
23 /**
24 * A list of all available backends. Currently this list cannot be extended.
25 * This is for security reasons to avoid inserting some dummy backend to
26 * the list.
27 *
28 * @var array
29 */
30 static protected $availableBackends = array(
31 'TYPO3\\CMS\\Rsaauth\\Backend\\PhpBackend',
32 'TYPO3\\CMS\\Rsaauth\\Backend\\CommandLineBackend'
33 );
34
35 /**
36 * A flag that tells if the factory is initialized. This is to prevent
37 * continuous creation of backends in case if none of them is available.
38 *
39 * @var boolean
40 */
41 static protected $initialized = FALSE;
42
43 /**
44 * A selected backend. This member is set in the getBackend() function. It
45 * will not be an abstract backend as shown below but a real class, which is
46 * derived from the \TYPO3\CMS\Rsaauth\Backend\AbstractBackend.
47 *
48 * @var \TYPO3\CMS\Rsaauth\Backend\AbstractBackend
49 */
50 static protected $selectedBackend = NULL;
51
52 /**
53 * Obtains a backend. This function will return a non-abstract class, which
54 * is derived from the \TYPO3\CMS\Rsaauth\Backend\AbstractBackend. Applications should
55 * not use any methods that are not declared in the \TYPO3\CMS\Rsaauth\Backend\AbstractBackend.
56 *
57 * @return \TYPO3\CMS\Rsaauth\Backend\AbstractBackend A backend
58 */
59 static public function getBackend() {
60 if (!self::$initialized) {
61 // Backend does not exist yet. Create it.
62 foreach (self::$availableBackends as $backend) {
63 $backendObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($backend);
64 // Check that it is derived from the proper base class
65 if ($backendObject instanceof \TYPO3\CMS\Rsaauth\Backend\AbstractBackend) {
66 /** @var $backendObject \TYPO3\CMS\Rsaauth\Backend\AbstractBackend */
67 if ($backendObject->isAvailable()) {
68 // The backend is available, save it and stop the loop
69 self::$selectedBackend = $backendObject;
70 self::$initialized = TRUE;
71 break;
72 }
73 // Attempt to force destruction of the object
74 unset($backendObject);
75 }
76 }
77 }
78 return self::$selectedBackend;
79 }
80
81 }