014b13a395a207d92bd9d735192082f04ac3baa3
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Compatibility / DocbookGeneratorService.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Compatibility;
3
4 /* *
5 * This script is part of the TYPO3 project - inspiring people to share! *
6 * *
7 * TYPO3 is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU General Public License version 2 as published by *
9 * the Free Software Foundation. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14 * Public License for more details. *
15 * */
16 /**
17 * Class extending the docbook generator service for use in typo3 v4.
18 *
19 * Usage in TypoScript:
20 *
21 *
22 *
23 * config.disableAllHeaderCode = 1
24 * page = PAGE
25 * page.10 = USER_INT
26 * page.10.userFunc = Tx_Fluid_Compatibility_DocbookGeneratorService->userFunc
27 *
28 * @internal
29 */
30 class DocbookGeneratorService extends \TYPO3\CMS\Fluid\Service\DocbookGenerator {
31
32 public function userFunc() {
33 if (!class_exists('TYPO3\\CMS\\Extbase\\Utility\\ClassLoaderUtility')) {
34 require \t3lib_extmgm::extPath('extbase') . 'Classes/Utility/ClassLoader.php';
35 }
36 $classLoader = new \TYPO3\CMS\Extbase\Utility\ClassLoaderUtility();
37 spl_autoload_register(array($classLoader, 'loadClass'));
38 return $this->generateDocbook('Tx_Fluid_ViewHelpers');
39 }
40
41 protected function getClassNamesInNamespace($namespace) {
42 $namespaceParts = explode('_', $namespace);
43 if ($namespaceParts[count($namespaceParts) - 1] == '') {
44 }
45 $classFilePathAndName = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(\TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($namespaceParts[1])) . 'Classes/';
46 $classFilePathAndName .= implode(array_slice($namespaceParts, 2, -1), '/') . '/';
47 $classNames = array();
48 $this->recursiveClassNameSearch($namespace, $classFilePathAndName, $classNames);
49 sort($classNames);
50 return $classNames;
51 }
52
53 private function recursiveClassNameSearch($namespace, $directory, &$classNames) {
54 $dh = opendir($directory);
55 while (($file = readdir($dh)) !== FALSE) {
56 if ($file == '.' || $file == '..' || $file == '.svn') {
57 continue;
58 }
59 if (is_file($directory . $file)) {
60 if (substr($file, 0, 8) == 'Abstract') {
61 continue;
62 }
63 $classNames[] = $namespace . substr($file, 0, -4);
64 } elseif (is_dir($directory . $file)) {
65 $this->recursiveClassNameSearch($namespace . $file . '_', $directory . $file . '/', $classNames);
66 }
67 }
68 closedir($dh);
69 }
70
71 protected function instanciateViewHelper($className) {
72 $objectFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
73 return $objectFactory->get($className);
74 }
75 }
76
77 ?>