ada1f77cd439258363db138868086fbb99c6b828
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Filter / FileNameFilter.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Filter;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Resource\Driver\DriverInterface;
18
19 /**
20 * Utility methods for filtering filenames
21 */
22 class FileNameFilter
23 {
24 /**
25 * whether to also show the hidden files (don't show them by default)
26 *
27 * @var bool
28 */
29 protected static $showHiddenFilesAndFolders = false;
30
31 /**
32 * Filter method that checks if a file/folder name starts with a dot (e.g. .htaccess)
33 *
34 * We have to use -1 as the „don't include“ return value, as call_user_func() will return FALSE
35 * If calling the method succeeded and thus we can't use that as a return value.
36 *
37 * @param string $itemName
38 * @param string $itemIdentifier
39 * @param string $parentIdentifier
40 * @param array $additionalInformation Additional information (driver dependent) about the inspected item
41 * @param DriverInterface $driverInstance
42 * @return bool|int -1 if the file should not be included in a listing
43 */
44 public static function filterHiddenFilesAndFolders($itemName, $itemIdentifier, $parentIdentifier, array $additionalInformation, DriverInterface $driverInstance)
45 {
46 // Only apply the filter if you want to hide the hidden files
47 if (self::$showHiddenFilesAndFolders === false && strpos($itemIdentifier, '/.') !== false) {
48 return -1;
49 } else {
50 return true;
51 }
52 }
53
54 /**
55 * Gets the info whether the hidden files are also displayed currently
56 *
57 * @static
58 * @return bool
59 */
60 public static function getShowHiddenFilesAndFolders()
61 {
62 return self::$showHiddenFilesAndFolders;
63 }
64
65 /**
66 * set the flag to show (or hide) the hidden files
67 *
68 * @static
69 * @param bool $showHiddenFilesAndFolders
70 * @return bool
71 */
72 public static function setShowHiddenFilesAndFolders($showHiddenFilesAndFolders)
73 {
74 return self::$showHiddenFilesAndFolders = (bool)$showHiddenFilesAndFolders;
75 }
76 }