bfabio / publiccode-parser-php
Parse and validate publiccode.yml files
v1.4.1
2026-10-20 09:40 UTC
Requires
- php: ^8.0
- ext-ffi: *
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.5 || ^10.0
- squizlabs/php_codesniffer: ^3.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
PHP bindings for the libpubliccode 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 foreach ($publicCode->getWarnings() as $warning) { echo "- " . $warning . "\n"; } // Structured warnings include type, line, column, key and description. foreach ($publicCode->getValidationWarnings() as $warning) { echo $warning->getLine() . ': ' . $warning->getDescription() . "\n"; } } 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"; } // getErrors() remains available for backwards compatibility. foreach ($e->getValidationErrors() as $error) { echo $error->getLine() . ': ' . $error->getDescription() . "\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.