dbp / relay-verity-bundle
A validation bundle for the Relay API gateway
Installs: 53
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.1
- ext-curl: *
- ext-fileinfo: *
- ext-json: *
- api-platform/core: ^3.2
- dbp/relay-core-bundle: ^0.1.191
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/expression-language: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-client: ^6.4
- symfony/http-kernel: ^6.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.50
- phpstan/phpstan: ^1.10.59
- phpstan/phpstan-phpunit: ^1.3.16
- phpstan/phpstan-symfony: ^1.3.7
- phpunit/phpunit: ^10.1
- symfony/browser-kit: ^6.4
- symfony/monolog-bundle: ^3.10
- symfony/phpunit-bridge: ^7.0.4
- vimeo/psalm: ^5.22.2
README
The verity bundle provides an API for interacting with objects to validate (e.g. a PDF to validate against PDF/A-1b).
Bundle installation
You can install the bundle directly from packagist.org.
composer require dbp/relay-verity-bundle
Integration into the Relay API Server
- Add the bundle to your
config/bundles.php
in front ofDbpRelayCoreBundle
:
... Dbp\Relay\VerityBundle\DbpRelayVerityBundle::class => ['all' => true], Dbp\Relay\CoreBundle\DbpRelayCoreBundle::class => ['all' => true], ];
If you were using the DBP API Server Template as template for your Symfony application, then this should have already been generated for you.
- Run
composer install
to clear caches
Configuration
For this create config/packages/dbp_relay_verity.yaml
in the app with the following
content:
dbp_relay_verity: backends: pdfa: validator: 'Dbp\Relay\VerityConnectorVerapdfBundle\Service\PDFAValidationAPI' profiles: archive: name: 'Check PDFs for archiving complacency' rule: 'pdfa.validity == true && pdfa_b2.validity == true' checks: pdfa: backend: 'pdfa' flavour: 'auto' pdfa_b2: backend: 'pdfa' flavour: 'b2'
There are two sections in this bundle configuration:
backends
for the configuration of backend servicesprofiles
for the checks available via the API
In this example, a backend with the name pdfa
is implemented by the PHP class PDFAValidationAPI
.
There is also a profile defines with the name archive
. A profile performs all checks
and stores the results (the validity
and also errors
) in a variable named like the check, here pdfa
and pdfa_b2
. Each check has the name of its backend
to use and a flavour
to set the type of check to perform.
The results of all checks are then evaluated by the rule
of the profile. The syntax of the rule is almost PHP syntax, but before any function is available, they must be registered first!
If you were using the DBP API Server Template as template for your Symfony application, then the configuration file should have already been generated for you.
For more info on bundle configuration see https://symfony.com/doc/current/bundles/configuration.html.
Development & Testing
- Install dependencies:
composer install
- Run tests:
composer test
- Run linters:
composer run lint
- Run cs-fixer:
composer run cs-fix
Bundle dependencies
Don't forget you need to pull down your dependencies in your main application if you are installing packages in a bundle.
# updates and installs dependencies of dbp/relay-verity-bundle
composer update dbp/relay-verity-bundle
Scripts
Error codes
/verity/reports
POST
/verity/reports/{identifier}
GET
Roles
This bundle needs the role ROLE_SCOPE_VALIDATION
assigned to the user to get permissions to fetch data.
To create a new submission entry the Symfony role ROLE_SCOPE_VALIDATION-POST
is required.
Events
To extend the behavior of the bundle the following event is registered:
VerityRequestEvent
This event allows you to send a request for validation internally.
See tests/EventSubscriberTest.php
as an example.
VerityEvent
This event allows you to get notifications for (all) verity reports.
An event subscriber receives a Dbp\Relay\VerityBundle\Event\VerityEvent
instance:
<?php namespace App\EventSubscriber; use Dbp\Relay\VerityBundle\Event\VerityEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class VerityEventSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ VeritasEvent::NAME => 'onVerity', ]; } public function onVerity(VeritasEvent $event) { $report = $event->getReport(); // TODO: extract relevant information $valid = $report->isValid(); } }