PHP code example of eilander / gateway

1. Go to this page and download the library: Download eilander/gateway library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eilander / gateway example snippets



'providers' => [
    ...
    Eilander\Gateway\Providers\GatewayServiceProvider::class,
],



   "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "Eilander\\Gateway\\": "../library/eilander/gateway/src/"
        }
    },

#!json

composer dump-autoload

 

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Gateways\ProductGateway as Gateway;

class ProductController extends Controller
{
    /**
     * @var VodafoneGateway
     */
    protected $gateway;

    public function __construct(Gateway $gateway){
        $this->gateway = $gateway;
    }

    public funcion create() {
        return $this->gateway->createProduct();
    }

    ....
}

 

namespace  App\Gateways;

use Illuminate\Http\Request;

class TestGateway {

    public function __construct(Request $request) 
    {
        $this->request = $request;
    }

    public function createProduct() 
    {
        // some validation
        ...
        // screate new product
        $product = App\Product::create($this->request->all());
    }
}

use League\Fractal\TransformerAbstract;

class PostTransformer extends TransformerAbstract
{
    public function transform(\Post $post)
    {
        return [
            'id'      => (int) $post->id,
            'title'   => $post->title,
            'content' => $post->content
        ];
    }
}



namespace  App\Gateways\Eloquent;

use App\Gateways\Eloquent\Contracts\GebruikerGateway as Gateways;
use App\Repositories\Eloquent\Contracts\GebruikerRepository as Repository;
use App\Validators\GebruikerValidator as Validator;
use Eilander\Gateway\Eloquent\EloquentGateway;
use App\Presenters\GebruikerPresenter as Presenter;

/**
 * Class FruitRepository
 */
class GebruikerGateway extends EloquentGateway implements Gateways {
{

    ...

    public function presenter()
    {
        return Presenter::class;
    }
}

$posts = $this->gateway->skipPresenter()->all();