ApplyFiltersTrait.php
1 day ago
ArrayableTrait.php
1 day ago
BatchSizeCalculateTrait.php
1 day ago
BearerTokenTrait.php
1 day ago
BenchmarkTrait.php
1 day ago
BooleanTransientTrait.php
1 day ago
DatabaseSearchReplaceTrait.php
1 day ago
DbRowsGeneratorTrait.php
1 day ago
DebugLogTrait.php
1 day ago
DeveloperTimerTrait.php
1 day ago
EndOfLinePlaceholderTrait.php
1 day ago
EventLoggerTrait.php
1 day ago
FileScanToCacheTrait.php
1 day ago
FormatTrait.php
1 day ago
HttpRequestTrait.php
1 day ago
HydrateTrait.php
1 day ago
I18nTrait.php
1 day ago
IpResolverTrait.php
1 day ago
JobResponseTrait.php
1 day ago
MaintenanceTrait.php
7 months ago
MemoryExhaustTrait.php
1 day ago
MySQLRowsGeneratorTrait.php
1 day ago
NoticesTrait.php
1 day ago
PagesTrait.php
1 day ago
PropertyConstructor.php
1 day ago
RenameTmpDirectoryTrait.php
1 day ago
ResourceTrait.php
1 day ago
RestRequestTrait.php
1 day ago
RestoreFileExclusionTrait.php
1 day ago
SafeFileInfoTrait.php
1 day ago
SerializeTrait.php
1 day ago
SetTimeLimitTrait.php
1 day ago
SlashTrait.php
1 day ago
SqlCommentTrait.php
1 day ago
TablePrefixValidator.php
5 months ago
UrlTrait.php
1 day ago
ValueGetterTrait.php
1 day ago
WindowsOsTrait.php
1 day ago
SafeFileInfoTrait.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Traits; |
| 4 | |
| 5 | use RuntimeException; |
| 6 | use SplFileInfo; |
| 7 | |
| 8 | use function WPStaging\functions\debug_log; |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | trait SafeFileInfoTrait |
| 15 | { |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | protected function isLinkSafely(SplFileInfo $item) |
| 21 | { |
| 22 | try { |
| 23 | return $item->isLink(); |
| 24 | } catch (RuntimeException $openBaseDirException) { |
| 25 | $this->logInaccessiblePath($item, $openBaseDirException); |
| 26 | return null; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | protected function isFileSafely(SplFileInfo $item) |
| 35 | { |
| 36 | try { |
| 37 | return $item->isFile(); |
| 38 | } catch (RuntimeException $openBaseDirException) { |
| 39 | $this->logInaccessiblePath($item, $openBaseDirException); |
| 40 | return null; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | protected function isDirSafely(SplFileInfo $item) |
| 49 | { |
| 50 | try { |
| 51 | return $item->isDir(); |
| 52 | } catch (RuntimeException $openBaseDirException) { |
| 53 | $this->logInaccessiblePath($item, $openBaseDirException); |
| 54 | return null; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | protected function getRealPathSafely(SplFileInfo $item) |
| 63 | { |
| 64 | try { |
| 65 | return $item->getRealPath(); |
| 66 | } catch (RuntimeException $openBaseDirException) { |
| 67 | $this->logInaccessiblePath($item, $openBaseDirException); |
| 68 | return false; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | protected function logInaccessiblePath(SplFileInfo $item, RuntimeException $exception) |
| 78 | { |
| 79 | debug_log('WP STAGING: Skipping inaccessible path during scan: ' . $item->getPathname() . ' - ' . $exception->getMessage()); |
| 80 | } |
| 81 | } |
| 82 |