satispress icon indicating copy to clipboard operation
satispress copied to clipboard

Allow modification of package output.

Open NielsdeBlaauw opened this issue 3 years ago • 3 comments

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 avatar Aug 30 '22 14:08 NielsdeBlaauw

@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 );

bradyvercher avatar Nov 04 '22 16:11 bradyvercher