satispress
satispress copied to clipboard
Allow modification of package output.
I want to add some metadata to a package, such as:
- Adding tags/keywords,
- Adding php version requirements,
- Amend the description.
Adding an apply_filters call allows developers to extend satispress capabilities.
@NielsdeBlaauw It's actually possible to modify most of the behavior in SatisPress by extending or replacing the dependencies in the container. In this case, you can accomplish the same thing by doing something like this:
class MyRepositoryTransformer extends \SatisPress\Transformer\ComposerRepositoryTransformer {
protected function transform_item( Package $package ): array {
$data = parent::transform_item( $package );
// Filter data here.
return $data;
}
}
// Replace the Composer repository transformer dependency in the container.
add_action( 'satispress_compose', function( $plugin, $container ) {
$container['transformer.composer_repository'] = function( $container ) {
return new MyRepositoryTransformer(
$container['transformer.composer_package'],
$container['release.manager'],
$container['version.parser'],
$container['logger']
);
};
}, 10, 2 );