brandon14 / fossabot-commander-laravel
Library to bridge the brandon14/fossabot-commander library to a Laravel application.
Requires
- php: ^7.4 || ^8.0
- brandon14/fossabot-commander: ^1.0.2
- guzzlehttp/guzzle: ^7.4.5
- guzzlehttp/psr7: ^2.4.5
- illuminate/console: ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- comcast/php-legal-licenses: ^1.2
- friendsofphp/php-cs-fixer: ^3.35
- mockery/mockery: ^1.6
- neronmoon/scriptsdev: ^0.1.9
- nunomaduro/phpinsights: ^2.9
- orchestra/testbench: ^6.38.0 || ^7.35.0 || ^8.15.0 || ^9.2.0
- pestphp/pest: ^1.23.1 || ^2.34.9
- pestphp/pest-plugin-laravel: ^1.4 || ^2.0
- phpmd/phpmd: ^2.14
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
- symfony/thanks: ^1.2.10
- vimeo/psalm: ^5.15
This package is auto-updated.
Last update: 2024-11-08 10:29:19 UTC
README
brandon14/fossabot-commander-laravel
Source code for brandon14/fossabot-commander-laravel
Table of Contents
- Requirements
- Purpose
- Installation
- Usage
- Standards
- Coverage
- Documentation
- Contributing
- Versioning
- Security Vulnerabilities
Requirements
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 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 function Brandon14\FossabotCommanderLaravel\fossabot_commander; 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 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; 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 fossabot:make: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-2024 Brandon Clothier