Textpattern | PHP Cross Reference | Content Management Systems |
Description: Recursive directory iterator
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 /** 25 * Recursive directory iterator 26 * 27 * <code> 28 * $files = new \Textpattern\Iterator\RecDirIterator($dirPath); 29 * 30 * foreach ($files as $file) { 31 * echo $file->getPathname(); 32 * } 33 * </code> 34 * 35 * @since 4.7.0 36 * @package Iterator 37 */ 38 39 namespace Textpattern\Iterator { 40 41 class RecDirIterator extends \RecursiveDirectoryIterator 42 { 43 /** 44 * {@inheritdoc} 45 */ 46 47 public function __construct($path, $flags = null) 48 { 49 if ($flags === null) { 50 $flags = \FilesystemIterator::FOLLOW_SYMLINKS | 51 \FilesystemIterator::CURRENT_AS_SELF | 52 \FilesystemIterator::SKIP_DOTS; 53 } 54 55 parent::__construct($path, $flags); 56 } 57 58 /** 59 * Gets the template contents. 60 * 61 * @throws \Exception 62 */ 63 64 public function getContents() 65 { 66 $pathname = $this->getPathname(); 67 $contents = file_get_contents($pathname); 68 69 if ($contents !== false) { 70 return preg_replace('/[\r|\n]+$/', '', $contents); 71 } 72 73 throw new \Exception('Unable to read: '.$pathname); 74 } 75 76 /** 77 * Gets JSON file contents as an object. 78 * 79 * @return array 80 */ 81 82 public function getJSONContents() 83 { 84 return @json_decode($this->getContents(), true); 85 } 86 } 87 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title