コード例 #1
0
ファイル: Middleware.php プロジェクト: YounessTayer/directus
 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']);
 }
コード例 #2
0
 public static function exceptionHandler($app, $exception)
 {
     $response = $app->response();
     $response->header('Content-type', 'application/json');
     $httpCode = 500;
     $data = [];
     /**
      * Directus\Acl\Exception\AclException & subclasses
      */
     if ($exception instanceof AclException || is_subclass_of($exception, 'Directus\\Acl\\Exception\\AclException')) {
         $httpCode = 403;
         $data = ['message' => $exception->getMessage()];
     } elseif ($exception instanceof RelationshipMetadataException) {
         $httpCode = 424;
         $data = ['message' => $exception->getMessage()];
     } elseif ($exception instanceof CustomUiValidationError) {
         $httpCode = 422;
         $data = ['message' => $exception->getMessage()];
     } elseif ($exception instanceof DuplicateEntryException) {
         $httpCode = 409;
         $data = ['message' => $exception->getMessage()];
     } else {
         $data = ['message' => __t('internal_server_error')];
         if ('production' !== DIRECTUS_ENV) {
             $data = ['code' => $exception->getCode(), 'class' => get_class($exception), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), 'traceAsString' => $exception->getTraceAsString()];
         }
     }
     $data = @json_encode($data);
     if ('production' !== DIRECTUS_ENV) {
         $data = JsonView::format_json($data);
     }
     http_response_code($httpCode);
     header('Content-type: application/json');
     echo $data;
     exit;
 }
コード例 #3
0
ファイル: api.php プロジェクト: smkkstudios/Directus
 * 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();
}
コード例 #4
0
ファイル: _example.php プロジェクト: YounessTayer/directus
<?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']);
});
コード例 #5
0
ファイル: api.php プロジェクト: YounessTayer/directus
            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