Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / middleware.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/service/middleware.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/service/middleware.twig
new file mode 100644 (file)
index 0000000..9aba558
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\{{ machine_name }};
+
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+
+/**
+ * {{ class }} middleware.
+ */
+class {{ class }} implements HttpKernelInterface {
+
+  use StringTranslationTrait;
+
+  /**
+   * The kernel.
+   *
+   * @var \Symfony\Component\HttpKernel\HttpKernelInterface
+   */
+  protected $httpKernel;
+
+  /**
+   * Constructs the {{ class }} object.
+   *
+   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
+   *   The decorated kernel.
+   */
+  public function __construct(HttpKernelInterface $http_kernel) {
+    $this->httpKernel = $http_kernel;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
+
+    if ($request->getClientIp() == '127.0.0.10') {
+      return new Response($this->t('Bye!'), 403);
+    }
+
+    return $this->httpKernel->handle($request, $type, $catch);
+  }
+
+}