[TASK] Use fully qualified name resolution in PHP 5.5
[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 /**
18 * Class extending the docbook generator service for use in typo3 v4.
19 *
20 * Usage in TypoScript:
21 *
22 * config.disableAllHeaderCode = 1
23 * page = PAGE
24 * page.10 = USER_INT
25 * page.10.userFunc = \TYPO3\CMS\Fluid\Compatibility\DocbookGeneratorService->userFunc
26 *
27 * @internal
28 */
29 class DocbookGeneratorService extends \TYPO3\CMS\Fluid\Service\DocbookGenerator {
30
31 /**
32 *
33 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
34 */
35 protected $objectManager;
36
37 /**
38 * User function
39 *
40 * @return string
41 */
42 public function userFunc() {
43 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
44 $this->injectDocCommentParser($this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\DocCommentParser::class));
45 $this->injectReflectionService($this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class));
46 return $this->generateDocbook('TYPO3\CMS\Fluid\ViewHelpers');
47 }
48
49 /**
50 * Get class names within namespace
51 *
52 * @param string $namespace
53 * @return array
54 */
55 protected function getClassNamesInNamespace($namespace) {
56 $namespaceParts = explode('\\', $namespace);
57 if ($namespaceParts[count($namespaceParts) - 1] == '') {
58 }
59 $classFilePathAndName = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(\TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($namespaceParts[2])) . 'Classes/';
60 $classFilePathAndName .= implode(array_slice($namespaceParts, 3, -1), '/') . '/';
61 $classNames = array();
62 $this->recursiveClassNameSearch($namespace, $classFilePathAndName, $classNames);
63 sort($classNames);
64 return $classNames;
65 }
66
67 /**
68 * Search recursivly class names within namespace
69 *
70 * @param string $namespace
71 * @param string $directory
72 * @param array $classNames
73 * @return void
74 */
75 private function recursiveClassNameSearch($namespace, $directory, &$classNames) {
76
77 $dh = opendir($directory);
78 $counter = 0;
79 while (($file = readdir($dh)) !== FALSE) {
80 if ($file == '.' || $file == '..' || $file == '.svn') {
81 continue;
82 }
83 if (is_file($directory . $file)) {
84 if (substr($file, 0, 8) == 'Abstract') {
85 continue;
86 }
87 $classNames[] = $namespace . substr($file, 0, -4);
88 } elseif (is_dir($directory . $file)) {
89 $this->recursiveClassNameSearch($namespace . $file . '\\', $directory . $file . '/', $classNames);
90 }
91 }
92 closedir($dh);
93 }
94
95 }