Skip to content
This repository was archived by the owner on Aug 14, 2022. It is now read-only.

Commit 2f7f1a6

Browse files
committed
Updated to 1.1.4 version
1 parent b1a7bc2 commit 2f7f1a6

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* Added `File/_config.yml` file.
1515
* Added `File/.travis.yml` file.
1616

17+
* Added `Josantonius\File\Test\FileTest::CopyDirRecursively()` method.
18+
1719
* Deleted `Josantonius\File\Tests\FileTest::testSearchString()` method.
1820

1921
* Deleted `Josantonius\File\Tests\FileTest` class.

README-ES.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ File::exists();
6060
File::delete();
6161
File::createDir();
6262
File::deleteEmptyDir();
63+
File::CopyDirRecursively();
6364
File::deleteDirRecursively();
6465
File::getFilesFromDir();
6566
```

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ File::exists();
6060
File::delete();
6161
File::createDir();
6262
File::deleteEmptyDir();
63+
File::CopyDirRecursively();
6364
File::deleteDirRecursively();
6465
File::getFilesFromDir();
6566
```

src/File/File.php

+34
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,40 @@ public static function createDir($path) {
8787
return (!is_dir($path) && @mkdir($path, 0777, true));
8888
}
8989

90+
/**
91+
* Copy directory recursively.
92+
*
93+
* @since 1.1.4
94+
*
95+
* @param string $fromPath → path from copy
96+
* @param string $toPath → path to copy
97+
*
98+
* @return boolean
99+
*/
100+
public static function CopyDirRecursively($from, $to) {
101+
102+
if (!$path = self::getFilesFromDir($from)) { return false; }
103+
104+
self::createDir($to = rtrim($to, '/') . '/');
105+
106+
foreach($path as $file) {
107+
108+
if ($file->isFile()) {
109+
110+
if (!copy($file->getRealPath(), $to.$file->getFilename())) {
111+
112+
return false;
113+
}
114+
115+
} else if (!$file->isDot() && $file->isDir()) {
116+
117+
self::CopyDirRecursively($file->getRealPath(), $to . $path);
118+
}
119+
}
120+
121+
return true;
122+
}
123+
90124
/**
91125
* Delete empty directory.
92126
*

test.txt

Whitespace-only changes.

tests/File/Test/FileTest.php

+37-2
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,57 @@ public function testDeleteEmptyDirError() {
174174
}
175175

176176
/**
177-
* Test delete directory recursively.
177+
* Test copy directory recursively.
178178
*
179179
* @since 1.1.4
180180
*
181181
* @return void
182182
*/
183-
public function testDeleteDirRecursively() {
183+
public function testCopyDirRecursively() {
184184

185185
File::createDir(__DIR__ . '/test/test/test/');
186186

187187
touch(__DIR__ . '/test/test/test/test.txt');
188188

189+
$this->assertTrue(
190+
191+
File::copyDirRecursively(__DIR__ . '/test/', __DIR__ . '/copy/')
192+
);
193+
}
194+
195+
/**
196+
* Test copy missing directory recursively.
197+
*
198+
* @since 1.1.4
199+
*
200+
* @return void
201+
*/
202+
public function testCopyMissingDirRecursively() {
203+
204+
$this->assertFalse(
205+
206+
File::deleteDirRecursively(__DIR__ . '/unknown/')
207+
);
208+
}
209+
210+
/**
211+
* Test delete directory recursively.
212+
*
213+
* @since 1.1.4
214+
*
215+
* @return void
216+
*/
217+
public function testDeleteDirRecursively() {
218+
189219
$this->assertTrue(
190220

191221
File::deleteDirRecursively(__DIR__ . '/test/')
192222
);
223+
224+
$this->assertTrue(
225+
226+
File::deleteDirRecursively(__DIR__ . '/copy/')
227+
);
193228
}
194229

195230
/**

0 commit comments

Comments
 (0)