GetFile.php in Acquia Content Hub 8.2
File
modules/acquia_contenthub_publisher/src/EventSubscriber/HandleWebhook/GetFile.php
View source
<?php
namespace Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhook;
use Drupal\acquia_contenthub\AcquiaContentHubEvents;
use Drupal\acquia_contenthub\ContentHubCommonActions;
use Drupal\acquia_contenthub\Event\HandleWebhookEvent;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class GetFile implements EventSubscriberInterface {
use HandleWebhookTrait;
protected $common;
protected $streamWrapperManager;
public function __construct(ContentHubCommonActions $common, StreamWrapperManagerInterface $stream_wrapper_manager) {
$this->common = $common;
$this->streamWrapperManager = $stream_wrapper_manager;
}
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::HANDLE_WEBHOOK][] = [
'onHandleWebhook',
1000,
];
return $events;
}
public function onHandleWebhook(HandleWebhookEvent $event) : void {
$payload = $event
->getPayload();
$client = $event
->getClient();
$settings = $client
->getSettings();
$client_uuid = $settings
->getUuid();
if ('successful' !== $payload['status'] || empty($payload['uuid']) || 'getFile' !== $payload['crud'] || $payload['initiator'] === $client_uuid || empty($payload['cdf'])) {
return;
}
$file_uri = $payload['cdf']['uri'];
$file_scheme = $payload['cdf']['scheme'];
if ($this->streamWrapperManager
->isValidScheme($file_scheme) && is_file($file_uri)) {
$binary = new BinaryFileResponse($file_uri, 200, [], $file_scheme === 'private' ? FALSE : TRUE, 'inline');
$response = $this
->getResponse($event, '', 200, $binary);
$event
->setResponse($response);
$event
->stopPropagation();
}
}
}
Classes
Name |
Description |
GetFile |
Gets files during preview in content as a service. |