Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / media / tests / modules / media_test_oembed / src / Controller / ResourceController.php
diff --git a/web/core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php b/web/core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php
new file mode 100644 (file)
index 0000000..ca401e7
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace Drupal\media_test_oembed\Controller;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * Test controller returning oEmbed resources from Media's test fixtures.
+ */
+class ResourceController {
+
+  /**
+   * Returns the contents of an oEmbed resource fixture.
+   *
+   * @param \Symfony\Component\HttpFoundation\Request $request
+   *   The request.
+   *
+   * @return \Symfony\Component\HttpFoundation\Response
+   *   The JSON response.
+   */
+  public function get(Request $request) {
+    $asset_url = $request->query->get('url');
+
+    $resources = \Drupal::state()->get(static::class, []);
+
+    $content = file_get_contents($resources[$asset_url]);
+    $response = new Response($content);
+    $response->headers->set('Content-Type', 'application/json');
+
+    return $response;
+  }
+
+  /**
+   * Maps an asset URL to a local fixture representing its oEmbed resource.
+   *
+   * @param string $asset_url
+   *   The asset URL.
+   * @param string $resource_path
+   *   The path of the oEmbed resource representing the asset.
+   */
+  public static function setResourceUrl($asset_url, $resource_path) {
+    $resources = \Drupal::state()->get(static::class, []);
+    $resources[$asset_url] = $resource_path;
+    \Drupal::state()->set(static::class, $resources);
+  }
+
+}