Skip to content

brandon14/fossabot-commander-laravel

Repository files navigation

Packagist PHP Version

GitHub Workflow Status (with event) Code Climate maintainability Codecov GitHub

GitHub issues GitHub closed issues GitHub pull requests GitHub closed pull requests

GitHub release (with filter) GitHub commit activity (branch) GitHub last commit (by committer)

brandon14/fossabot-commander-laravel

Table of Contents

  1. Requirements
  2. Purpose
  3. Installation
  4. Usage
  5. Standards
  6. Coverage
  7. Documentation
  8. Contributing
  9. Versioning
  10. Security Vulnerabilities

Requirements

Dependency Version
php ^7.4 || ^8.0
brandon14/fossabot-commander ^1.0.0
guzzlehttp/guzzle ^6.5.8 || ^7.4.5
illuminate/console ^8.0 || ^9.0 || ^10.0
illuminate/support ^8.0 || ^9.0 || ^10.0

Purpose

This is a simple wrapper for the fossabot-commander package for Laravel. This allows for easy integration into a Laravel project.

This library provides all the bindings for the Laravel IoC container to set up the fossabot-commander library, and also includes a helper function fossabot_commander() to get the commander class from the container. It also provides a FossabotCommander facade. The package is bound to the container under the Brandon14\FossabotCommander\Contracts\FossabotCommander interface, and also as the alias fossabot-commander.

Installation

composer require brandon14/fossabot-commander-laravel

Usage

You will first need to get the custom API token from the request header. It will be in the x-fossabot-customapitoken header.

For a simple command in Laravel:

// FooCommand.php
<?php

declare(strict_types=1);

namespace App\Fossabot\Commands;

use Brandon14\FossabotCommander\FossabotCommand;
use Brandon14\FossabotCommander\Contracts\Context\FossabotContext;

class FooCommand extends FossabotCommand
{
    /**
     * {@inheritDoc}
     */
    public function getResponse(?FossabotContext $context = null) : string
    {
        return 'Hello chat!';
    }
}

// In some Laravel Controller
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Fossabot\Commands\FooCommand;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Brandon14\FossabotCommander\Contracts\FossabotCommander;

class Controller extends BaseController
{
    use AuthorizesRequests;
    use ValidatesRequests;

    private FossabotCommander $commander;

    public function __construct(FossabotCommander $commander)
    {
        $this->commander = $commander;
    }

    public function fooCommand(Request $request): string
    {
        // Get Fossabot API token.
        $apiToken = $request->header('x-fossabot-customapitoken');

        // Invoke command.
        return $this->commander->runCommand(new FooCommand(), $apiToken);
    }
}

To use the facade:

<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Fossabot\Commands\FooCommand;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests;
    use ValidatesRequests;

    public function fooCommand(Request $request): string
    {
        // Get Fossabot API token.
        $apiToken = $request->header('x-fossabot-customapitoken');

        return fossabot_commander()->runCommand(new FooCommand(), $apiToken);
    }
}

To use the helper:

<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Fossabot\Commands\FooCommand;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Brandon14\FossabotCommanderLaravel\Facades\FossabotCommander;

class Controller extends BaseController
{
    use AuthorizesRequests;
    use ValidatesRequests;
    
    public function fooCommand(Request $request): string
    {
        // Get Fossabot API token.
        $apiToken = $request->header('x-fossabot-customapitoken');

        return FossabotCommander::runCommand(new FooCommand(), $apiToken);
    }
}

To make commands via the Artisan command:

php artisan make:fossabot-command NameOfCommand

Standards

We strive to meet the PSR-12 coding style for PHP projects, and enforce our coding standard via the php-cs-fixer linting tool. Our ruleset can be found in the .php-cs-fixer.dist.php file.

Coverage

The latest code coverage information can be found via Codecov. We strive to maintain 100% coverage across the entire Flysystem adapter, so if you are contributing, please make sure to include tests for new code added.

Documentation

Documentation to this project can be found here.

Contributing

Got something you want to add? Found a bug or otherwise bad code? Feel free to submit pull requests to add in new features, fix bugs, or clean things up. Just be sure to follow the Code of Conduct and Contributing Guide, and we encourage creating clean and well described pull requests if possible.

If you notice an issues with the library or want to suggest new features, feel free to create issues appropriately using the issue tracker.

In order to run the tests, it is recommended that you sign up for a Cloudinary account (it's a free service), and use that account to run the full integration tests. In order to do that, you will need to copy .env.example to .env and fill in the variables using the details in your account. The integration tests will use random prefixed directories and clean everything up before and after the tests.

Versioning

brandon14/fossabot-commander-laravel uses semantic versioning that looks like MAJOR.MINOR.PATCH.

Major version changes will include backwards-incompatible changes and may require refactoring of projects using it. Minor version changes will include backwards-compatible new features and changes and will not break existing usages. Patch version changes will include backwards-compatible bug and security fixes, and should be updated as soon as possible.

Security Vulnerabilities

If you discover a vulnerability within this package, please email Brandon Clothier via brandon14125@gmail.com. All security vulnerabilities will be promptly addressed.

This code is released under the MIT license.

Copyright © 2023 Brandon Clothier

X (formerly Twitter) URL

X (formerly Twitter) Follow

About

Library to bridge the brandon14/fossabot-commander library to a Laravel application.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages