Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 6b898a3

Browse files
committed
add symfony filesystem package - refactor delete commands
1 parent 562a962 commit 6b898a3

File tree

5 files changed

+11
-33
lines changed

5 files changed

+11
-33
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"symfony/console": "^2.7|^3.0",
2121
"symfony/process": "^2.7|^3.0",
2222
"symfony/finder": "^2.7|^3.0",
23+
"symfony/filesystem": "^2.7|^3.0",
2324
"stevebauman/log-reader": "^1.1",
2425
"phploc/phploc": "^3.0"
2526
}

src/Commands/FeatureDeleteCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function fire()
6262
if (!$this->exists($feature = $this->findFeaturePath($service, $title))) {
6363
$this->error('Feature class '.$title.' cannot be found.');
6464
} else {
65-
$this->deleteFile($feature);
65+
$this->delete($feature);
6666

6767
$this->info('Feature class <comment>'.$title.'</comment> deleted successfully.');
6868
}

src/Commands/JobDeleteCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public function fire()
6262
if (!$this->exists($job = $this->findJobPath($domain, $title))) {
6363
$this->error('Job class '.$title.' cannot be found.');
6464
} else {
65-
$this->deleteFile($job);
65+
$this->delete($job);
6666

6767
if (count($this->listJobs($domain)->first()) === 0) {
68-
$this->deleteDirectory($this->findDomainPath($domain));
68+
$this->delete($this->findDomainPath($domain));
6969
}
7070

7171
$this->info('Job class <comment>'.$title.'</comment> deleted successfully.');

src/Commands/ServiceDeleteCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function fire()
7777
if (!$this->exists($service = $this->findServicePath($name))) {
7878
$this->error('Service '.$name.' cannot be found.');
7979
} else {
80-
$this->deleteDirectory($service);
80+
$this->delete($service);
8181

8282
$this->info('Service <comment>'.$name.'</comment> deleted successfully.'."\n");
8383

src/Filesystem.php

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Lucid\Console;
1313

14+
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
15+
1416
/**
1517
* @author Abed Halawi <[email protected]>
1618
* @author Charalampos Raftopoulos <[email protected]>
@@ -62,41 +64,16 @@ public function createDirectory($path, $mode = 0755, $recursive = true, $force =
6264
}
6365

6466
/**
65-
* Delete an existing directory at the given path.
67+
* Delete an existing file or directory at the given path.
6668
*
6769
* @param string $path
6870
*
6971
* @return bool
7072
*/
71-
public function deleteDirectory($path)
73+
public function delete($path)
7274
{
73-
if ($handle = opendir($path)) {
74-
while (false !== ($file = readdir($handle))) {
75-
if ($file != '.' && $file != '..') {
76-
if (is_dir($path.'/'.$file)) {
77-
if (!@rmdir($path.'/'.$file)) {
78-
$this->deleteDirectory($path.'/'.$file.'/');
79-
}
80-
} else {
81-
@unlink($path.'/'.$file);
82-
}
83-
}
84-
}
85-
closedir($handle);
86-
87-
return @rmdir($path);
88-
}
89-
}
75+
$filesystem = new SymfonyFilesystem();
9076

91-
/**
92-
* Delete an existing file at the given path.
93-
*
94-
* @param string $path
95-
*
96-
* @return bool
97-
*/
98-
public function deleteFile($path)
99-
{
100-
return @unlink($path);
77+
$filesystem->remove($path);
10178
}
10279
}

0 commit comments

Comments
 (0)