2017 © Pedro Peláez
 

library pheign

Feign implement for php

image

airmanbzh/pheign

Feign implement for php

  • Wednesday, August 23, 2017
  • by Airmanbzh
  • Repository
  • 1 Watchers
  • 2 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Pheign Library

Pheign library makes writing php http client easier., (*1)

(inspired by OpenFeign/feign), (*2)

Installation

Library can be installed with Composer. Installation is quite easy:, (*3)

$ composer require airmanbzh/pheign

Composer will install the library to your project's vendor/airmanbzh/pheign directory., (*4)

Usage

To make a request, you have to :, (*5)

Create a request class

<?php
namespace test;

use pheign\annotation\method\GET;
use pheign\annotation\Options;
use pheign\annotation\Pheign;
use pheign\annotation\Target;

class Github
{
    /**
     * @Pheign
     *
     * @GET
     * @Target("/users/{owner}/repos")
     *
     * @Options(CURLOPT_SSL_VERIFYHOST=0, CURLOPT_SSL_VERIFYPEER=0)
     */
    public function repositories($owner){}

    /**
     * @Pheign
     *
     * @GET
     * @Target("/repos/{owner}/{repo}")
     *
     * @Options(CURLOPT_SSL_VERIFYHOST=0, CURLOPT_SSL_VERIFYPEER=0)
     */
    public function repositoryInformations($owner, $repo){}
}

Make a request

// Initialisation de pheign
$pheign = \pheign\builder\Pheign::builder()->target(\test\Github::class, 'https://api.github.com');

$result = $pheign->repositories('airmanbzh');
echo('

' . htmlentities($result) . '
'); $result = $pheign->repositoryInformations('airmanbzh', $repo); echo('
' . htmlentities($result) . '
');

Annotations

Method

Namespace : pheign\annotation\method... Define request method, (*6)

@GET, @POST, @PUT, @DELETE, (*7)

Target

Namespace : pheign\annotation\Target, (*8)

Request endpoint, (*9)

@Target("/search/{id}")

Headers

Namespace : pheign\annotation\Headers, (*10)

Define a custom header, (*11)

@Headers({"Content-Type : application/json", "Accept-Charset: utf-8"})

Datas

Namespace : pheign\annotation\Datas, (*12)

@Datas(myDatas="{datas}", myId="{id}")

Options

Namespace : pheign\annotation\Options, (*13)

@Options(CURLOPT_SSL_VERIFYHOST=0, CURLOPT_SSL_VERIFYPEER=0)

To configure AOP

<?php
$loader = require_once(__DIR__ . '/../vendor/autoload.php');

$applicationAspectKernel = \pheign\kernel\PheignKernel::getInstance();
$applicationAspectKernel->init(array(
    'debug' => true,
    'appDir' => __DIR__ . '/../private', // The directory where you find your request class
    'cacheDir' => __DIR__ . '/../cache',
    'excludePaths' => array(
        __DIR__ . '/../vendor'
    )
));

More about Goaop and its configuration : goaop/framework, (*14)

The Versions

23/08 2017

dev-master

9999999-dev https://github.com/airmanbzh/pheign

Feign implement for php

  Sources   Download

MIT

The Requires

 

php pheign feign

23/08 2017

v1.0

1.0.0.0 https://github.com/airmanbzh/pheign

Feign implement for php

  Sources   Download

MIT

The Requires

 

php pheign feign