Giter Club home page Giter Club logo

php-edlib-resource-kit-laravel's Introduction

Edlib Resource Kit integration for Laravel

codecov

Integrates Edlib Resource Kit with Laravel.

Requirements

  • PHP 8.0, 8.1, or 8.2
  • Laravel 8, 9, or 10
  • A PSR-18 compatible HTTP client (e.g. Guzzle 7)
  • PSR-17 compatible HTTP message factories (included with Guzzle 7)

Installation

composer require cerpus/edlib-resource-kit-laravel

If using Guzzle 6, you will also need some adapters:

composer require cerpus/edlib-resource-kit-laravel \
    http-interop/http-factory-guzzle \
    php-http/guzzle6-adapter

Configuration

First publish the configuration:

php artisan vendor:publish --provider="Cerpus\EdlibResourceKitProvider\EdlibResourceKitServiceProvider"

For asynchronous publishing, it is required to configure RabbitMQ. Edit config/edlib-resource-kit.php, or provide the expected environment variables to match your infrastructure.

If using cerpus/laravel-rabbitmq-pubsub, you can reuse its configuration:

<?php

return [
    'pub-sub' => Cerpus\PubSub\PubSub::class,
];

For synchronous publishing, it is sufficient to provide the following config:

<?php

return [
    'synchronous-resource-manager' => true,
];

Usage

Automatic publishing of resources

Given a model that implements EdlibResource:

use Cerpus\EdlibResourceKit\Contract\EdlibResource;
use Cerpus\EdlibResourceKitProvider\Traits\PublishToEdlib;
use Illuminate\Database\Eloquent\Model;

class Article extends Model implements EdlibResource
{
    use PublishToEdlib;
}

Or a model that implements ConvertableToEdlibResource:

use Cerpus\EdlibResourceKit\Contract\EdlibResource;
use Cerpus\EdlibResourceKitProvider\Contract\ConvertableToEdlibResource;
use Cerpus\EdlibResourceKitProvider\Traits\PublishToEdlib;
use Illuminate\Database\Eloquent\Model;

class Article extends Model implements EdlibResource
{
    use PublishToEdlib;

    public function toEdlibResource(): EdlibResource
    {
        // Return your own data object
        return new ArticleEdlibResource(/* ... */);
    }
}

With the PublishToEdlib trait used, Edlib will now be notified upon changes to the resource.

License

This package is released under the GNU General Public License 3.0. See the LICENSE file for more information.

php-edlib-resource-kit-laravel's People

Contributors

emmachughes avatar maxmoeschinger avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.