bfabio/publiccode-parser-php
最新稳定版本:v1.1.1
Composer 安装命令:
composer require bfabio/publiccode-parser-php
包简介
Parse and validate publiccode.yml files
README 文档
README
PHP bindings for the publiccode-parser-go library. Parse and validate publiccode.yml files in your PHP projects.
Installation
You can install the package via composer:
composer require bfabio/publiccode-parser-php
Supported Platforms
This library supports the following platforms:
- Linux x86-64 (AMD64) - Fully supported
- Linux ARM64 (aarch64) - Fully supported
- macOS Apple Silicon (ARM64/M1/M2/M3/M4) - Fully supported
Usage
Validation
use Bfabio\PublicCodeParser\Parser; $parser = new Parser(); if ($parser->isValid('/path/to/publiccode.yml')) { echo "publiccode.yml is valid!\n"; } else { echo "publiccode.yml is NOT valid!\n"; };
Parsing
use Bfabio\PublicCodeParser\Parser; use Bfabio\PublicCodeParser\Exception\ValidationException; use Bfabio\PublicCodeParser\Exception\ParserException; $parser = new Parser(); try { $publicCode = $parser->parseFile('/path/to/publiccode.yml'); // // or parse from string // $yamlContent = file_get_contents('/path/to/publiccode.yml'); // $publicCode = $parser->parse($yamlContent); echo "publiccode.yml file is valid!\n"; // Access parsed data echo $publicCode->getName(); // Get software name echo $publicCode->getDescription('it'); // Get Italian description echo $publicCode->getDescription('en'); // Get English description } catch (ValidationException $e) { echo "publiccode.yml file is NOT valid: " . $e->getMessage() . "\n"; // Get detailed validation errors foreach ($e->getErrors() as $error) { echo "- " . $error . "\n"; } } catch (ParserException $e) { echo "publiccode.yml file is NOT valid: " . $e->getMessage() . "\n"; }
Working with the PublicCode object
$parser = new Parser(); $publicCode = $parser->parseFile('/path/to/publiccode.yml'); if ($publicCode instanceof PublicCodeV0) { $name = $publicCode->getName(); $url = $publicCode->getUrl(); $landingUrl = $publicCode->getLandingUrl(); $descriptionIt = $publicCode->getDescription('it'); $descriptionEn = $publicCode->getDescription('en'); $allDescriptions = $publicCode->getAllDescriptions(); $platforms = $publicCode->getPlatforms(); // ['web', 'android', 'ios', etc.] } /* In the future, when v1 will be released */ /* else if ($publicCode instanceof PublicCodeV1) { ... } */
Advanced config
use Bfabio\PublicCodeParser\Parser; use Bfabio\PublicCodeParser\ParserConfig; // Create parser with custom config $options = new ParserConfig(); $options->setDisableNetwork(true); // Disable remote existance checks for URLs $parser = new Parser($options);
License
Licensed under the EUPL 1.2. Please see License File for more information.
统计信息
- 总下载量: 121
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-08-18