bestdefense-io/bd-sdk-php

BestDefense.io - PHP SDK

dev-master 2024-12-02 14:26 UTC

This package is auto-updated.

Last update: 2025-03-30 15:09:37 UTC


README

Welcome to the PHP SDK Package! This SDK allows you to easily interact with BestDefense.io Service API within your Laravel or Symfony applications. It provides seamless integration and autowiring, requiring minimal setup so you can focus on building your application.

Table of Contents

Installation

You can install the package via Composer. It's hosted on Packagist and can be included in your project by running:

composer require bestdefense-io/bd-sdk-php

Configuration

Laravel

  1. Publish the Configuration File

    After installing the package, publish the configuration file using Artisan:

    php artisan vendor:publish --provider="BestdefenseIo\BdSdkPhp\Providers\ApiServiceProvider" --tag="config"

    This command will publish a bestdefense_sdk.php configuration file to your application's config directory.

  2. Set Environment Variables

    Add your API credentials to your .env file:

    BESTDEFENSE_API_TOKEN=your-api-token
    BESTDEFENSE_ACCOUNT_ID=your-account-id

    Alternatively, you can set these values directly in the config/bestdefense_sdk.php file.

  3. Caching Configuration (Optional)

    If you cache your configuration, remember to refresh it after making changes:

    php artisan config:cache

Symfony

  1. Register the Bundle

    Add the bundle to your config/bundles.php file:

    return [
        // ...
        BestdefenseIo\BdSdkPhp\BdSDKBundle::class => ['all' => true],
    ];
  2. Configure Environment Variables

    Add your API credentials to your .env file:

    BESTDEFENSE_API_TOKEN=your-api-token
    BESTDEFENSE_ACCOUNT_ID=your-account-id
  3. Import Services Configuration

    Ensure that the package's services configuration is loaded by importing it in your config/services.yaml:

    # config/services.yaml
    imports:
        - { resource: '@BdSDKBundle/Resources/config/services.yaml' }

Usage

Once installed and configured, you can start using the SDK in your application.

Laravel Example

<?php

namespace App\Http\Controllers;

use BestdefenseIo\BdSdkPhp\ApiService;

class YourController extends Controller
{
    protected $apiService;

    public function __construct(ApiService $apiService)
    {
        $this->apiService = $apiService;
    }

    public function index()
    {
        $reports = $this->apiService->getRunningReports();

        // Process the data as needed
        return view('your_view', compact('reports'));
    }
}

Symfony Example

<?php

namespace App\Controller;

use BestdefenseIo\BdSdkPhp\ApiService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

class YourController extends AbstractController
{
    public function index(ApiService $apiService): Response
    {
        $reports = $apiService->getRunningReports();

        // Process the data as needed
        return $this->render('your_view.html.twig', [
            'reports' => $reports,
        ]);
    }
}

Methods

Below are some of the methods available in the ApiService class. Replace these with actual methods provided by your SDK.

  • getData(): Retrieves data associated with your account.
  • createResource(array $parameters): Creates a new resource.
  • updateResource(string $id, array $parameters): Updates an existing resource.
  • deleteResource(string $id): Deletes a resource.

Example Usage:

// Retrieve data
$data = $yourService->getData();

// Create a new resource
$newResource = $yourService->createResource([
    'name' => 'honeypot',
    'type' => 'medium', #small, medium, large
    'region' => 'us-east-2',
    'meta' => [
        'term' => '1 year',
        'config' => [ ... ]
    ],   
]);

// Update a resource
$updatedResource = $yourService->updateResource('resource-id', [
    'name' => 'Some New Updated Name',
]);

// Delete a resource
$yourService->deleteResource('resource-id');

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository on GitHub.
  2. Create a new branch for your feature or bugfix.
  3. Write tests for your changes.
  4. Submit a pull request with a clear description of your changes.

Please make sure all tests pass before submitting your pull request.

License

This package is open-sourced software licensed under the MIT license.

If you encounter any issues or have questions, feel free to open an issue on GitHub.

Happy coding! 🚀