{"id":19502186,"url":"https://github.com/scarlettsamantha/lshw-parser","last_synced_at":"2026-01-08T09:49:55.100Z","repository":{"id":249940118,"uuid":"832104391","full_name":"ScarlettSamantha/lshw-parser","owner":"ScarlettSamantha","description":"A PHP library to parse and analyze XML output from the lshw command, providing an easy way to extract and query detailed hardware information on Linux systems.","archived":false,"fork":false,"pushed_at":"2024-08-01T04:40:24.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T09:51:13.683Z","etag":null,"topics":["linux","lshw","php8","system-info","xml"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScarlettSamantha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-22T11:10:24.000Z","updated_at":"2025-01-18T04:19:44.000Z","dependencies_parsed_at":"2024-07-24T09:02:14.267Z","dependency_job_id":null,"html_url":"https://github.com/ScarlettSamantha/lshw-parser","commit_stats":null,"previous_names":["scarlettsamantha/lshw-parser"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarlettSamantha%2Flshw-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarlettSamantha%2Flshw-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarlettSamantha%2Flshw-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarlettSamantha%2Flshw-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScarlettSamantha","download_url":"https://codeload.github.com/ScarlettSamantha/lshw-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246662900,"owners_count":20813802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","lshw","php8","system-info","xml"],"created_at":"2024-11-10T22:15:32.781Z","updated_at":"2026-01-08T09:49:55.073Z","avatar_url":"https://github.com/ScarlettSamantha.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LSHW XML Parser\n\nThis PHP library parses XML output from the lshw command to extract hardware information on Linux systems.\n\n## Features\n\n- Parse lshw XML output.\n- Retrieve system memory, CPU, storage device, and network interface information.\n- Dynamic filtering of nodes based on properties.\n- Customizable filtering logic with callable functions.\n- Skiphubs can be enabled to skip hub/bridge objects.\n- \\\u003e85% code coverage.\n\n## Installation\n\nInstall the library using Composer:\n\n`sh composer require scarlett/lshw-parser`\n\n## Usage\n\nParsing the XML Output\n\n```php\nuse Scarlett\\LshwParser\\Parser;\n\n$xmlContent = file_get_contents('path/to/lshw-output.xml');\n$parser = new Parser($xmlContent);\n\n// Get system memory information\n$memory = $parser-\u003egetSystemMemory();\necho $memory-\u003egetProperty('description')-\u003egetFirstValue();\n\n// Get CPU information\n$cpuInfo = $parser-\u003egetCpuInfo();\necho $cpuInfo-\u003egetProperty('vendor')-\u003egetFirstValue();\n```\n\nFiltering Nodes by Properties\n\n```php\nuse Scarlett\\LshwParser\\Parser;\n\n$xmlContent = file_get_contents('path/to/lshw-output.xml');\n$parser = new Parser($xmlContent);\n\n// Filter nodes with AND logic\n$results = $parser-\u003eparseByProperties(['class' =\u003e 'processor', 'vendor' =\u003e 'Intel Corp.'], 'and');\nforeach ($results as $result) {\n    echo $result-\u003egetProperty('description')-\u003egetFirstValue();\n}\n\n// Filter nodes with OR logic\n$results = $parser-\u003eparseByProperties(['class' =\u003e 'processor', 'vendor' =\u003e 'AMD'], 'or');\nforeach ($results as $result) {\n    echo $result-\u003egetProperty('description')-\u003egetFirstValue();\n}\n```\n\nCustom Filtering with Callables\n\n```php\nuse Scarlett\\LshwParser\\Parser;\n\n$xmlContent = file_get_contents('path/to/lshw-output.xml');\n$parser = new Parser($xmlContent);\n\n$results = $parser-\u003esearchNodesByFilter(function($properties) {\n    return isset($properties['vendor']) \u0026\u0026 $properties['vendor'] === 'Intel Corp.';\n});\n\nforeach ($results as $result) {\n    echo $result-\u003egetProperty('description')-\u003egetFirstValue();\n}\n```\n\n## Skiphubs\n\nThe 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:\n\n- `/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\".\n- `/(pci(e)?\\s*bridge)/i`: Matches \"pci bridge\", \"pcie bridge\".\n- `/(isa\\s*bridge)/i`: Matches \"isa bridge\".\n- `/hub/i`: Matches \"hub\".\n\nSetting the skipHubs flag to true enables this functionality, ensuring that such nodes are excluded from the results.\nTo enable `public function __construct(string $xmlContent, bool $skipHubs = true)` or when instanced `setSkipHubs(bool) -\u003e void`.\n\n## Running Tests\n\nThe project uses PHPUnit for unit testing. To run the tests, use the following command:\n\n`./vendor/bin/phpunit .`\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request for any changes.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarlettsamantha%2Flshw-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscarlettsamantha%2Flshw-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarlettsamantha%2Flshw-parser/lists"}