|
17 | 17 | use League\Route\Router; |
18 | 18 | use League\Route\Strategy\ApplicationStrategy; |
19 | 19 | use Pdsinterop\Solid\Controller\AddSlashToPathController; |
20 | | -use Pdsinterop\Solid\Controller\AuthorizeController; |
21 | 20 | use Pdsinterop\Solid\Controller\ApprovalController; |
| 21 | +use Pdsinterop\Solid\Controller\AuthorizeController; |
22 | 22 | use Pdsinterop\Solid\Controller\CorsController; |
23 | 23 | use Pdsinterop\Solid\Controller\HandleApprovalController; |
24 | 24 | use Pdsinterop\Solid\Controller\HelloWorldController; |
|
30 | 30 | use Pdsinterop\Solid\Controller\Profile\CardController; |
31 | 31 | use Pdsinterop\Solid\Controller\Profile\ProfileController; |
32 | 32 | use Pdsinterop\Solid\Controller\RegisterController; |
| 33 | +use Pdsinterop\Solid\Controller\ResourceController; |
33 | 34 | use Pdsinterop\Solid\Controller\StorageController; |
34 | 35 | use Pdsinterop\Solid\Controller\TokenController; |
35 | | -use Pdsinterop\Solid\Resources\Server; |
| 36 | +use Pdsinterop\Solid\Resources\Server as ResourceServer; |
36 | 37 |
|
37 | 38 | use Psr\Http\Message\ResponseInterface; |
38 | 39 | use Psr\Http\Message\ServerRequestInterface; |
|
81 | 82 | return $template; |
82 | 83 | }); |
83 | 84 |
|
| 85 | +$container->add(ResourceController::class, function () use ($container) { |
| 86 | + $filesystem = $container-> get(FilesystemInterface::class); |
| 87 | + |
| 88 | + require_once __DIR__ . '/../lib/solid-crud/src/Server.php'; |
| 89 | + |
| 90 | + $server = new ResourceServer($filesystem, new Response()); |
| 91 | + |
| 92 | + return new ResourceController($server); |
| 93 | +}); |
| 94 | + |
84 | 95 | $controllers = [ |
85 | 96 | AddSlashToPathController::class, |
86 | 97 | ApprovalController::class, |
|
191 | 202 |
|
192 | 203 | $response = new HtmlResponse($html, 500, []); |
193 | 204 | } |
| 205 | +/* |
| 206 | +$router->group('/data', static function (\League\Route\RouteGroup $group) { |
| 207 | + $methods = [ |
| 208 | + 'DELETE', |
| 209 | + 'GET', |
| 210 | + 'HEAD', |
| 211 | + // 'OPTIONS', // @TODO: This breaks because of the CorsController being added to `OPTION /*` in the index.php |
| 212 | + 'PATCH', |
| 213 | + 'POST', |
| 214 | + 'PUT', |
| 215 | + ]; |
| 216 | +
|
| 217 | + array_walk($methods, static function ($method) use (&$group) { |
| 218 | + $group->map($method, '/', AddSlashToPathController::class); |
| 219 | + $group->map($method, '{path:.*}', ResourceController::class); |
| 220 | + }); |
| 221 | +})->setScheme($scheme); |
| 222 | +
|
| 223 | +try { |
| 224 | + $response = $router->dispatch($request); |
| 225 | +} catch (HttpException $exception) { |
| 226 | + $status = $exception->getStatusCode(); |
| 227 | +
|
| 228 | + $message = 'Yeah, that\'s an error.'; |
| 229 | + if ($exception instanceof NotFoundException) { |
| 230 | + $message = 'No such page.'; |
| 231 | + } |
| 232 | +
|
| 233 | + $html = "<h1>{$message}</h1><p>{$exception->getMessage()} ({$status})</p>"; |
| 234 | +
|
| 235 | + if (getenv('ENVIRONMENT') === 'development') { |
| 236 | + $html .= "<pre>{$exception->getTraceAsString()}</pre>"; |
| 237 | + } |
| 238 | +
|
| 239 | + $response = new HtmlResponse($html, $status, $exception->getHeaders()); |
| 240 | +} catch (\Exception $exception) { |
| 241 | + $html = "<h1>Oh-no! The developers messed up!</h1><p>{$exception->getMessage()}</p>"; |
| 242 | +
|
| 243 | + if (getenv('ENVIRONMENT') === 'development') { |
| 244 | + $html .= |
| 245 | + "<p>{$exception->getFile()}:{$exception->getLine()}</p>" . |
| 246 | + "<pre>{$exception->getTraceAsString()}</pre>" |
| 247 | + ; |
| 248 | + } |
| 249 | +
|
| 250 | + $response = new HtmlResponse($html, 500, []); |
| 251 | +*/ |
194 | 252 | } |
195 | 253 |
|
196 | 254 | // send the response to the browser |
|
0 commit comments