scarlett/lshw-parser
Composer 安装命令:
composer require scarlett/lshw-parser
包简介
A simple php lshw parser with no non ext dependencies.
README 文档
README
This PHP library parses XML output from the lshw command to extract hardware information on Linux systems.
Features
- Parse lshw XML output.
- Retrieve system memory, CPU, storage device, and network interface information.
- Dynamic filtering of nodes based on properties.
- Customizable filtering logic with callable functions.
- Skiphubs can be enabled to skip hub/bridge objects.
- >85% code coverage.
Installation
Install the library using Composer:
sh composer require scarlett/lshw-parser
Usage
Parsing the XML Output
use Scarlett\LshwParser\Parser; $xmlContent = file_get_contents('path/to/lshw-output.xml'); $parser = new Parser($xmlContent); // Get system memory information $memory = $parser->getSystemMemory(); echo $memory->getProperty('description')->getFirstValue(); // Get CPU information $cpuInfo = $parser->getCpuInfo(); echo $cpuInfo->getProperty('vendor')->getFirstValue();
Filtering Nodes by Properties
use Scarlett\LshwParser\Parser; $xmlContent = file_get_contents('path/to/lshw-output.xml'); $parser = new Parser($xmlContent); // Filter nodes with AND logic $results = $parser->parseByProperties(['class' => 'processor', 'vendor' => 'Intel Corp.'], 'and'); foreach ($results as $result) { echo $result->getProperty('description')->getFirstValue(); } // Filter nodes with OR logic $results = $parser->parseByProperties(['class' => 'processor', 'vendor' => 'AMD'], 'or'); foreach ($results as $result) { echo $result->getProperty('description')->getFirstValue(); }
Custom Filtering with Callables
use Scarlett\LshwParser\Parser; $xmlContent = file_get_contents('path/to/lshw-output.xml'); $parser = new Parser($xmlContent); $results = $parser->searchNodesByFilter(function($properties) { return isset($properties['vendor']) && $properties['vendor'] === 'Intel Corp.'; }); foreach ($results as $result) { echo $result->getProperty('description')->getFirstValue(); }
Skiphubs
The skipHubs feature(default:OFF) in the Parser class allows for the skipping of nodes identified as hubs during parsing. The following regex patterns are used to match node descriptions:
/usb\s*(hub|2(\.0)?\s*hub|3(\.0)?\s*hub)/i: Matches "usb hub", "usb2 hub", "usb2.0 hub", "usb3 hub", "usb3.0 hub"./(pci(e)?\s*bridge)/i: Matches "pci bridge", "pcie bridge"./(isa\s*bridge)/i: Matches "isa bridge"./hub/i: Matches "hub".
Setting the skipHubs flag to true enables this functionality, ensuring that such nodes are excluded from the results.
To enable public function __construct(string $xmlContent, bool $skipHubs = true) or when instanced setSkipHubs(bool) -> void.
Running Tests
The project uses PHPUnit for unit testing. To run the tests, use the following command:
./vendor/bin/phpunit .
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any changes.
License
This project is licensed under the MIT License.
scarlett/lshw-parser 适用场景与选型建议
scarlett/lshw-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「parser」 「linux」 「ubuntu」 「hardware」 「information」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 scarlett/lshw-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scarlett/lshw-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 scarlett/lshw-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Brotli binary provided by google/brotli and compiled for amd64
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Advanced local development experience for Linux.
An MT940 bank statement parser for PHP
Laravel integration for the jsonapi.org parser
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-24