muqsit / preprocessor
用于准备生产代码的 PHP 库
dev-master
2024-06-15 02:48 UTC
Requires
- php: ^8.1
- nikic/php-parser: 5.0.*
- php-parallel-lint/php-console-color: ^1.0
- phpstan/phpstan: 1.11.*
- symfony/filesystem: ~6.4.0
Requires (Dev)
- phpunit/phpunit: ^10.3
- pocketmine/pocketmine-mp: 5.6.0
This package is auto-updated.
Last update: 2024-09-15 03:19:00 UTC
README
在生产环境中推送代码前,请注释掉调试代码。
快速入门
安装
使用 composer 安装库
composer require muqsit/preprocessor:dev-master
预处理 PHP 文件列表
require_once "src/proxy/Client.php"; require_once "src/proxy/Server.php"; require_once "src/proxy/Logger.php"; use muqsit\preprocessor\PreProcessor; use proxy\Logger; PreProcessor::fromPaths(["src/proxy/Client.php", "src/proxy/Server.php", "src/proxy/Logger.php"]) // files to preprocess ->commentOut(Logger::class, "debug") ->export("./preprocessed-src"); // preprocessed files written to ./preprocessed-src folder
结果
final class Client{
/** @var Logger */
private $logger;
public function onLogin(){
- $this->logger->debug("Client logged in");
+ /* $this->logger->debug("Client logged in ") */;
}
}
预处理 PHP 文件夹
require "vendor/autoload.php"; use muqsit\preprocessor\PreProcessor; use pocketmine\entity\Entity; use pocketmine\Player; use pocketmine\utils\Utils; PreProcessor::fromDirectory("./src") // searches for .php files recursively ->commentOut(Logger::class, "debug") ->commentOut(Utils::class, "testValidInstance") ->commentOut(Utils::class, "validateCallableSignature") ->commentOut(Client::class, "debugClientStatus") ->export("./preprocessed-src");
结果
final class Player extends Client implements LoggerHolder{
public function onJoin() : void{
- $this->getLogger()->debug("Player {$this->getUUID()} joined");
+ /* $this->getLogger()->debug("Player {$this->getUUID()} joined") */;
- $this->sendMessage("You joined the server"); $this->debugClientStatus();
+ $this->sendMessage("You joined the server"); /* $this->debugClientStatus() */;
}
public function registerQuitListener(Closure $listener) : void{
- Utils::validateCallableSignature(function(Player $player) : void{}, $listener);
+ /* Utils::validateCallableSignature(function(Player $player) : void{}, $listener) */;
}
}
使用的库
- nikic/PHP-Parser - 使用格式保留功能读取和写入节点
- phpstan/phpstan - 确定作用域内变量的类型、属性、方法等