170a894cc90b262f5b39d247dd7a87d8547c9240
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / Classes / Autoloader.php
1 <?php
2 namespace TYPO3\CMS\Dbal;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Xavier Perseguers <xavier@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 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Autoloader included from Install Tool that lets DBAL load itself
31 * if it makes sense.
32 *
33 * @author Xavier Perseguers <xavier@typo3.org>
34 */
35 class Autoloader {
36
37 /**
38 * Activates DBAL if it is supported.
39 *
40 * @param \TYPO3\CMS\Install\Installer $instObj
41 * @return void
42 */
43 public function execute(\TYPO3\CMS\Install\Installer $instObj) {
44 if ($instObj->mode == '123') {
45 switch ($instObj->step) {
46 case 1:
47 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal') && $this->isDbalSupported()) {
48 $this->activateDbal();
49 // Reload page to have Install Tool actually load DBAL
50 $redirectUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
51 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($redirectUrl);
52 }
53 break;
54 case 2:
55 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal') && $this->isDbalSupported()) {
56 $this->activateDbal();
57 }
58 break;
59 case 3:
60 $driver = $instObj->INSTALL['Database']['typo_db_driver'];
61 if ($driver === 'mysql') {
62 $this->deactivateDbal();
63 }
64 break;
65 }
66 }
67 }
68
69 /**
70 * Returns TRUE if PHP modules to run DBAL are loaded.
71 *
72 * @return boolean
73 */
74 protected function isDbalSupported() {
75 return extension_loaded('odbc') || extension_loaded('pdo') || extension_loaded('oci8');
76 }
77
78 /**
79 * Activates DBAL.
80 *
81 * @return void
82 */
83 protected function activateDbal() {
84 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')) {
85 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtension('adodb');
86 }
87 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')) {
88 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtension('dbal');
89 }
90 }
91
92 /**
93 * Dectivates DBAL.
94 *
95 * @return void
96 */
97 protected function deactivateDbal() {
98 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal')) {
99 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::unloadExtension('dbal');
100 }
101 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('adodb')) {
102 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::unloadExtension('adodb');
103 }
104 }
105
106 }
107
108
109 ?>