You are here

class TextimageRoutes in Textimage 8.3

Same name and namespace in other branches
  1. 8.4 src/Routing/TextimageRoutes.php \Drupal\textimage\Routing\TextimageRoutes

Defines a route for serving Textimages through the URL.

Hierarchy

Expanded class hierarchy of TextimageRoutes

File

src/Routing/TextimageRoutes.php, line 13

Namespace

Drupal\textimage\Routing
View source
class TextimageRoutes implements ContainerInjectionInterface {

  /**
   * The stream wrapper manager service.
   *
   * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
   */
  protected $streamWrapperManager;

  /**
   * Constructs a new TextimageRoutes object.
   *
   * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
   *   The stream wrapper manager service.
   */
  public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) {
    $this->streamWrapperManager = $stream_wrapper_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('stream_wrapper_manager'));
  }

  /**
   * Returns an array of route objects.
   *
   * @return \Symfony\Component\Routing\Route[]
   *   An array of route objects.
   */
  public function routes() {
    $routes = [];

    // Route for generation of textimages from URL.
    $stream_wrapper = $this->streamWrapperManager
      ->getViaScheme('public');
    if (method_exists($stream_wrapper, 'getDirectoryPath')) {

      // Route for direct URL Textimage generation.
      // If the textimage derivative does not exist, Drupal will create it
      // via TextimageDownloadController::urlDeliver.
      // If the textimage derivative already exists, the web server will
      // deliver it directly.
      $routes['textimage.public'] = new Route('/' . $stream_wrapper
        ->getDirectoryPath() . '/textimage/{image_style}', [
        '_controller' => 'Drupal\\textimage\\Controller\\TextimageDownloadController::urlDeliver',
        '_disable_route_normalizer' => TRUE,
      ], [
        '_permission' => 'generate textimage url derivatives',
      ]);

      // Route for deferred generation in public scheme.
      // If the textimage derivative does not exist, Drupal will create it
      // via TextimageDownloadController::deferredDelivery.
      // If the textimage derivative already exists, the web server will
      // deliver it directly.
      $routes['textimage_store.public'] = new Route('/' . $stream_wrapper
        ->getDirectoryPath() . '/textimage_store', [
        '_controller' => 'Drupal\\textimage\\Controller\\TextimageDownloadController::deferredDelivery',
        '_disable_route_normalizer' => TRUE,
      ], [
        '_access' => 'TRUE',
      ]);
    }
    if ($this->streamWrapperManager
      ->getViaScheme('private')) {

      // Route for deferred generation in private scheme.
      // If the textimage derivative does not exist, Drupal will create it
      // via TextimageDownloadController::deferredDelivery.
      // If the textimage derivative already exists, Drupal will
      // deliver it via file_download.
      $routes['textimage_store.private'] = new Route('/system/files/textimage_store', [
        '_controller' => 'Drupal\\textimage\\Controller\\TextimageDownloadController::deferredDelivery',
        '_disable_route_normalizer' => TRUE,
      ], [
        '_access' => 'TRUE',
      ]);
    }
    return $routes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TextimageRoutes::$streamWrapperManager protected property The stream wrapper manager service.
TextimageRoutes::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
TextimageRoutes::routes public function Returns an array of route objects.
TextimageRoutes::__construct public function Constructs a new TextimageRoutes object.