定制 fofx/helper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fofx/helper

最新稳定版本:v1.2.5

Composer 安装命令:

composer require fofx/helper

包简介

Helper functions.

README 文档

README

This is a library of PHP Helper functions.

The main class is Tracker, which allows you to create code sections to track script times. It can also track changes in memory, and bandwidth.

The Tracker class uses a Singleton pattern to ensure a single global instance.

Installation

To include this package in your project, run the following command in your project's root directory:

composer require fofx/helper

The default configuration file path config/helper.config.php.

Docs

Tracker Usage

Below is a basic example from the public/index.php file:

require_once __DIR__ . "/../vendor/autoload.php";

use FOfX\Helper;
use FOfX\Helper\Tracker;

$tracker = Tracker::getInstance();
Helper\get_diagnostics();

// Create three code sections
$sections = array('1', '2', '3');
foreach ($sections as $i) {
    Tracker::scriptTimer("Section" . $i, "start");
    Helper\rand_sleep(.1);
    Tracker::scriptTimer("Section" . $i, "end");
}

// Print the section timer information arrays
Tracker::trackerEnd();

AutoStart

Alternatively, in config/helper.config.php you can set autoStartTracker to true. This will auto-start the Tracker global Singleton.

Since this can cause problems in testing environments, this will only work if is_phpunit_environment() returns false.

If autoStartTracker is enabled, you do not need to do $tracker = Tracker::getInstance();. The global Singleton will be initialized automatically during autoloading.

Testing and Development

To run the PHPUnit test suite through composer:

composer test

To use PHPStan for static analysis:

composer phpstan

To run PHPStan on the tests folder:

composer phpstan tests

To use PHP-CS-Fixer for code style:

composer cs-fix

PHPUnit Notes

Some tests require a web server. You can either use PHP's built-in server:

php -S localhost:8000 -t public/

Or use Laragon (Windows), Apache, Nginx, etc.

Note:

get_windows_memory_info() (in src/memory.php) uses shell_exec() to call PowerShell. This can cause font glitches in legacy CMD (conhost.exe).

If you run PHPUnit through legacy CMD, it may switch fonts. Use Terminal for PHPUnit instead.

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-18