midnite81/badges

Render out package badges

v1.0.4 2018-07-17 20:48 UTC

This package is auto-updated.

Last update: 2024-12-05 20:29:01 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Build Coverage Status
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

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

Latest Stable Version

[![Latest Stable Version](https://poser.pugx.org/midnite81/badges/version)](https://packagist.org/packages/midnite81/badges)