phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 431 forks source link

[Proposal] Plugins #63

Closed adam-paterson closed 8 years ago

adam-paterson commented 9 years ago

Context

I started building a similar library because I forgot this existed. I wanted to have a solution similar to Rocketeer which allowed people to create a directory in their project .githooks which contained a php config file with the tasks they wanted to do with particular git commands. The idea being companies can create their own plugins to do particular tasks. post-commit for example could post to a Slack channel, etc.

Misc Tasks

It would allow people to easily create their own tasks with classes or callbacks. For example I could have a task that did a test merge with the parent branch to check for an conflicts before I push.

Proposal

I don't want to reinvent the wheel and release a new library where 80% of the work is achieved with GrumPHP. But to make GrumPHP work how I'd like I'd need to refactor a lot of the structure. But it would allow users to specify only the plugins they required and have it all managed through composer as well as other tasks which might not have a library around them.

Any thoughts?

veewee commented 9 years ago

First of all I haven't used Rocketeer before, so I don't know exactly what you are trying to accomplish.

Next to that, it is allready possible to configure your own Tasks / Listeners to GrumPHP by adding services to the grumphp.yml file:

https://github.com/phpro/grumphp#custom-tasks https://github.com/phpro/grumphp#events

I can imagine that this part is not the easiest extension point for developers. Another option that comes to mind is to create extensions like phpspec / behat does:

http://phpspec.readthedocs.org/en/latest/cookbook/extensions.html https://github.com/phpspec/phpspec/blob/master/src/PhpSpec/Extension/ExtensionInterface.php

The idea is that a package can contain an extension to GrumPHP. The application will be able to hook in to the service container. The extension needs to be configured in the grumphp.yml file. During the creation of the service container, the extension will be loaded and it wil hook in it's custom tasks / listeners / custom console commands / .... This will make it possible to reuse company specific tasks or create tasks per project. It is also a possibility to create a new task that will run a php callback in the future.

However, The main idea is that the core package contains as much general tasks as possible.

About the git hooks: Currently there are 2 git hooks configured: pre-commit, commit-message. Following tasks need to be done to register a new hook:

Maybe we can simplify this flow in the future.

Some questions: What is your definition of this plugin based system? Does this result in a grumphp-pre-commit plugin or plugins with specific tasks (e.g: grumpgp-frontend--tasks-plugin)? How do you see the integration? You say you started a similar project. Can you give me a link. Maybe we can use some of your ideas?