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