| 1 | <?php |
||
| 2 | |||
| 3 | namespace LeKoala\DevToolkit\Helpers; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Helper class to find spaces in your current scope that break everything in ajax requests... |
||
| 7 | */ |
||
| 8 | class EmptySpaceFinder |
||
| 9 | { |
||
| 10 | const REGEX_OPENING = '/^[\s]+<\?php/'; |
||
| 11 | const REGEX_CLOSING = '/\?>[\s]+$/'; |
||
| 12 | |||
| 13 | public static function findSpacesInFiles($files) |
||
| 14 | { |
||
| 15 | echo '<pre>'; |
||
| 16 | echo "Finding opened or closed tags ...\n\n"; |
||
| 17 | |||
| 18 | $openings = []; |
||
| 19 | $closings = []; |
||
| 20 | foreach ($files as $file) { |
||
| 21 | $content = file_get_contents($file); |
||
| 22 | |||
| 23 | $matches = null; |
||
| 24 | preg_match_all(self::REGEX_OPENING, $content, $matches); |
||
| 25 | |||
| 26 | if (!empty($matches[0])) { |
||
| 27 | $openings[] = $file; |
||
| 28 | } |
||
| 29 | |||
| 30 | $matches = null; |
||
| 31 | preg_match_all(self::REGEX_CLOSING, $content, $matches); |
||
| 32 | |||
| 33 | if (!empty($matches[0])) { |
||
| 34 | $closings[] = $file; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | if (!empty($openings)) { |
||
| 39 | echo "Files with opening tags that may need fixing\n"; |
||
| 40 | foreach ($openings as $file) { |
||
| 41 | echo "$file\n"; |
||
| 42 | } |
||
| 43 | echo "***\n"; |
||
| 44 | } |
||
| 45 | if (!empty($closings)) { |
||
| 46 | echo "Files with closing tags that may need fixing\n"; |
||
| 47 | foreach ($closings as $file) { |
||
| 48 | echo "$file\n"; |
||
| 49 | } |
||
| 50 | echo "***\n"; |
||
| 51 | } |
||
| 52 | |||
| 53 | echo "\nDone!"; |
||
| 54 | echo '</pre>'; |
||
| 55 | die(); |
||
|
0 ignored issues
–
show
|
|||
| 56 | } |
||
| 57 | |||
| 58 | public static function findSpacesInIncludedFiles() |
||
| 59 | { |
||
| 60 | $files = get_included_files(); |
||
| 61 | self::findSpacesInFiles($files); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.