43074d206e867ea9bd88d1b895f16682f0823c7d
[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-2011 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 * @package TYPO3
35 * @subpackage dbal
36 */
37 class Autoloader {
38
39 /**
40 * Activates DBAL if it is supported.
41 *
42 * @param \TYPO3\CMS\Install\Installer $instObj
43 * @return void
44 */
45 public function execute(\TYPO3\CMS\Install\Installer $instObj) {
46 if ($instObj->mode == '123') {
47 switch ($instObj->step) {
48 case 1:
49 if (!\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('dbal') && $this->isDbalSupported()) {
50 $this->activateDbal();
51 // Reload page to have Install Tool actually load DBAL
52 $redirectUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
53 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($redirectUrl);
54 }
55 break;
56 case 2:
57 if (!\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('dbal') && $this->isDbalSupported()) {
58 $this->activateDbal();
59 }
60 break;
61 case 3:
62 $driver = $instObj->INSTALL['Database']['typo_db_driver'];
63 if ($driver === 'mysql') {
64 $this->deactivateDbal();
65 }
66 break;
67 }
68 }
69 }
70
71 /**
72 * Returns TRUE if PHP modules to run DBAL are loaded.
73 *
74 * @return boolean
75 */
76 protected function isDbalSupported() {
77 return extension_loaded('odbc') || extension_loaded('pdo') || extension_loaded('oci8');
78 }
79
80 /**
81 * Activates DBAL.
82 *
83 * @return void
84 */
85 protected function activateDbal() {
86 if (!\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('adodb')) {
87 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtension('adodb');
88 }
89 if (!\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('dbal')) {
90 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtension('dbal');
91 }
92 }
93
94 /**
95 * Dectivates DBAL.
96 *
97 * @return void
98 */
99 protected function deactivateDbal() {
100 if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('dbal')) {
101 \TYPO3\CMS\Core\Extension\ExtensionManager::unloadExtension('dbal');
102 }
103 if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('adodb')) {
104 \TYPO3\CMS\Core\Extension\ExtensionManager::unloadExtension('adodb');
105 }
106 }
107
108 }
109
110
111 ?>