public function DataStreamController::dataStream in farmOS 2.x
Respond to GET or POST requests referencing Data Streams by UUID.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request.
string $uuid: The DataStream UUID.
Return value
\Symfony\Component\HttpFoundation\Response The response.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 string reference to 'DataStreamController::dataStream'
- data_stream.routing.yml in modules/
core/ data_stream/ data_stream.routing.yml - modules/core/data_stream/data_stream.routing.yml
File
- modules/
core/ data_stream/ src/ Controller/ DataStreamController.php, line 31
Class
- DataStreamController
- Route callbacks for the DataStream controller.
Namespace
Drupal\data_stream\ControllerCode
public function dataStream(Request $request, string $uuid) {
// Load the data stream.
$data_streams = $this
->entityTypeManager()
->getStorage('data_stream')
->loadByProperties([
'uuid' => $uuid,
]);
// Bail if UUID is not found.
if (empty($data_streams)) {
throw new NotFoundHttpException();
}
/** @var \Drupal\data_stream\Entity\DataStreamInterface $data_stream */
$data_stream = reset($data_streams);
// Get the data stream plugin.
$plugin = $data_stream
->getPlugin();
// Bail if the plugin does not handle API requests.
if (!$plugin instanceof DataStreamApiInterface) {
throw new MethodNotAllowedHttpException([]);
}
// Get the request method.
$method = $request
->getMethod();
// Bail if the plugin does not allow the method.
$allowed_methods = $plugin
->apiAllowedMethods();
if (!in_array($method, $allowed_methods)) {
throw new MethodNotAllowedHttpException($allowed_methods);
}
return $plugin
->apiHandleRequest($data_stream, $request);
}