Exemple #1
0
 public static function renderJson()
 {
     $app = \Slim\Slim::getInstance();
     $view = $app->view();
     $viewData = $view->getData();
     if (!array_key_exists('jsonResponse', $viewData)) {
         throw new \RuntimeException('renderJson middleware expected `jsonResponse` key within the view data array.');
     }
     JsonView::render($viewData['jsonResponse']);
 }
Exemple #2
0
<?php

use Directus\Bootstrap;
use Directus\View\JsonView;
// Slim App
$app = Bootstrap::get('app');
// Simple GET endpoint example
$app->get('/example', function () {
    return JsonView::render(['item 1', 'item 2']);
});
Exemple #3
0
 * UI COLLECTION
 */
$app->map("/{$v}/tables/:table/columns/:column/:ui/?", function ($table, $column, $ui) use($acl, $ZendDb, $params, $requestPayload, $app) {
    $TableGateway = new TableGateway($acl, 'directus_ui', $ZendDb);
    switch ($app->request()->getMethod()) {
        case "PUT":
        case "POST":
            $keys = array('table_name' => $table, 'column_name' => $column, 'ui_name' => $ui);
            $uis = to_name_value($requestPayload, $keys);
            $column_settings = array();
            foreach ($uis as $col) {
                $existing = $TableGateway->select(array('table_name' => $table, 'column_name' => $column, 'ui_name' => $ui, 'name' => $col['name']))->toArray();
                if (count($existing) > 0) {
                    $col['id'] = $existing[0]['id'];
                }
                array_push($column_settings, $col);
            }
            $TableGateway->updateCollection($column_settings);
    }
    $UiOptions = new DirectusUiTableGateway($acl, $ZendDb);
    $get_new = $UiOptions->fetchOptions($table, $column, $ui);
    JsonView::render($get_new);
})->via('GET', 'POST', 'PUT');
/**
 * Run the Router
 */
if (isset($_GET['run_api_router']) && $_GET['run_api_router']) {
    // Run Slim
    $app->response()->header('Content-Type', 'application/json; charset=utf-8');
    $app->run();
}
Exemple #4
0
            foreach ($uis as $col) {
                $existing = $TableGateway->select(['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui, 'name' => $col['name']])->toArray();
                if (count($existing) > 0) {
                    $col['id'] = $existing[0]['id'];
                }
                array_push($column_settings, $col);
            }
            $TableGateway->updateCollection($column_settings);
    }
    $UiOptions = new DirectusUiTableGateway($acl, $ZendDb);
    $response = $UiOptions->fetchOptions($table, $column, $ui);
    if (!$response) {
        $app->response()->setStatus(404);
        $response = ['message' => __t('unable_to_find_column_x_options_for_x', ['column' => $column, 'ui' => $ui]), 'success' => false];
    }
    JsonView::render($response);
})->via('GET', 'POST', 'PUT');
$app->notFound(function () use($app, $acl, $ZendDb) {
    $app->response()->header('Content-Type', 'text/html; charset=utf-8');
    $settingsTable = new DirectusSettingsTableGateway($acl, $ZendDb);
    $settings = $settingsTable->fetchCollection('global');
    $projectName = isset($settings['project_name']) ? $settings['project_name'] : 'Directus';
    $projectLogoURL = '/assets/img/directus-logo-flat.svg';
    if (isset($settings['cms_thumbnail_url']) && $settings['cms_thumbnail_url']) {
        $projectLogoURL = $settings['cms_thumbnail_url'];
    }
    $data = ['project_name' => $projectName, 'project_logo' => $projectLogoURL];
    $app->render('errors/404.twig.html', $data);
});
/**
 * Run the Router