-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow modification of package output. #187
Comments
@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 ); |
Hi @bradyvercher, seeing that #188 didn't make it into https://github.com/cedaro/satispress/releases/tag/v2.0.0, I wanted to bump here once more because I still think adding this filter to SatisPress would be a no-brainer while being helpful for cases like this (from #188 (review)): add_filter(
'satispress_package_repository_item',
static function(array $composerData, \SatisPress\Package $package): array {
if ($package->get_name() !== 'satispress/foo') {
return $composerData;
}
return array_map(function($data) {
$data['replace'] = [
'bar/foo' => 'self.version'
];
return $data;
}, $composerData);
},
10,
2
); This works just fine and is much less code than the effort required to achieve this with Thank you very much! |
@tyrann0us While I can appreciate that it is less code, I tried not to introduce external APIs like |
I want to add some metadata to a package, such as:
Adding an
apply_filters
call allows developers to extend satispress capabilities.The text was updated successfully, but these errors were encountered: