示例#1
0
[![Forms](../resources/Form.gif)](users.html)
We have made it easy to try different styles
Also this example serves as an example for our Blade template integration

See bootstrap3.blade.php and foundation5.blade.php

Content:

*[bootstrap3.blade.php]: _016_forms/views/base/bootstrap3.blade.php
*[foundation5.blade.php]: _016_forms/views/base/foundation5.blade.php
*/
$loader = (include '../../../vendor/autoload.php');
$loader->setUseIncludePath(true);
use Luracast\Restler\Data\Validator;
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;
use Luracast\Restler\Format\HtmlFormat;
use Luracast\Restler\UI\Forms;
use Luracast\Restler\UI\FormStyles;
HtmlFormat::$viewPath = __DIR__ . '/views';
HtmlFormat::$template = 'blade';
Validator::$holdException = true;
$themes = array('amelia', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal', 'lumen', 'readable', 'simplex', 'slate', 'spacelab', 'superhero', 'united', 'yeti');
$theme = isset($_GET['theme']) ? $_GET['theme'] : $themes[array_rand($themes, 1)];
$style = $theme == 'foundation5' ? 'foundation5' : 'bootstrap3';
HtmlFormat::$data += compact('theme', 'themes', 'style');
Forms::$style = FormStyles::${$style};
$r = new Restler();
$r->setSupportedFormats('HtmlFormat');
$r->addAPIClass('Users');
$r->handle();
示例#2
0
if ($matches && isset($matches[1]) && $matches[1] == 2) {
    $version = 2;
}
// Do not put .json at the end of the resource
Resources::$useFormatAsExtension = false;
//Do not hide the API
Resources::$hideProtected = false;
// Use /api/v1/projects uri
Defaults::$useUrlBasedVersioning = true;
if (ForgeConfig::get('DEBUG_MODE')) {
    $restler = new Restler(false, true);
} else {
    $restler = new Restler();
}
$restler->setAPIVersion($version);
$restler->setSupportedFormats('JsonFormat', 'XmlFormat');
$core_resources_injector = new Tuleap\REST\ResourcesInjector();
$core_resources_injector->populate($restler);
switch ($version) {
    case 2:
        $event = Event::REST_RESOURCES_V2;
        break;
    default:
        $event = Event::REST_RESOURCES;
        break;
}
EventManager::instance()->processEvent($event, array('restler' => $restler));
$restler->addAPIClass('Resources');
$restler->addAuthenticationClass('\\Tuleap\\REST\\TokenAuthentication');
$restler->addAuthenticationClass('\\Tuleap\\REST\\BasicAuthentication');
$restler->handle();
示例#3
0
    @view  folder/name.extension
When the extension is omitted `HtmlFormat::$format` will be used
HtmlFormat will look at `views` folder that resides parallel to `vendor` directory
for the template files and can be changed by setting `HtmlFormat::$viewPath` to
full path of a folder
Content:
In this example, we are building tasks api and also a single page application
using jQuery and the templates
[![Single Page App](../resources/html_view.png)](tasks)
Our api response is sent to the template under the name `response` along with other
information such as `basePath`, `baseUrl`, `request` parameters.
You can send custom data yourself by setting key value pairs in
`HtmlFormat::$data` array
If you do not want all the information and want to keep your template simple, you
can use `{@data key.innerkey}` comment as shown below
    @view todo/list {@data response}
This calls the list template with key value pairs defined at the response array
directly accessible as the variable and value inside the template
This example also show cases the heredoc syntax based simple templating system
which is Supported with out any external dependencies
Just to show that it is possible to come up with API as well as an App using the
same resource and url, you can try the json version of the tasks api using the
API Explorer [here](explorer/index.html)
*/
require_once '../../../vendor/restler.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->setSupportedFormats('JsonFormat', 'HtmlFormat');
$r->addAPIClass('Tasks');
$r->addAPIClass('Resources');
$r->handle();
示例#4
0
<?php

require_once __DIR__ . '/../../../fw/includes.php';
require_once __DIR__ . '/../ExcelImport.php';
require_once __DIR__ . '/../../../api/vendor/restler.php';
use Luracast\Restler\Restler;
use Luracast\Restler\Format\UploadFormat;
$r = new Restler();
UploadFormat::$allowedMimeTypes = Config::get('allowedMimeTypes', 'excelImport');
$r->setSupportedFormats('JsonFormat', 'UploadFormat');
// some strange error in Restler when UploadFormat is mentioned as first parameter
$r->addAPIClass('ExcelImportApi', '');
$r->handle();
示例#5
0
文件: index.php 项目: raven7/Restler
<?php

/*
 * Testing all the attributes for @param annotation
 */
use Luracast\Restler\Restler;
require_once "../../../vendor/restler.php";
$r = new Restler();
$r->setSupportedFormats('JsonFormat', 'CsvFormat');
$r->addAPIClass('Data', '');
$r->addAPIClass('Resources');
$r->handle();
示例#6
0
<?php

//Show errors
error_reporting(E_ALL);
ini_set("display_errors", 1);
// Set Timezone
date_default_timezone_set("UTC");
// ORM configuration
require_once "app/orm/Config.php";
// Composre autoloader
require_once "vendor/autoload.php";
// Dependencies
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;
use Luracast\Restler\Resources;
use Luracast\Restler\Format\HtmlFormat;
use App\Services\Env;
// Enable CORS by default
Defaults::$crossOriginResourceSharing = true;
// Supported formats by default
$r = new Restler();
$r->setSupportedFormats('JsonFormat', 'YamlFormat', 'XmlFormat', 'HtmlFormat', 'UploadFormat');
// Add endpoints here like (go into app directory there is the class for the endpoint):
$r->addAPIClass('Device');
// For documentation
$r->addApiClass('Resources');
Env::init();
$r->handle();