Skip to content

Instantly share code, notes, and snippets.

@davb
Created September 10, 2012 21:07
Show Gist options
  • Save davb/3693866 to your computer and use it in GitHub Desktop.
Save davb/3693866 to your computer and use it in GitHub Desktop.
A skeleton implementation of a Feeligo API Endpoint using the "expose PHP script" method.
<?php
/**
* Api endpoint controller
*
* this file is provided as a skeleton implementation of a Feeligo API Endpoint.
*/
/**
* require the SDK's built-in FeeligoController
*
* you may need to modify the path according to your directory structure
*/
require_once(str_replace('//','/',dirname(__FILE__).'/').'modules/feeligo/sdk/lib/controllers/controller.php');
/**
* class Feeligo_Mysite_Controller
*
* you may adapt the class name to your naming conventions
*/
class Feeligo_Mysite_Controller {
/**
* action 'index'
*
* all requests will be routed to this method, which will instantiate
* the SDK's built-in FeeligoController, call its run() method to
* process the request, and return the resulting response to the user.
*/
public function index () {
// instantiate the FeeligoController
// the constructor expects the singleton instance of FeeligoApi as its argument
$feeligo_controller = new FeeligoController(/*FeeligoApi::_()*/);
// call the run method and get the response object
$feeligo_response = $feeligo_controller->run();
// pass the response's HTTP properties (status code, headers, body)
// to the Feeligo_Mysite_Controller's own response object
// which will be returned to the user.
//
// (refer to your framework's documentation to accomplish this.)
$this->response()->set_headers($feeligo_response->headers());
$this->response()->set_status_code($feeligo_response->code());
$this->response()->set_body($feeligo_response->body());
}
}
<?php
/**
* Api endpoint script
*
* this file is provided as a skeleton implementation of a Feeligo API Endpoint.
*/
/**
* require the SDK's built-in FeeligoController
*
* you may need to modify the path according to your directory structure
*/
require_once(str_replace('//','/',dirname(__FILE__).'/').'modules/feeligo/sdk/lib/controllers/controller.php');
/**
* instantiate the FeeligoController
*
* the constructor expects the singleton instance of FeeligoApi as its argument
*/
$controller = new FeeligoController(/*FeeligoApi::_()*/); // use your own implementation of FeeligoApi
/**
* process the request
*/
$response = $controller->run();
/**
* set response headers and output body
*/
header("HTTP/1.1 ".$response->code());
foreach($response->headers() as $k => $v) {
header("$k: $v");
}
echo $response->body();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment