midnite81 / badges
Render out package badges
Installs: 266
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 3
Open Issues: 0
pkg:composer/midnite81/badges
Requires (Dev)
- illuminate/support: ^5.5|^5.6
- phpunit/phpunit: ^6|^7
- satooshi/php-coveralls: 1.0.*
- symfony/var-dumper: ^3.4|^4.0|^4.1
README
A PHP package to render out package badges
Installation
This package requires PHP 5.6+
To install through composer include the package in your composer.json.
"midnite81/badges": "^1.0.0"
Run composer install or composer update to download the dependencies or you can
run composer require midnite81/badges.
Badges Supported
| Type | Example |
|---|---|
| Latest Stable | |
| Total Downloads | |
| Latest Unstable | |
| Licence | |
| Build | |
| Coverage | |
| Gitter | |
| StyleCI | (Image Coming soon) |
| Scrutinizer | (Image Coming soon) |
Over time support for other badges will be added. You can create your own templates which extend
Midnite81\Badges\Type\BadgeType and can be passed through the $badges->get(MyClass::class) method. More
documentation on adding your own templates will be added later.
Example Usage
Firstly, you need to create an instance of badges.
use Midnite81\Badges\Badges; $badges = new Badges($attributes); // or $badges = Badges::create($attributes);
You'll notice that a variable of $attributes is passed on construction. The attributes are what the package will use to translate the template. By default we're only going to pass the following attributes as they are needed for the supported badges. Obviously update the above attributes to suit your own needs.
$attributes = [
'$PACKAGE_NAME$' => 'midnite81/badges', // Your GitHub package repo name
'$STYLE_CI$' => 'repoNumber', // Your StyleCi repo number
'$GITTER_ROOM$' => 'room-name' // Your gitter room name
];
Once the class is instantiated, you then need to select the type of badge you want.
$myBadge = $this->latestStableVersion();
This will return you a Writer object, which you can call ->toHtml() or ->toMarkdown on for the final rendering
of the badge. The default _toString method will return the html version.
So all in all;
use Midnite81\Badges\Badges;
$badges = Badges::create(['$PACKAGE_NAME$' => 'midnite81/badges']);
echo $badges->latestStableVersion()->toMarkdown();
will output
[](https://packagist.org/packages/midnite81/badges)