-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use await-generator for I/O functions
- Loading branch information
nmtho
committed
Dec 2, 2023
1 parent
453e887
commit c07e7f9
Showing
8 changed files
with
134 additions
and
82 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
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
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
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,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of oh-my-pmmp. | ||
* | ||
* (c) thebigcrafter <[email protected]> | ||
* | ||
* This source file is subject to the GPL-3.0 license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace thebigcrafter\omp\helpers; | ||
|
||
use Closure; | ||
use Exception; | ||
use Generator; | ||
use SOFe\AwaitGenerator\Await; | ||
use Symfony\Component\Filesystem\Path; | ||
use thebigcrafter\omp\OhMyPMMP; | ||
use thebigcrafter\omp\Utils; | ||
use thebigcrafter\omp\utils\Filesystem; | ||
|
||
class PluginHelper | ||
{ | ||
public static function remove(string $name, bool $wipeData) : Generator | ||
{ | ||
return yield from Await::promise(function (Closure $resolve, Closure $reject) use ($name, $wipeData) { | ||
$pluginFilePath = Path::join(Utils::getPluginsFolder(), "$name.phar"); | ||
$pluginFolderPath = Path::join(Utils::getPluginsFolder(), $name); | ||
|
||
if (Filesystem::exists($pluginFilePath)) { | ||
Await::g2c(Filesystem::remove($pluginFilePath)); | ||
} elseif (Filesystem::exists($pluginFolderPath)) { | ||
Await::g2c(Filesystem::remove($pluginFolderPath)); | ||
} else { | ||
$reject(new Exception("Plugin not found")); | ||
} | ||
if ($wipeData) { | ||
$pluginDataFolder = Path::join(OhMyPMMP::getInstance()->getDataFolder(), "..", $name); | ||
Await::g2c(Filesystem::remove($pluginDataFolder)); | ||
} | ||
$resolve(true); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.