-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from universityofadelaide/delete-install-php
Add in delete function as part of the file scaffolding.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UniversityOfAdelaide\ShepherdDrupalScaffold\tasks; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class DeleteFile implements TaskInterface | ||
{ | ||
protected Filesystem $filesystem; | ||
protected string $path; | ||
protected string $filename; | ||
|
||
public function __construct(Filesystem $filesystem, string $path, string $filename) | ||
{ | ||
$this->filesystem = $filesystem; | ||
$this->path = $path; | ||
$this->filename = $filename; | ||
} | ||
|
||
public function getFilename(): string | ||
{ | ||
return $this->filename; | ||
} | ||
|
||
/** | ||
* @throws \Symfony\Component\Filesystem\Exception\FileNotFoundException | ||
* When original file doesn't exist | ||
* @throws \Symfony\Component\Filesystem\Exception\IOException | ||
* When copy fails | ||
*/ | ||
public function execute(): void | ||
{ | ||
// Skip copying files that already exist at the destination. | ||
if (!$this->filesystem->exists($this->path . '/' . $this->filename)) { | ||
return; | ||
} | ||
|
||
$this->filesystem->remove( | ||
$this->path . '/' . $this->filename | ||
); | ||
} | ||
} |