2017 © Pedro Peláez
 

yii2-extension yii2-nithrift

Thrift server application using Yii2

image

rangelreale/yii2-nithrift

Thrift server application using Yii2

  • Thursday, January 14, 2016
  • by RangelReale
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

yii2-nithrift

Thrift extension for Yii2, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist RangelReale/yii2-nithrift "*"

or add, (*4)

"RangelReale/yii2-nithrift": "*"

Minimum Requirement

  • Thrift version 0.9.3. To install thrift, check http://thrift.apache.org/download
  • Yii 2.0.0

Usage

The Thrift base classes must be accessible someway. I put the thrift/lib/php/lib path in my application root, and add this to composer.json:, (*5)

"autoload": {
    "psr-0": {
        "Thrift": "lib"
    }
}

Create a directory named generated in your application root. Put your .thrift files into it, and generate the php wrapper on the default gen-php path, using command below., (*6)

thrift --gen php:server path/to/the/thrift/file

The files should be like this:, (*7)

-- ROOT
    -- config
    -- controllers
    -- generated
        file1.thrift
        file2.thrift
        -- gen-php
            -- file1
            -- file2
    ...

In the component configuration add the thrift component, with the Thrift definitions., (*8)

return [
    'component' => [
        'thrift' => [
            'class' => 'RangelReale\nithrift\Thrift',
            'definitions' => [
                'shared',
                'tutorial',
            ],
        ]
    ]
]

Implement your Thrift handlers in separate class files, following the thrift documentation. I recommend using a services directory on the application root. There is no need to override or implement any other interface., (*9)

Your controller should extend \RangelReale\nithrift\Controller. You can use the custom \RangelReale\nithrift\Action class to implement the services., (*10)

class ApiController extends \RangelReale\nithrift\Controller
{
    public function actions()
    {
        return [
            'calculator' => [
                'class' => 'RangelReale\nithrift\Action',
                'handler' => 'app\services\CalculatorHandler',
                'processor' => 'tutorial\CalculatorProcessor',
            ]
        ];
    }
}

If you prefer, you can implement an inline action, and either return a \RangelReale\nithrift\Response object, or a processor object directly., (*11)

public function actionCalculator()
{
    $handler = new \app\services\CalculatorHandler();
    $processor = new \tutorial\CalculatorProcessor($handler);

    return new ThriftResponse($processor); // could be `return $processor;`
}

Author

Rangel Reale (rangelspam@gmail.com), (*12)

The Versions

14/01 2016

dev-master

9999999-dev

Thrift server application using Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Rangel Reale

yii2 thrift