deb75f1f54775216786499af82b685ba3baafd9a
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Storage / StorageFactory.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Storage;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Dmitry Dulepov <dmitry@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * This class contains a factory for the RSA backends.
28 *
29 * @author Dmitry Dulepov <dmitry@typo3.org>
30 */
31 class StorageFactory {
32
33 /**
34 * A list of all available storages. Currently this list cannot be extended.
35 * This is for security reasons to avoid inserting some dummy storage to
36 * the list.
37 *
38 * @var string
39 */
40 static protected $preferredStorage = 'TYPO3\\CMS\\Rsaauth\\Storage\\SplitStorage';
41
42 /**
43 * An instance of the storage. This member is set in the getStorage() function.
44 * It will not be an abstract storage as shown below but a real class, which is
45 * derived from the \TYPO3\CMS\Rsaauth\Storage\AbstractStorage.
46 *
47 * <!-- Please, keep the variable type! It helps IDEs to provide autocomplete! -->
48 *
49 * @var \TYPO3\CMS\Rsaauth\Storage\AbstractStorage
50 */
51 static protected $storageInstance = NULL;
52
53 /**
54 * Obtains a storage. This function will return a non-abstract class, which
55 * is derived from \TYPO3\CMS\Rsaauth\Storage\AbstractStorage. Applications should
56 * not use any methods that are not declared in the \TYPO3\CMS\Rsaauth\Storage\AbstractStorage.
57 *
58 * @return \TYPO3\CMS\Rsaauth\Storage\AbstractStorage A storage
59 */
60 static public function getStorage() {
61 if (is_null(self::$storageInstance)) {
62 self::$storageInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj(self::$preferredStorage);
63 }
64 return self::$storageInstance;
65 }
66
67 /**
68 * Sets the preferred storage to the factory. This method can be called from
69 * another extension or ext_localconf.php
70 *
71 * @param string $preferredStorage Preferred storage
72 * @return void
73 */
74 static public function setPreferredStorage($preferredStorage) {
75 self::$preferredStorage = $preferredStorage;
76 }
77
78 }