cabag / ext-backend-progress
添加一个工具栏项,显示长时间运行的任务进度。
2.0.1
2020-11-17 09:59 UTC
Requires
- php: 7.2
- typo3/cms-backend: ^10.4.6
- typo3/cms-core: ^10.4.6
- typo3/cms-extbase: ^10.4.6
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-25 21:48:05 UTC
README
关于
本扩展基于cabag的boiler_plate扩展。
本扩展的目的是为TYPO3后台提供一个进度条,作为工具栏项,以便在切换模块时仍能跟踪长时间运行的任务。
实现此功能的扩展有两种显示进度的方法
- 作为一个进度圈,中间显示进度百分比
- 作为一个进度条,带有额外的进度标签,允许在长时间运行的任务上提供额外信息,在这种情况下,进度条可能用于显示所有任务的进度。
这样的长时间运行的任务现在必须作为任务实现,但将来可能作为Websocket调用实现。
对于开发者
为了简化实现工作,扩展提供了BackendProgressAwareTrait。
初始化
请参阅examples/Command/ExampleProgressBarCommand.php以获取完整示例
<?php namespace Cabag\BackendProgress\Examples\Command; use Cabag\BackendProgress\Progress\BackendProgressAwareTrait; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ExampleProgressBarCommand extends Command { use BackendProgressAwareTrait; /** * Configure command */ public function configure() { $this->registerTaskInProgress('your_awesome_task', 3); parent::configure(); // TODO: Change the autogenerated stub } /** * @param InputInterface $input * @param OutputInterface $output * @return int|void */ public function execute(InputInterface $input, OutputInterface $output) { // Start the task $this->startTask(); // Go to the next step $this->nextStep(); // Update the step label $this->updateStepLabel('Executing part one of this step'); $array = []; // Do some more for find $array // ... // Update in a loop $amount = count($array); foreach ($array as $key => $value) { $this->updateStepLabel(sprintf('Update part %s from %d', $key, $amount)); // Do some processing } // Go to the next step and update label $this->nextStep('Label for whole task (can be updated)'); $this->nextStep('This is the last step'); // If you execute nextStep too often, the total amount of steps will raise and the completion will stay at // steps-1 until endTask is called $this->nextStep('An additional step'); // End the task $this->endTask(); // Set up how long a task should stay in the queue after finishing (default 60 seconds) $this->cleanupTask(30); // Negative values are put into absolute values, so this is equivalent $this->cleanupTask(-30); } }
请参阅examples/Command以获取源代码。
不要忘记删除所有不需要的文件和文件夹。
静态分析
Boilerplate扩展具有多个静态代码分析工具。目前包括
- PHPStan (https://github.com/phpstan/phpstan)
- phpcs (https://github.com/squizlabs/PHP_CodeSniffer)
- Gitlab SAST (https://docs.gitlab.com/ee/user/application_security/sast/)
所有这些工具都配置为在您的本地环境或Gitlabs CI中直接运行。如果您只是克隆了boilerplate,则默认启用所有工具。如果您想在Gitlab中禁用它们,根据您要删除的测试,从gitlab-ci.yml中删除以下行(以- composer 开头)
static_analysis:
stage: static_analysis
script:
- composer phpstan
- composer phpcs
示例:如果您想在部署中删除phpcs的分析,请删除行 - composer phpcs
如果您想删除Gitlab SAST,请删除包含- template: Security/SAST.gitlab-ci.yml的include(不推荐)
如何在您的扩展中使用静态分析功能?
PHPStan
- 将以下内容添加到您的 .editorconfig 文件中(如果尚不存在)
# neon-Files
[*.{neon,neon.dist}]
indent_style = tab
indent_size = 2
- 将 phpstan.neon.dist 文件复制到您的扩展中
- 如果您想将静态分析集成到CI中,请复制 gitlab-ci.yml 文件(或仅复制所需部分)。如果您只想在本地系统上执行静态分析,请跳过此步骤。
- 确保从gitlab-ci中删除您不想在部署期间执行的脚本
- 将以下内容添加到您的 .gitignore 文件中(如果尚不存在)
# TYPO3 and vendors
/vendor
/public
composer.lock
# Custom configuration files for testing
phpstan.neon
- 将以下两个部分添加到您的 composer.json 文件中(如果尚不存在)。如果这些部分已存在,请仅添加其内容
"require-dev": {
"phpstan/phpstan": "*",
"typo3/cms-core": "^10.4.6",
"typo3/cms-extbase": "^10.4.6"
},
"scripts": {
"phpstan": "phpstan analyse"
}
如果核心已在 require {} 部分中要求,请从 require-dev 中删除它。要找出还需要哪些其他核心包,请扫描您的类中的使用语句,以了解所需的核心包。
- 如果您在扩展中使用了核心类(您应该使用!),可能需要向 require-dev 中添加更多 typo3/cms-* 依赖项。
- 执行
composer update - 更新完成后,您可以使用
composer phpstan来检查您的扩展中的错误。 - 小贴士:在您推送之前,请在本地系统上执行此操作。
phpcs
- 将以下内容添加到您的 .editorconfig 文件中(如果尚不存在)
# xml-Files
[*.{xml,xml.dist}]
indent_style = tab
- 将文件 phpcs.xml.dist 复制到您的扩展中
- 如果您想将静态分析集成到CI中,请复制 gitlab-ci.yml 文件(或仅复制所需部分)。如果您只想在本地系统上执行静态分析,请跳过此步骤。
- 确保从gitlab-ci中删除您不想在部署期间执行的脚本
- 将以下内容添加到您的 .gitignore 文件中(如果尚不存在)
# TYPO3 and vendors
/vendor
/public
composer.lock
# Custom configuration files for testing
phpcs.xml
- 将以下两个部分添加到您的 composer.json 文件中(如果尚不存在)。如果这些部分已存在,请仅添加其内容
"require-dev": {
"squizlabs/php_codesniffer": "*",
"typo3/cms-core": "^10.4.6",
"typo3/cms-extbase": "^10.4.6"
},
"scripts": {
"phpcs": "phpcs"
}
- 如果您在扩展中使用了核心类(您应该使用!),可能需要向 require-dev 中添加更多 typo3/cms-* 依赖项。
- 执行
composer update - 更新完成后,您可以使用
composer phpcs来检查您的扩展中的错误。如果 phpcs 发现错误,它可能能够修复其中的一些。如果它建议修复错误,请运行vendor/bin/phpcbf - 小贴士:在您推送之前,请在本地系统上执行此操作。