-
Notifications
You must be signed in to change notification settings - Fork 4
/
DirectoryBackporter.php
46 lines (35 loc) · 1.17 KB
/
DirectoryBackporter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Bouda\Php7Backport;
class DirectoryBackporter
{
public function __construct($sourceDir, $destinationDir = false, $output = false)
{
if (!$destinationDir)
{
$destinationDir = $sourceDir;
}
$backporter = new Backporter;
$iterator =
new \CallbackFilterIterator(
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($sourceDir)), function($file)
{
return $file;
});
foreach ($iterator as $file)
{
$newPath = preg_replace("#^" . preg_quote($sourceDir) . "#", $destinationDir, $file);
if ($file->isDir() && !file_exists($newPath))
{
mkdir($newPath);
if ($output) echo "mkdir $newPath\n";
}
elseif ($file->isFile() && in_array($file->getExtension(), ['php', 'phpt', 'phtml'], TRUE))
{
$original = file_get_contents($file);
file_put_contents($newPath, $backporter->port($original));
if ($output) echo "ported file $newPath\n";
}
}
}
}